forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

table-preferences.test.tsx46 lines, 1.3 KiBHistoryRawDownload
1import { fireEvent, render, screen } from "@solidjs/testing-library";
2import {
3 createTablePreferences,
4 defaultTablePreferences,
5 readTablePreferences,
6} from "@/lib/table-preferences";
7
8const key = "users";
9const storageKey = `hezarfen.table.${key}`;
10
11beforeEach(() => localStorage.clear());
12
13test("reads saved visibility", () => {
14 localStorage.setItem(
15 storageKey,
16 JSON.stringify({ visibility: { email: false } }),
17 );
18
19 expect(readTablePreferences(key)).toEqual({ visibility: { email: false } });
20});
21
22test("falls back to defaults for broken storage", () => {
23 localStorage.setItem(storageKey, "{broken");
24 expect(readTablePreferences(key)).toEqual(defaultTablePreferences);
25});
26
27function PreferencesProbe() {
28 const controller = createTablePreferences(key);
29 return (
30 <>
31 <output data-testid="preferences">{JSON.stringify(controller.preferences())}</output>
32 <button type="button" onClick={() => controller.setVisibility({ email: false })}>visibility</button>
33 </>
34 );
35}
36
37test("persists visibility changes", () => {
38 render(() => <PreferencesProbe />);
39
40 fireEvent.click(screen.getByRole("button", { name: "visibility" }));
41
42 expect(JSON.parse(localStorage.getItem(storageKey) ?? "{}")).toEqual({
43 visibility: { email: false },
44 });
45 expect(screen.getByTestId("preferences").textContent).toContain('"email":false');
46});