From dc4db405d2991d3ec6a114f3b08d3fccd057d3ee Mon Sep 17 00:00:00 2001
From: Wolfgang Müller
Date: Thu, 13 Feb 2025 17:52:16 +0100
Subject: frontend: Migrate to Svelte 5

---
 frontend/tests/Reader.test.ts    |  3 +-
 frontend/tests/Selection.test.ts | 92 ++++++++++++++++++++++------------------
 2 files changed, 52 insertions(+), 43 deletions(-)

(limited to 'frontend/tests')

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);
-- 
cgit v1.2.3-2-gb3c3