From 9d1bc7457cac8b2ced7ca244c7e567b76a621fc4 Mon Sep 17 00:00:00 2001 From: Kai Date: Sun, 15 Dec 2024 22:19:34 +0000 Subject: [PATCH] fix: Make url optional to make tests pass --- .../elements/WalterDataTable.svelte | 28 +++++++++++++------ .../components/lists/WalterAdressen.test.ts | 6 ++-- .../WalterBetriebskostenrechnungen.test.ts | 4 ++- .../WalterErhaltungsaufwendungen.test.ts | 4 ++- .../components/lists/WalterKontakte.test.ts | 6 ++-- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Deeplex.Saverwalter.WebAPI/svelte/src/components/elements/WalterDataTable.svelte b/Deeplex.Saverwalter.WebAPI/svelte/src/components/elements/WalterDataTable.svelte index 988e51f9..74a7278d 100644 --- a/Deeplex.Saverwalter.WebAPI/svelte/src/components/elements/WalterDataTable.svelte +++ b/Deeplex.Saverwalter.WebAPI/svelte/src/components/elements/WalterDataTable.svelte @@ -48,16 +48,28 @@ along with this program. If not, see . export let rows: unknown[]; export let add: (() => void) | undefined = undefined; - const searchParams: URLSearchParams = new URL($page.url).searchParams; - let searchQuery = searchParams.get('search') || ''; + const searchParams: URLSearchParams | null = $page + ? new URL($page.url).searchParams + : null; + let searchQuery = searchParams?.get('search') || ''; function toolbarSearchInput() { - if (searchQuery) { - searchParams.set('search', searchQuery); - window.history.replaceState({}, '', `?${searchParams.toString()}`); - } else { - searchParams.delete('search'); - window.history.replaceState({}, '', `?${searchParams.toString()}`); + if (searchParams) { + if (searchQuery) { + searchParams.set('search', searchQuery); + window.history.replaceState( + {}, + '', + `?${searchParams.toString()}` + ); + } else { + searchParams.delete('search'); + window.history.replaceState( + {}, + '', + `?${searchParams.toString()}` + ); + } } } diff --git a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterAdressen.test.ts b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterAdressen.test.ts index 29a18eb2..53170c4b 100644 --- a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterAdressen.test.ts +++ b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterAdressen.test.ts @@ -13,12 +13,13 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import { expect, describe, it, afterEach, vi, beforeEach } from 'vitest'; +import { expect, describe, it, afterEach, vi } from 'vitest'; import { render, cleanup } from '@testing-library/svelte'; import { writable } from 'svelte/store'; import Page from './WalterAdressen.svelte'; import { WalterAdresseEntry } from '$walter/lib'; +import { WalterPermissions } from '$walter/lib/WalterPermissions'; vi.mock('$app/stores', async (importOriginal) => { return { @@ -47,7 +48,8 @@ function createEntryMocks(entries: number) { new Date(), [], [], - [] + [], + new WalterPermissions(true, true, true) ) ); } diff --git a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterBetriebskostenrechnungen.test.ts b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterBetriebskostenrechnungen.test.ts index 304dd1fb..345a62ce 100644 --- a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterBetriebskostenrechnungen.test.ts +++ b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterBetriebskostenrechnungen.test.ts @@ -20,6 +20,7 @@ import { writable } from 'svelte/store'; import Page from './WalterBetriebskostenrechnungen.svelte'; import { WalterBetriebskostenrechnungEntry } from '$walter/lib'; import { convertDateGerman } from '$walter/services/utils'; +import { WalterPermissions } from '$walter/lib/WalterPermissions'; vi.mock('$app/stores', async (importOriginal) => { return { @@ -47,7 +48,8 @@ function createEntryMocks(entries: number) { { id: 1, text: 'Testtyp' }, { id: 2, text: 'Testumlage' }, [], - [] + [], + new WalterPermissions(true, true, true) ) ); } diff --git a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterErhaltungsaufwendungen.test.ts b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterErhaltungsaufwendungen.test.ts index 3dfc90df..7597b752 100644 --- a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterErhaltungsaufwendungen.test.ts +++ b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterErhaltungsaufwendungen.test.ts @@ -20,6 +20,7 @@ import { writable } from 'svelte/store'; import Page from './WalterErhaltungsaufwendungen.svelte'; import { WalterErhaltungsaufwendungEntry } from '$walter/lib'; import { convertDateGerman } from '$walter/services/utils'; +import { WalterPermissions } from '$walter/lib/WalterPermissions'; vi.mock('$app/stores', async (importOriginal) => { return { @@ -45,7 +46,8 @@ function createEntryMocks(entries: number) { new Date(), new Date(), { id: 1, text: 'Testwohnung' }, - { id: 2, text: 'Testaussteller' } + { id: 2, text: 'Testaussteller' }, + new WalterPermissions(true, true, true) ) ); } diff --git a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterKontakte.test.ts b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterKontakte.test.ts index 02c275c4..eb2dc113 100644 --- a/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterKontakte.test.ts +++ b/Deeplex.Saverwalter.WebAPI/svelte/src/components/lists/WalterKontakte.test.ts @@ -19,6 +19,7 @@ import { writable } from 'svelte/store'; import Page from './WalterKontakte.svelte'; import { WalterKontaktEntry } from '$walter/lib'; +import { WalterPermissions } from '$walter/lib/WalterPermissions'; vi.mock('$app/stores', async (importOriginal) => { return { @@ -50,12 +51,13 @@ function createEntryMocks(entries: number) { new Date(), { id: 0, text: 'Herr' }, [], - null, + undefined, [], [], [], [], - [] + [], + new WalterPermissions(true, true, true) ) ); }