104 lines
3.9 KiB
TypeScript
104 lines
3.9 KiB
TypeScript
import { render, screen, within } from '@testing-library/svelte';
|
|
import { describe, expect, it, test } from 'vitest';
|
|
import TatortListPage from '../src/routes/(token-based)/list/[vorgang]/+page.svelte';
|
|
import { baseData } from './fixtures';
|
|
import { ROUTE_NAMES } from '../src/routes';
|
|
|
|
describe('Seite: Vorgangsansicht', () => {
|
|
test.todo('zeigt PIN und Share-Link, wenn Admin');
|
|
test.todo('zeigt PIN und Share-Link disabeld, wenn Liste leer');
|
|
|
|
describe('Szenario: Liste leer (unabhängig von Rolle)', () => {
|
|
it('zeigt Hinweistext bei leerer Liste', () => {
|
|
const testData = { ...baseData, crimesList: [] };
|
|
const { getByTestId } = render(TatortListPage, { props: { data: testData } });
|
|
|
|
expect(getByTestId('empty-list')).toBeInTheDocument();
|
|
});
|
|
|
|
it('zeigt keinen Listeneintrag', () => {
|
|
const items = screen.queryAllByTestId('test-list-item');
|
|
|
|
expect(items).toHaveLength(0);
|
|
});
|
|
});
|
|
|
|
describe('Szenario: Liste gefüllt (unabhängig von Rolle)', () => {
|
|
it('rendert mindestens ein Listenelement bei vorhandenen crimesList-Daten', () => {
|
|
const testData = { ...baseData };
|
|
const { queryAllByTestId } = render(TatortListPage, { props: { data: testData } });
|
|
const items = queryAllByTestId('test-list-item');
|
|
|
|
expect(items.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('zeigt für jeden Eintrag einen Link', () => {
|
|
const testData = { ...baseData };
|
|
render(TatortListPage, { props: { data: testData } });
|
|
const links = screen.queryAllByTestId('crime-link');
|
|
|
|
expect(links).toHaveLength(testData.crimesList.length);
|
|
});
|
|
|
|
it('prüft href und title jedes Links', () => {
|
|
const testData = { ...baseData };
|
|
const { queryAllByTestId } = render(TatortListPage, { props: { data: testData } });
|
|
const items = queryAllByTestId('test-list-item');
|
|
|
|
items.forEach((item, i) => {
|
|
const link = within(item).getByRole('link');
|
|
const expectedHref = `/view/${testData.vorgang.vorgangToken}/${testData.crimesList[i].name}?pin=${testData.vorgang.vorgangPIN}`;
|
|
|
|
expect(link).toBeInTheDocument();
|
|
expect(link).toHaveAttribute('href', expectedHref);
|
|
expect(link).toHaveAttribute('title', testData.crimesList[i].name);
|
|
});
|
|
});
|
|
|
|
test.todo('testet zuletzt angezeigt, wenn item.lastModified');
|
|
test.todo('zeigt Dateigröße, wenn item.size vorhanden ist');
|
|
});
|
|
|
|
describe('Szenario: Admin + Liste gefüllt', () => {
|
|
const testData = { ...baseData, user: { ...baseData.user, admin: true } };
|
|
it('zeigt Listeneinträge mit Komponente NameItemEditor', () => {
|
|
const { getAllByTestId } = render(TatortListPage, { props: { data: testData } });
|
|
const items = getAllByTestId('test-nameItemEditor');
|
|
|
|
expect(items.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test.todo('Modal testen, wenn open');
|
|
});
|
|
|
|
describe('Szenario: Viewer + Liste gefüllt', () => {
|
|
const testData = { ...baseData, user: { ...baseData.user, admin: false } };
|
|
it('zeigt Listeneinträge mit p', () => {
|
|
render(TatortListPage, { props: { data: testData } });
|
|
const paragraphs = screen.queryAllByTestId('test-nameItem-p');
|
|
|
|
expect(paragraphs).toHaveLength(testData.crimesList.length);
|
|
paragraphs.forEach((p, i) => {
|
|
expect(p).toHaveTextContent(testData.crimesList[i].name);
|
|
});
|
|
});
|
|
|
|
test.todo('zeigt keinen Share-Link oder PIN');
|
|
});
|
|
|
|
describe('Teste Links auf Korrektheit', () => {
|
|
it('Überprüfe Links', () => {
|
|
const crimesListOneItem = baseData.crimesList.slice(0, 1);
|
|
const crimeObj = crimesListOneItem[0];
|
|
const vorgObj = baseData.vorgangList[0]
|
|
const expectedURL = ROUTE_NAMES.CRIME(vorgObj.vorgangToken, crimeObj.name, vorgObj.vorgangPIN)
|
|
|
|
render(TatortListPage, { props: { data: { ...baseData, crimesList: crimesListOneItem } } });
|
|
const listItem = screen.getByTestId("test-list-item");
|
|
const linkElement = within(listItem).getByRole('link');
|
|
expect(linkElement).toBeInTheDocument();
|
|
expect(linkElement).toHaveAttribute('href', expectedURL);
|
|
});
|
|
});
|
|
});
|