hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { createSignal } from "solid-js"; |
| 2 | import { Portal } from "solid-js/web"; |
| 3 | import { fireEvent, render, screen, within } from "@solidjs/testing-library"; |
| 4 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 5 | import { DataTable } from "@/components/ui/data-table"; |
| 6 | import { DataSection } from "@/components/ui/data-section"; |
| 7 | import { PageHeader } from "@/components/layout/page-header"; |
| 8 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 9 | |
| 10 | type Row = { name: string; role?: string }; |
| 11 | |
| 12 | const columns: ColumnDef<Row>[] = [ |
| 13 | { accessorKey: "name", header: "Name" }, |
| 14 | { id: "update", header: "Role", cell: () => "Role" }, |
| 15 | { |
| 16 | id: "actions", |
| 17 | header: "Actions", |
| 18 | meta: { headerClass: "w-14", cellClass: "w-40 text-right" }, |
| 19 | cell: () => "…", |
| 20 | }, |
| 21 | ]; |
| 22 | |
| 23 | beforeEach(() => { |
| 24 | localStorage.clear(); |
| 25 | vi.spyOn(window, "scrollTo").mockImplementation(() => undefined); |
| 26 | }); |
| 27 | afterEach(() => vi.restoreAllMocks()); |
| 28 | |
| 29 | test("keeps only the rightmost action column sticky and fixed at 110x45", () => { |
| 30 | render(() => ( |
| 31 | <PreferencesProvider> |
| 32 | <DataTable columns={columns} data={[{ name: "Ada" }]} enableColumnVisibility={false} /> |
| 33 | </PreferencesProvider> |
| 34 | )); |
| 35 | |
| 36 | const actionsHeader = screen.getByRole("columnheader", { name: "Actions" }); |
| 37 | expect(actionsHeader.classList).toContain("table-sticky-head-right"); |
| 38 | expect(actionsHeader.classList).toContain("table-action-cell"); |
| 39 | expect(actionsHeader.classList).toContain("h-[45px]"); |
| 40 | expect(actionsHeader.classList).toContain("w-[110px]"); |
| 41 | expect(actionsHeader.classList).not.toContain("w-14"); |
| 42 | expect(actionsHeader.style.width).toBe("110px"); |
| 43 | expect(actionsHeader.classList).toContain("z-30"); |
| 44 | const actionsCell = screen.getByRole("cell", { name: "…" }); |
| 45 | expect(actionsCell.classList).toContain("table-action-cell"); |
| 46 | expect(actionsCell.classList).toContain("h-[45px]"); |
| 47 | expect(actionsCell.classList).toContain("w-[110px]"); |
| 48 | expect(actionsCell.classList).not.toContain("w-40"); |
| 49 | expect(actionsCell.classList).toContain("text-center"); |
| 50 | expect(actionsCell.classList).not.toContain("text-right"); |
| 51 | expect(actionsCell.style.width).toBe("110px"); |
| 52 | const columnTracks = document.querySelectorAll("col"); |
| 53 | // Plain percentages: Chrome reads a %-and-px calc() on a table column as |
| 54 | // auto and splits the table evenly, whatever each column's size says. |
| 55 | expect(columnTracks[0]?.style.width).toBe("50%"); |
| 56 | expect(columnTracks[1]?.style.width).toBe("50%"); |
| 57 | expect(columnTracks[2]?.style.width).toBe("110px"); |
| 58 | const roleHeader = screen.getAllByRole("columnheader").find((header) => header.textContent?.startsWith("Role")); |
| 59 | expect(roleHeader?.classList).not.toContain("table-sticky-head-right"); |
| 60 | }); |
| 61 | |
| 62 | test("freezes the meta.stickyLeft column and centres headers and left-aligns cells", () => { |
| 63 | const alignedColumns: ColumnDef<Row>[] = [ |
| 64 | { accessorKey: "name", header: "Name", meta: { stickyLeft: true } }, |
| 65 | { accessorKey: "role", header: "Role", meta: { align: "right" } }, |
| 66 | ]; |
| 67 | render(() => ( |
| 68 | <PreferencesProvider> |
| 69 | <DataTable columns={alignedColumns} data={[{ name: "Ada", role: "Admin" }]} enableColumnVisibility={false} enableSorting={false} /> |
| 70 | </PreferencesProvider> |
| 71 | )); |
| 72 | |
| 73 | const headers = screen.getAllByRole("columnheader"); |
| 74 | const nameHeader = headers.find((header) => header.textContent?.startsWith("Name")); |
| 75 | expect(nameHeader?.classList).toContain("table-sticky-head-left"); |
| 76 | expect(nameHeader?.classList).toContain("left-0"); |
| 77 | |
| 78 | const roleHeader = headers.find((header) => header.textContent?.startsWith("Role")); |
| 79 | const roleCell = screen.getByRole("cell", { name: "Admin" }); |
| 80 | // List tables use one consistent centered alignment, including numeric columns. |
| 81 | expect(roleHeader?.classList).toContain("text-center"); |
| 82 | expect(roleCell.classList).toContain("text-left"); |
| 83 | }); |
| 84 | |
| 85 | /** Stand-in IntersectionObserver whose callback a test fires by hand. */ |
| 86 | function stubIntersectionObserver() { |
| 87 | const callbacks: IntersectionObserverCallback[] = []; |
| 88 | class FakeObserver { |
| 89 | constructor(callback: IntersectionObserverCallback) { |
| 90 | callbacks.push(callback); |
| 91 | } |
| 92 | observe() {} |
| 93 | disconnect() {} |
| 94 | } |
| 95 | vi.stubGlobal("IntersectionObserver", FakeObserver); |
| 96 | return () => { |
| 97 | for (const callback of callbacks) callback([{ isIntersecting: true } as IntersectionObserverEntry], {} as IntersectionObserver); |
| 98 | }; |
| 99 | } |
| 100 | |
| 101 | test("paginates client rows without observing the scroll position", () => { |
| 102 | const reachEnd = stubIntersectionObserver(); |
| 103 | const rows = Array.from({ length: 21 }, (_, index) => ({ name: `Person ${index + 1}` })); |
| 104 | try { |
| 105 | render(() => ( |
| 106 | <PreferencesProvider> |
| 107 | <DataTable columns={[columns[0]]} data={rows} enableColumnVisibility={false} /> |
| 108 | </PreferencesProvider> |
| 109 | )); |
| 110 | expect(screen.getByText("Person 10")).toBeTruthy(); |
| 111 | expect(screen.queryByText("Person 11")).toBeNull(); |
| 112 | expect(screen.getByText("1 / 3")).toBeTruthy(); |
| 113 | reachEnd(); |
| 114 | expect(screen.queryByText("Person 11")).toBeNull(); |
| 115 | fireEvent.click(screen.getByRole("button", { name: /Next|Sonraki/ })); |
| 116 | expect(screen.getByText("Person 11")).toBeTruthy(); |
| 117 | } finally { |
| 118 | vi.unstubAllGlobals(); |
| 119 | } |
| 120 | }); |
| 121 | |
| 122 | test("reports rendered client and manual page rows", () => { |
| 123 | const rows = Array.from({ length: 12 }, (_, index) => ({ name: `Person ${index + 1}` })); |
| 124 | const onPageRowsChange = vi.fn(); |
| 125 | const client = render(() => ( |
| 126 | <PreferencesProvider> |
| 127 | <DataTable columns={[columns[0]]} data={rows} onPageRowsChange={onPageRowsChange} enableColumnVisibility={false} /> |
| 128 | </PreferencesProvider> |
| 129 | )); |
| 130 | expect(onPageRowsChange.mock.lastCall?.[0].map((row: Row) => row.name)).toEqual(rows.slice(0, 10).map((row) => row.name)); |
| 131 | fireEvent.click(screen.getByRole("button", { name: /Next|Sonraki/ })); |
| 132 | expect(onPageRowsChange.mock.lastCall?.[0].map((row: Row) => row.name)).toEqual(["Person 11", "Person 12"]); |
| 133 | client.unmount(); |
| 134 | |
| 135 | onPageRowsChange.mockClear(); |
| 136 | const [page, setPage] = createSignal(0); |
| 137 | render(() => ( |
| 138 | <PreferencesProvider> |
| 139 | <DataTable |
| 140 | columns={[columns[0]]} |
| 141 | data={rows.slice(page() * 5, page() * 5 + 5)} |
| 142 | manualPagination={{ pageIndex: page(), pageSize: 5, total: rows.length, onPageChange: setPage }} |
| 143 | onPageRowsChange={onPageRowsChange} |
| 144 | enableColumnVisibility={false} |
| 145 | /> |
| 146 | </PreferencesProvider> |
| 147 | )); |
| 148 | expect(onPageRowsChange.mock.lastCall?.[0].map((row: Row) => row.name)).toEqual(rows.slice(0, 5).map((row) => row.name)); |
| 149 | fireEvent.click(screen.getByRole("button", { name: /Next|Sonraki/ })); |
| 150 | expect(onPageRowsChange.mock.lastCall?.[0].map((row: Row) => row.name)).toEqual(rows.slice(5, 10).map((row) => row.name)); |
| 151 | }); |
| 152 | |
| 153 | test("without IntersectionObserver client rows still paginate", () => { |
| 154 | vi.stubGlobal("IntersectionObserver", undefined); |
| 155 | const rows = Array.from({ length: 60 }, (_, index) => ({ name: `Person ${index + 1}` })); |
| 156 | try { |
| 157 | render(() => ( |
| 158 | <PreferencesProvider> |
| 159 | <DataTable columns={[columns[0]]} data={rows} enableColumnVisibility={false} /> |
| 160 | </PreferencesProvider> |
| 161 | )); |
| 162 | expect(screen.queryByText("Person 60")).toBeNull(); |
| 163 | expect(screen.getByText("1 / 6")).toBeTruthy(); |
| 164 | } finally { |
| 165 | vi.unstubAllGlobals(); |
| 166 | } |
| 167 | }); |
| 168 | test("uses a shorter client page on phones", () => { |
| 169 | vi.stubGlobal("matchMedia", (query: string) => ({ |
| 170 | matches: query.includes("max-width"), |
| 171 | media: query, |
| 172 | addEventListener: () => undefined, |
| 173 | removeEventListener: () => undefined, |
| 174 | })); |
| 175 | try { |
| 176 | render(() => ( |
| 177 | <PreferencesProvider> |
| 178 | <DataTable |
| 179 | columns={[columns[0]]} |
| 180 | data={Array.from({ length: 11 }, (_, index) => ({ name: `Person ${index + 1}` }))} |
| 181 | enableColumnVisibility={false} |
| 182 | /> |
| 183 | </PreferencesProvider> |
| 184 | )); |
| 185 | expect(screen.getByText("Person 5")).toBeTruthy(); |
| 186 | expect(screen.queryByText("Person 6")).toBeNull(); |
| 187 | expect(screen.getByText("1 / 3")).toBeTruthy(); |
| 188 | } finally { |
| 189 | vi.unstubAllGlobals(); |
| 190 | } |
| 191 | }); |
| 192 | test("search resets a client page and shrinking data clamps its index", () => { |
| 193 | const [rows, setRows] = createSignal(Array.from({ length: 22 }, (_, index) => ({ name: `Person ${index + 1}` }))); |
| 194 | render(() => ( |
| 195 | <PreferencesProvider> |
| 196 | <DataTable |
| 197 | columns={[columns[0]]} |
| 198 | data={rows()} |
| 199 | enableColumnVisibility={false} |
| 200 | searchPredicate={(row, query) => row.name.toLowerCase().includes(query.toLowerCase())} |
| 201 | /> |
| 202 | </PreferencesProvider> |
| 203 | )); |
| 204 | fireEvent.click(screen.getByRole("button", { name: /Next|Sonraki/ })); |
| 205 | fireEvent.click(screen.getByRole("button", { name: /Next|Sonraki/ })); |
| 206 | expect(screen.getByText("Person 22")).toBeTruthy(); |
| 207 | setRows((current) => current.slice(0, 12)); |
| 208 | expect(screen.getByText("Person 12")).toBeTruthy(); |
| 209 | fireEvent.input(screen.getByRole("textbox"), { target: { value: "Person 12" } }); |
| 210 | expect(screen.getByText("Person 12")).toBeTruthy(); |
| 211 | }); |
| 212 | test("a display column renders its own cell instead of the empty dash", () => { |
| 213 | // A column with no accessorFn has no value to be empty, so the empty-cell |
| 214 | // fallback must not swallow its render function. |
| 215 | render(() => ( |
| 216 | <PreferencesProvider> |
| 217 | <DataTable |
| 218 | columns={[ |
| 219 | { accessorKey: "name", header: "Name" }, |
| 220 | { id: "label", header: "Label", cell: (c) => `#${c.row.original.name}` }, |
| 221 | ] as ColumnDef<Row>[]} |
| 222 | data={[{ name: "ada" }]} |
| 223 | /> |
| 224 | </PreferencesProvider> |
| 225 | )); |
| 226 | |
| 227 | expect(screen.getByText("#ada")).toBeTruthy(); |
| 228 | }); |
| 229 | |
| 230 | test("the header action toolbar of every shared host can shrink below its max-content width", () => { |
| 231 | // `shrink-0` plus the flex default `min-width: auto` pinned the toolbar to |
| 232 | // its max-content width, so a wide action row pushed the whole document |
| 233 | // past a 390px viewport instead of wrapping inside the constrained parent. |
| 234 | render(() => ( |
| 235 | <> |
| 236 | <PreferencesProvider> |
| 237 | <DataTable |
| 238 | columns={[columns[0]]} |
| 239 | data={[{ name: "Ada" }]} |
| 240 | enableColumnVisibility={false} |
| 241 | actions={<button type="button">Export</button>} |
| 242 | /> |
| 243 | </PreferencesProvider> |
| 244 | <DataSection title="Card" actions={<button type="button">Export</button>} /> |
| 245 | <PageHeader title="Page" actions={<button type="button">Export</button>} /> |
| 246 | </> |
| 247 | )); |
| 248 | |
| 249 | const toolbars = screen.getAllByText("Export").map((action) => action.parentElement as HTMLElement); |
| 250 | expect(toolbars).toHaveLength(3); |
| 251 | for (const toolbar of toolbars) { |
| 252 | expect(toolbar.classList).toContain("flex-wrap"); |
| 253 | expect(toolbar.classList).toContain("min-w-0"); |
| 254 | expect(toolbar.classList).not.toContain("shrink-0"); |
| 255 | } |
| 256 | }); |
| 257 | |
| 258 | test("a search that matches nothing says so and clears back to the list", () => { |
| 259 | render(() => ( |
| 260 | <PreferencesProvider> |
| 261 | <DataTable |
| 262 | columns={columns} |
| 263 | data={[{ name: "Ada" }]} |
| 264 | empty="No people yet." |
| 265 | enableColumnVisibility={false} |
| 266 | searchPredicate={(row, query) => row.name.toLowerCase().includes(query.toLowerCase())} |
| 267 | /> |
| 268 | </PreferencesProvider> |
| 269 | )); |
| 270 | |
| 271 | fireEvent.input(screen.getByRole("textbox"), { target: { value: "zzz" } }); |
| 272 | expect(screen.queryByText("No people yet.")).toBeNull(); |
| 273 | expect(screen.getByText(/No results for “zzz”|“zzz” için sonuç yok/)).toBeTruthy(); |
| 274 | |
| 275 | fireEvent.click(within(screen.getByRole("table")).getByRole("button", { name: /Clear search|Aramayı temizle/ })); |
| 276 | expect(screen.getByText("Ada")).toBeTruthy(); |
| 277 | }); |
| 278 | |
| 279 | test("a server-paged table offers no header sort, since it could only sort one page", () => { |
| 280 | const sortable: ColumnDef<Row>[] = [{ accessorKey: "name", header: "Name" }]; |
| 281 | const { unmount } = render(() => ( |
| 282 | <PreferencesProvider> |
| 283 | <DataTable columns={sortable} data={[{ name: "Ada" }]} enableColumnVisibility={false} /> |
| 284 | </PreferencesProvider> |
| 285 | )); |
| 286 | expect(screen.getByRole("button", { name: /Name/ })).toBeTruthy(); |
| 287 | unmount(); |
| 288 | |
| 289 | render(() => ( |
| 290 | <PreferencesProvider> |
| 291 | <DataTable |
| 292 | columns={sortable} |
| 293 | data={[{ name: "Ada" }]} |
| 294 | enableColumnVisibility={false} |
| 295 | manualPagination={{ pageIndex: 0, pageSize: 10, total: 40, onPageChange: () => {} }} |
| 296 | /> |
| 297 | </PreferencesProvider> |
| 298 | )); |
| 299 | expect(screen.queryByRole("button", { name: /^Name/ })).toBeNull(); |
| 300 | }); |
| 301 | |
| 302 | test("on a phone-width screen rows render as labelled cards instead of a sideways table", () => { |
| 303 | vi.stubGlobal("matchMedia", (query: string) => ({ |
| 304 | matches: query.includes("max-width"), |
| 305 | addEventListener: () => {}, |
| 306 | removeEventListener: () => {}, |
| 307 | })); |
| 308 | const cardColumns: ColumnDef<Row>[] = [ |
| 309 | { accessorKey: "name", header: "Name" }, |
| 310 | { accessorKey: "role", header: "Role" }, |
| 311 | { id: "actions", header: "Actions", cell: () => <button type="button">Menu</button> }, |
| 312 | ]; |
| 313 | const onRowClick = vi.fn(); |
| 314 | render(() => ( |
| 315 | <PreferencesProvider> |
| 316 | <DataTable columns={cardColumns} data={[{ name: "Ada", role: "teacher" }]} enableColumnVisibility={false} onRowClick={onRowClick} /> |
| 317 | </PreferencesProvider> |
| 318 | )); |
| 319 | |
| 320 | expect(screen.queryByRole("table")).toBeNull(); |
| 321 | const card = screen.getByRole("listitem"); |
| 322 | expect(within(card).getByText("Ada")).toBeTruthy(); |
| 323 | expect(within(card).getByText("Role")).toBeTruthy(); |
| 324 | expect(within(card).getByText("teacher")).toBeTruthy(); |
| 325 | |
| 326 | fireEvent.click(within(card).getByRole("button", { name: "Menu" })); |
| 327 | expect(onRowClick).not.toHaveBeenCalled(); |
| 328 | fireEvent.click(within(card).getByText("teacher")); |
| 329 | expect(onRowClick).toHaveBeenCalledOnce(); |
| 330 | vi.unstubAllGlobals(); |
| 331 | }); |
| 332 | |
| 333 | test("a pick in a row's portalled menu does not also open the row", () => { |
| 334 | const portalColumns: ColumnDef<Row>[] = [ |
| 335 | { accessorKey: "name", header: "Name" }, |
| 336 | { |
| 337 | id: "actions", |
| 338 | header: "Actions", |
| 339 | cell: () => ( |
| 340 | <Portal> |
| 341 | <div role="menuitem">Edit</div> |
| 342 | </Portal> |
| 343 | ), |
| 344 | }, |
| 345 | ]; |
| 346 | const onRowClick = vi.fn(); |
| 347 | render(() => ( |
| 348 | <PreferencesProvider> |
| 349 | <DataTable columns={portalColumns} data={[{ name: "Ada" }]} enableColumnVisibility={false} onRowClick={onRowClick} /> |
| 350 | </PreferencesProvider> |
| 351 | )); |
| 352 | |
| 353 | fireEvent.click(screen.getAllByRole("menuitem", { name: "Edit" })[0]!); |
| 354 | expect(onRowClick).not.toHaveBeenCalled(); |
| 355 | fireEvent.click(screen.getAllByText("Ada")[0]!); |
| 356 | expect(onRowClick).toHaveBeenCalledOnce(); |
| 357 | }); |
| 358 | |
| 359 | test("sortable headers expose their order through aria-sort", () => { |
| 360 | const sortable: ColumnDef<Row>[] = [ |
| 361 | { accessorKey: "name", header: "Name" }, |
| 362 | { accessorKey: "role", header: "Role", enableSorting: false }, |
| 363 | ]; |
| 364 | render(() => ( |
| 365 | <PreferencesProvider> |
| 366 | <DataTable columns={sortable} data={[{ name: "Ada", role: "a" }, { name: "Bo", role: "b" }]} enableColumnVisibility={false} /> |
| 367 | </PreferencesProvider> |
| 368 | )); |
| 369 | const [nameHeader, roleHeader] = screen.getAllByRole("columnheader"); |
| 370 | expect(nameHeader?.getAttribute("aria-sort")).toBe("none"); |
| 371 | expect(roleHeader?.hasAttribute("aria-sort")).toBe(false); |
| 372 | fireEvent.click(within(nameHeader!).getByRole("button")); |
| 373 | expect(nameHeader?.getAttribute("aria-sort")).toBe("ascending"); |
| 374 | fireEvent.click(within(nameHeader!).getByRole("button")); |
| 375 | expect(nameHeader?.getAttribute("aria-sort")).toBe("descending"); |
| 376 | }); |
| 377 | |
| 378 | test("an empty list narrowed by the caller's filters offers to clear them", () => { |
| 379 | const onClearFilters = vi.fn(); |
| 380 | render(() => ( |
| 381 | <PreferencesProvider> |
| 382 | <DataTable columns={columns} data={[]} empty="No people yet." enableColumnVisibility={false} filtersActive onClearFilters={onClearFilters} /> |
| 383 | </PreferencesProvider> |
| 384 | )); |
| 385 | expect(screen.queryByText("No people yet.")).toBeNull(); |
| 386 | fireEvent.click(screen.getByRole("button", { name: /Clear filters|Filtreleri temizle/ })); |
| 387 | expect(onClearFilters).toHaveBeenCalledOnce(); |
| 388 | }); |
| 389 | |
| 390 | test("the client page holds when the caller hands over a fresh data array", () => { |
| 391 | const [tick, setTick] = createSignal(0); |
| 392 | const people = Array.from({ length: 70 }, (_, i) => ({ name: `P${String(i).padStart(2, "0")}` })); |
| 393 | render(() => ( |
| 394 | <PreferencesProvider> |
| 395 | <DataTable columns={[{ accessorKey: "name", header: "Name" }]} data={(tick(), people.map((row) => ({ ...row })))} enableColumnVisibility={false} /> |
| 396 | </PreferencesProvider> |
| 397 | )); |
| 398 | fireEvent.click(screen.getByRole("button", { name: /Next|Sonraki/ })); |
| 399 | expect(screen.getByText("P10")).toBeTruthy(); |
| 400 | setTick(1); |
| 401 | expect(screen.getByText("P10")).toBeTruthy(); |
| 402 | expect(screen.queryByText("P00")).toBeNull(); |
| 403 | }); |
| 404 | test("a toolbar holding only the column menu still gets its card", () => { |
| 405 | const { container } = render(() => ( |
| 406 | <PreferencesProvider> |
| 407 | <DataTable columns={[{ accessorKey: "name", header: "Name" }, { accessorKey: "role", header: "Role" }]} data={[{ name: "Ada", role: "a" }]} /> |
| 408 | </PreferencesProvider> |
| 409 | )); |
| 410 | const toolbar = container.querySelector(".space-y-3 > div"); |
| 411 | expect(toolbar?.className).toContain("rounded-xl"); |
| 412 | }); |
| 413 | |
| 414 | test("page actions in the toolbar take the shared control height", () => { |
| 415 | const { container } = render(() => ( |
| 416 | <PreferencesProvider> |
| 417 | <DataTable |
| 418 | columns={[{ accessorKey: "name", header: "Name" }, { accessorKey: "role", header: "Role" }]} |
| 419 | data={[{ name: "Ada", role: "a" }]} |
| 420 | actions={<button type="button">Add</button>} |
| 421 | /> |
| 422 | </PreferencesProvider> |
| 423 | )); |
| 424 | const add = [...container.querySelectorAll("button")].find((el) => el.textContent === "Add"); |
| 425 | expect(add?.parentElement?.className).toContain("sm:[&_button]:h-8"); |
| 426 | }); |
| 427 | |
| 428 | test("meta.headerInfo puts a labelled info icon beside the header that opens without sorting", async () => { |
| 429 | const withInfo: ColumnDef<Row>[] = [ |
| 430 | { accessorKey: "name", header: "Name" }, |
| 431 | { accessorKey: "role", header: "Average", meta: { headerInfo: "Filled in for small schools only." } }, |
| 432 | ]; |
| 433 | render(() => ( |
| 434 | <PreferencesProvider> |
| 435 | <DataTable columns={withInfo} data={[{ name: "Ada", role: "b" }, { name: "Bo", role: "a" }]} enableColumnVisibility={false} /> |
| 436 | </PreferencesProvider> |
| 437 | )); |
| 438 | const info = screen.getByRole("button", { name: /About Average|Average hakkında bilgi/ }); |
| 439 | const header = info.closest("th"); |
| 440 | expect(header?.getAttribute("aria-sort")).toBe("none"); |
| 441 | // Beside the sort button, never inside it: a button in a button is invalid. |
| 442 | expect(info.parentElement?.closest("button")).toBeNull(); |
| 443 | expect(screen.getAllByRole("columnheader")).toHaveLength(2); |
| 444 | expect(screen.queryByText("Filled in for small schools only.")).toBeNull(); |
| 445 | |
| 446 | fireEvent.click(info); |
| 447 | expect(header?.getAttribute("aria-sort")).toBe("none"); |
| 448 | expect(await screen.findByText("Filled in for small schools only.")).toBeTruthy(); |
| 449 | // No always-visible copy of the note is left in the table. |
| 450 | expect(document.querySelector("table")?.textContent).not.toContain("Filled in for small schools only."); |
| 451 | }); |
| 452 | |
| 453 | test("an infinite table asks for the next page near its end and does not sort", async () => { |
| 454 | const reachEnd = stubIntersectionObserver(); |
| 455 | const onLoadMore = vi.fn(); |
| 456 | const rows = Array.from({ length: 50 }, (_, index) => ({ name: `Person ${index + 1}` })); |
| 457 | try { |
| 458 | render(() => ( |
| 459 | <PreferencesProvider> |
| 460 | <DataTable |
| 461 | columns={[columns[0]]} |
| 462 | data={rows} |
| 463 | enableColumnVisibility={false} |
| 464 | infinite={{ hasMore: true, loading: false, total: 120, onLoadMore }} |
| 465 | /> |
| 466 | </PreferencesProvider> |
| 467 | )); |
| 468 | expect(screen.getByText("Person 50")).toBeTruthy(); |
| 469 | expect(screen.getByText(/(Showing 50 of 120|120 kayıttan 50)/)).toBeTruthy(); |
| 470 | expect(screen.getByRole("columnheader").getAttribute("aria-sort")).not.toBe("ascending"); |
| 471 | reachEnd(); |
| 472 | expect(onLoadMore).toHaveBeenCalledTimes(1); |
| 473 | } finally { |
| 474 | vi.unstubAllGlobals(); |
| 475 | } |
| 476 | }); |