fix fake URL in test fixtures pointing to 404-page and refactoring magic strings URLs
This commit is contained in:
@@ -4,6 +4,7 @@ import * as nav from '$app/navigation';
|
|||||||
import TatortListPage from '../src/routes/(token-based)/list/[vorgang]/+page.svelte';
|
import TatortListPage from '../src/routes/(token-based)/list/[vorgang]/+page.svelte';
|
||||||
import { baseData } from './fixtures';
|
import { baseData } from './fixtures';
|
||||||
import { tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
|
import { API_ROUTES } from '../src/routes';
|
||||||
|
|
||||||
vi.spyOn(nav, 'invalidateAll').mockResolvedValue();
|
vi.spyOn(nav, 'invalidateAll').mockResolvedValue();
|
||||||
global.fetch = vi.fn().mockResolvedValue({ ok: true });
|
global.fetch = vi.fn().mockResolvedValue({ ok: true });
|
||||||
@@ -50,6 +51,7 @@ describe('Seite: Vorgangsansicht', () => {
|
|||||||
it('führt DELETE-Request aus und entfernt Element aus UI', async () => {
|
it('führt DELETE-Request aus und entfernt Element aus UI', async () => {
|
||||||
const testData = structuredClone(baseData);
|
const testData = structuredClone(baseData);
|
||||||
const oldName = testData.crimesList[0].name;
|
const oldName = testData.crimesList[0].name;
|
||||||
|
const vorgang = testData.vorgang;
|
||||||
|
|
||||||
render(TatortListPage, { props: { data: testData } });
|
render(TatortListPage, { props: { data: testData } });
|
||||||
const initialItems = screen.getAllByTestId('test-list-item');
|
const initialItems = screen.getAllByTestId('test-list-item');
|
||||||
@@ -62,10 +64,9 @@ describe('Seite: Vorgangsansicht', () => {
|
|||||||
await fireEvent.click(within(listItem).getByTestId('delete-button'));
|
await fireEvent.click(within(listItem).getByTestId('delete-button'));
|
||||||
await tick();
|
await tick();
|
||||||
|
|
||||||
let expectedPath = new URL(testData.url).pathname;
|
let expectedPath = API_ROUTES.CRIME(vorgang.vorgangToken, oldName)
|
||||||
expectedPath += `/${oldName}`
|
|
||||||
expect(global.fetch).toHaveBeenCalledWith(
|
expect(global.fetch).toHaveBeenCalledWith(
|
||||||
`/api${expectedPath}`,
|
expectedPath,
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export const baseData = {
|
|||||||
vorgang: testVorgangsList[0],
|
vorgang: testVorgangsList[0],
|
||||||
vorgangList: testVorgangsList,
|
vorgangList: testVorgangsList,
|
||||||
crimesList: testCrimesList,
|
crimesList: testCrimesList,
|
||||||
url: `https://example.com/${testVorgangsList[0].vorgangToken}`,
|
url: `https://example.com/list/${testVorgangsList[0].vorgangToken}`,
|
||||||
crimeNames: ['modell-A', 'Fall-A']
|
crimeNames: ['modell-A', 'Fall-A']
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user