diff options
author | Wolfgang Müller | 2025-02-13 17:52:16 +0100 |
---|---|---|
committer | Wolfgang Müller | 2025-02-13 17:52:16 +0100 |
commit | dc4db405d2991d3ec6a114f3b08d3fccd057d3ee (patch) | |
tree | 2c620c9af2062ba09fa591f8b3ed961664adab58 /frontend/tests | |
parent | 4df870d793123be95c8af031a340a39b5b8402ac (diff) | |
download | hircine-dc4db405d2991d3ec6a114f3b08d3fccd057d3ee.tar.gz |
frontend: Migrate to Svelte 5
Diffstat (limited to 'frontend/tests')
-rw-r--r-- | frontend/tests/Reader.test.ts | 3 | ||||
-rw-r--r-- | frontend/tests/Selection.test.ts | 92 |
2 files changed, 52 insertions, 43 deletions
diff --git a/frontend/tests/Reader.test.ts b/frontend/tests/Reader.test.ts index e12d69b..a4928af 100644 --- a/frontend/tests/Reader.test.ts +++ b/frontend/tests/Reader.test.ts @@ -1,5 +1,6 @@ import { Layout, type PageFragment } from '$gql/graphql'; -import { partition, type Chunk } from '$lib/Reader'; +import { partition, type Chunk } from '$lib/reader/Reader.svelte'; + import { expect, test } from 'vitest'; const normalAttrs = { aspectRatio: 0.7, width: 140, height: 200 }; diff --git a/frontend/tests/Selection.test.ts b/frontend/tests/Selection.test.ts index c7847cd..1bdbb55 100644 --- a/frontend/tests/Selection.test.ts +++ b/frontend/tests/Selection.test.ts @@ -1,4 +1,4 @@ -import { ItemSelection } from '$lib/Selection'; +import { ItemSelection } from '$lib/selection/Selection.svelte'; import { expect, test } from 'vitest'; interface TestItem { @@ -17,100 +17,104 @@ const all = items.map((i) => i.id); const selectable = items.filter((i) => i.selectable).map((i) => i.id); const setup = () => { - const selection = new ItemSelection<TestItem>(); + const selection = new ItemSelection<TestItem>('test', (t) => t.id.toString()); selection.view = items; return selection; }; test('selects a single item', () => { - let selection = setup(); + const selection = setup(); - selection = selection.update(0, false); + selection.update(0, false); expect(selection.ids).toStrictEqual([items[0].id]); }); test('selects a single item (with empty shift select)', () => { - let selection = setup(); + const selection = setup(); - selection = selection.update(0, true); + selection.update(0, true); expect(selection.ids).toStrictEqual([items[0].id]); }); test('selects multiple items (forwards)', () => { - let selection = setup(); + const selection = setup(); - selection = selection.update(0, false); - selection = selection.update(2, true); + selection.update(0, false); + selection.update(2, true); expect(selection.ids.toSorted((a, b) => a - b)).toStrictEqual(all.slice(0, 3)); }); test('selects multiple items (backwards)', () => { - let selection = setup(); + const selection = setup(); - selection = selection.update(2, false); - selection = selection.update(0, true); + selection.update(2, false); + selection.update(0, true); expect(selection.ids.toSorted((a, b) => a - b)).toStrictEqual(all.slice(0, 3)); }); test('selects multiple items (only selectables)', () => { - let selection = setup(); + const selection = setup(); selection.selectable = (i) => i.selectable; - selection = selection.update(0, false); - selection = selection.update(3, true); + selection.update(0, false); + selection.update(3, true); expect(selection.ids).toStrictEqual(selectable); }); test('selects all', () => { - const selection = setup().all(); + const selection = setup(); + + selection.all(); expect(selection.ids).toStrictEqual(all); }); test('selects all selectables', () => { - let selection = setup(); + const selection = setup(); selection.selectable = (i) => i.selectable; - selection = selection.all(); + selection.all(); expect(selection.ids).toStrictEqual(selectable); }); test('deselects all', () => { - let selection = setup().all(); + const selection = setup(); - selection = selection.none(); + selection.all(); + selection.none(); expect(selection.ids).toHaveLength(0); }); test('deselects a single item', () => { - let selection = setup().all(); + const selection = setup(); - selection = selection.update(0, false); + selection.all(); + selection.update(0, false); expect(selection.ids).toStrictEqual(all.slice(1)); }); test('deselects multiple items', () => { - let selection = setup(); + const selection = setup(); - selection = selection.update(0, false); - selection = selection.update(2, true); - selection = selection.update(2, true); + selection.update(0, false); + selection.update(2, true); + selection.update(2, true); expect(selection.ids).toHaveLength(0); }); test('retains selection', () => { - let selection = setup(); + const selection = setup(); - selection = selection.all(); + selection.all(); selection.view = items.slice(0, 2); expect(selection.ids).toStrictEqual(all.slice(0, 2)); @@ -125,40 +129,40 @@ test('is inactive by default', () => { }); test('is inactive after clearing', () => { - let selection = setup(); + const selection = setup(); selection.active = true; - selection = selection.clear(); + selection.clear(); expect(selection.active).toBeFalsy(); }); test('can be toggled', () => { - let selection = setup(); + const selection = setup(); - selection = selection.toggle(); + selection.toggle(); expect(selection.active).toBe(true); - selection = selection.all(); - selection = selection.toggle(); + selection.all(); + selection.toggle(); expect(selection.active).toBe(false); expect(selection.ids).toHaveLength(0); }); test('can be cleared', () => { - let selection = setup(); + const selection = setup(); - selection = selection.all(); + selection.all(); - selection = selection.clear(); + selection.clear(); expect(selection.ids).toHaveLength(0); }); test('reports selected items', () => { - let selection = setup(); + const selection = setup(); - selection = selection.update(0, false); - selection = selection.update(2, false); + selection.update(0, false); + selection.update(2, false); expect(selection.contains(all[0])).toBeTruthy(); expect(selection.contains(all[1])).toBeFalsy(); @@ -167,13 +171,17 @@ test('reports selected items', () => { }); test('reports size', () => { - const selection = setup().all(); + const selection = setup(); + + selection.all(); expect(selection.size).toBe(all.length); }); test('reports size of visible items', () => { - const selection = setup().all(); + const selection = setup(); + + selection.all(); selection.view = items.slice(0, 2); expect(selection.size).toBe(2); |