Skip to content

Commit

Permalink
fix: Make url optional to make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
klawr committed Dec 15, 2024
1 parent 465163e commit 9d1bc74
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
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()}`
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

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 {
Expand Down Expand Up @@ -47,7 +48,8 @@ function createEntryMocks(entries: number) {
new Date(),
[],
[],
[]
[],
new WalterPermissions(true, true, true)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -47,7 +48,8 @@ function createEntryMocks(entries: number) {
{ id: 1, text: 'Testtyp' },
{ id: 2, text: 'Testumlage' },
[],
[]
[],
new WalterPermissions(true, true, true)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -50,12 +51,13 @@ function createEntryMocks(entries: number) {
new Date(),
{ id: 0, text: 'Herr' },
[],
null,
undefined,
[],
[],
[],
[],
[]
[],
new WalterPermissions(true, true, true)
)
);
}
Expand Down

0 comments on commit 9d1bc74

Please sign in to comment.