Skip to content

Commit 5422efb

Browse files
committed
test: fixes userEvent consistency and adds multi-page test
1 parent aebeaf2 commit 5422efb

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, it, expect, vi } from "vitest";
2-
import { render, screen, fireEvent } from "@solidjs/testing-library";
2+
import { render, screen } from "@solidjs/testing-library";
3+
import userEvent from "@testing-library/user-event";
34
import ExpandCollapseButtons from "../../src/app/components/shared/ExpandCollapseButtons";
45

56
describe("ExpandCollapseButtons", () => {
@@ -9,17 +10,19 @@ describe("ExpandCollapseButtons", () => {
910
expect(screen.getByRole("button", { name: "Collapse all" })).toBeTruthy();
1011
});
1112

12-
it("calls onExpandAll when expand button is clicked", () => {
13+
it("calls onExpandAll when expand button is clicked", async () => {
14+
const user = userEvent.setup();
1315
const onExpandAll = vi.fn();
1416
render(() => <ExpandCollapseButtons onExpandAll={onExpandAll} onCollapseAll={() => {}} />);
15-
fireEvent.click(screen.getByRole("button", { name: "Expand all" }));
17+
await user.click(screen.getByRole("button", { name: "Expand all" }));
1618
expect(onExpandAll).toHaveBeenCalledTimes(1);
1719
});
1820

19-
it("calls onCollapseAll when collapse button is clicked", () => {
21+
it("calls onCollapseAll when collapse button is clicked", async () => {
22+
const user = userEvent.setup();
2023
const onCollapseAll = vi.fn();
2124
render(() => <ExpandCollapseButtons onExpandAll={() => {}} onCollapseAll={onCollapseAll} />);
22-
fireEvent.click(screen.getByRole("button", { name: "Collapse all" }));
25+
await user.click(screen.getByRole("button", { name: "Collapse all" }));
2326
expect(onCollapseAll).toHaveBeenCalledTimes(1);
2427
});
2528
});

tests/components/IssuesTab.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,30 @@ describe("IssuesTab", () => {
489489
// State persisted in viewState store — should still be expanded
490490
screen.getByText("Survives remount");
491491
});
492+
493+
it("clicking 'Expand all' expands repos on other pages too", async () => {
494+
const user = userEvent.setup();
495+
updateConfig({ itemsPerPage: 10 });
496+
const issues = [
497+
...Array.from({ length: 6 }, (_, i) =>
498+
makeIssue({ id: 100 + i, title: `Repo A issue ${i}`, repoFullName: "org/repo-a" })
499+
),
500+
...Array.from({ length: 6 }, (_, i) =>
501+
makeIssue({ id: 200 + i, title: `Repo B issue ${i}`, repoFullName: "org/repo-b" })
502+
),
503+
];
504+
render(() => <IssuesTab issues={issues} userLogin="" />);
505+
// Page 1 shows repo-a, page 2 shows repo-b
506+
screen.getByText(/Page 1 of 2/);
507+
508+
// Expand all — affects repos on ALL pages
509+
await user.click(screen.getByLabelText("Expand all"));
510+
// Repo-a items visible on page 1
511+
screen.getByText("Repo A issue 0");
512+
513+
// Navigate to page 2 — repo-b should already be expanded
514+
await user.click(screen.getByLabelText("Next page"));
515+
screen.getByText("org/repo-b");
516+
screen.getByText("Repo B issue 0");
517+
});
492518
});

tests/components/PullRequestsTab.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,30 @@ describe("PullRequestsTab", () => {
569569
render(() => <PullRequestsTab pullRequests={prs} userLogin="" />);
570570
screen.getByText("Persistent PR");
571571
});
572+
573+
it("clicking 'Expand all' expands repos on other pages too", async () => {
574+
const user = userEvent.setup();
575+
updateConfig({ itemsPerPage: 10 });
576+
const prs = [
577+
...Array.from({ length: 6 }, (_, i) =>
578+
makePullRequest({ id: 100 + i, title: `Repo A PR ${i}`, repoFullName: "org/repo-a" })
579+
),
580+
...Array.from({ length: 6 }, (_, i) =>
581+
makePullRequest({ id: 200 + i, title: `Repo B PR ${i}`, repoFullName: "org/repo-b" })
582+
),
583+
];
584+
render(() => <PullRequestsTab pullRequests={prs} userLogin="" />);
585+
// Page 1 shows repo-a, page 2 shows repo-b
586+
screen.getByText(/Page 1 of 2/);
587+
588+
// Expand all — affects repos on ALL pages
589+
await user.click(screen.getByLabelText("Expand all"));
590+
// Repo-a items visible on page 1
591+
screen.getByText("Repo A PR 0");
592+
593+
// Navigate to page 2 — repo-b should already be expanded
594+
await user.click(screen.getByLabelText("Next page"));
595+
screen.getByText("org/repo-b");
596+
screen.getByText("Repo B PR 0");
597+
});
572598
});

0 commit comments

Comments
 (0)