|
1 | 1 | import { describe, it, expect, vi, beforeEach } from "vitest"; |
2 | 2 | import { render, screen } from "@solidjs/testing-library"; |
3 | 3 | import userEvent from "@testing-library/user-event"; |
| 4 | +import { createSignal } from "solid-js"; |
4 | 5 | import IssuesTab from "../../src/app/components/dashboard/IssuesTab"; |
5 | | -import type { ApiError } from "../../src/app/services/api"; |
| 6 | +import type { Issue, ApiError } from "../../src/app/services/api"; |
6 | 7 | import { makeIssue, resetViewStore } from "../helpers/index"; |
7 | 8 | import * as viewStore from "../../src/app/stores/view"; |
8 | 9 | import { updateConfig, resetConfig } from "../../src/app/stores/config"; |
@@ -294,6 +295,31 @@ describe("IssuesTab", () => { |
294 | 295 | screen.getByText("Bob issue"); |
295 | 296 | }); |
296 | 297 |
|
| 298 | + it("resets page when data shrinks below current page", async () => { |
| 299 | + const user = userEvent.setup(); |
| 300 | + updateConfig({ itemsPerPage: 10 }); |
| 301 | + const repoAIssues = Array.from({ length: 6 }, (_, i) => |
| 302 | + makeIssue({ id: 100 + i, title: `Repo A issue ${i}`, repoFullName: "org/repo-a" }) |
| 303 | + ); |
| 304 | + const repoBIssues = Array.from({ length: 6 }, (_, i) => |
| 305 | + makeIssue({ id: 200 + i, title: `Repo B issue ${i}`, repoFullName: "org/repo-b" }) |
| 306 | + ); |
| 307 | + const [issues, setIssues] = createSignal<Issue[]>([...repoAIssues, ...repoBIssues]); |
| 308 | + render(() => <IssuesTab issues={issues()} userLogin="" />); |
| 309 | + |
| 310 | + // Navigate to page 2 |
| 311 | + screen.getByText(/Page 1 of 2/); |
| 312 | + await user.click(screen.getByLabelText("Next page")); |
| 313 | + screen.getByText(/Page 2 of 2/); |
| 314 | + screen.getByText("org/repo-b"); |
| 315 | + |
| 316 | + // Shrink data to fit on 1 page — page should reset |
| 317 | + setIssues(repoAIssues); |
| 318 | + expect(screen.queryByLabelText("Next page")).toBeNull(); |
| 319 | + screen.getByText("org/repo-a"); |
| 320 | + screen.getByText("Repo A issue 0"); |
| 321 | + }); |
| 322 | + |
297 | 323 | it("keeps a large single-repo group on one page without splitting", () => { |
298 | 324 | updateConfig({ itemsPerPage: 10 }); |
299 | 325 | const issues = Array.from({ length: 15 }, (_, i) => |
|
0 commit comments