Adds SkippedFile to the local ImportStatus type and updates ImportStatusCard to show an amber skipped-count section with a collapsible filename list in the DONE state. Only rendered when skipped > 0. i18n keys added for de/en/es. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
183 lines
5.3 KiB
TypeScript
183 lines
5.3 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { render } from 'vitest-browser-svelte';
|
|
import { m } from '$lib/paraglide/messages.js';
|
|
import ImportStatusCard from './ImportStatusCard.svelte';
|
|
import type { ImportStatus } from './types.js';
|
|
|
|
const makeStatus = (overrides: Partial<ImportStatus> = {}): ImportStatus => ({
|
|
state: 'IDLE',
|
|
statusCode: 'IMPORT_IDLE',
|
|
processed: 0,
|
|
skipped: 0,
|
|
skippedFiles: [],
|
|
startedAt: null,
|
|
...overrides
|
|
});
|
|
|
|
describe('ImportStatusCard', () => {
|
|
it('shows spinner while state is RUNNING', async () => {
|
|
const { getByTestId } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'RUNNING', statusCode: 'IMPORT_RUNNING', processed: 3 }),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByTestId('spinner')).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows processed count at text-base while RUNNING', async () => {
|
|
const { getByTestId } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'RUNNING', statusCode: 'IMPORT_RUNNING', processed: 7 }),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByTestId('processed-count')).toHaveTextContent('7');
|
|
});
|
|
|
|
it('shows processed count while DONE', async () => {
|
|
const { getByText } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'DONE', statusCode: 'IMPORT_DONE', processed: 42 }),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByText('42')).toBeVisible();
|
|
});
|
|
|
|
it('shows no-spreadsheet message when statusCode is IMPORT_FAILED_NO_SPREADSHEET', async () => {
|
|
const { getByText } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({
|
|
state: 'FAILED',
|
|
statusCode: 'IMPORT_FAILED_NO_SPREADSHEET'
|
|
}),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByText(m.admin_system_import_failed_no_spreadsheet())).toBeVisible();
|
|
});
|
|
|
|
it('shows internal error message when statusCode is IMPORT_FAILED_INTERNAL', async () => {
|
|
const { getByText } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'FAILED', statusCode: 'IMPORT_FAILED_INTERNAL' }),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByText(m.admin_system_import_failed_internal())).toBeVisible();
|
|
});
|
|
|
|
it('shows idle text when importStatus is non-null and state is IDLE', async () => {
|
|
const { getByText } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'IDLE', statusCode: 'IMPORT_IDLE' }),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByText(m.admin_system_import_status_idle())).toBeVisible();
|
|
});
|
|
|
|
it('shows no spinner when importStatus is null', async () => {
|
|
const { getByTestId } = render(ImportStatusCard, {
|
|
props: { importStatus: null, ontrigger: () => {} }
|
|
});
|
|
|
|
await expect.element(getByTestId('spinner')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('calls ontrigger when retry button is clicked in DONE state', async () => {
|
|
const ontrigger = vi.fn();
|
|
const { getByRole } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'DONE', statusCode: 'IMPORT_DONE', processed: 5 }),
|
|
ontrigger
|
|
}
|
|
});
|
|
|
|
await getByRole('button').click();
|
|
expect(ontrigger).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it('calls ontrigger when retry button is clicked in FAILED state', async () => {
|
|
const ontrigger = vi.fn();
|
|
const { getByRole } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'FAILED', statusCode: 'IMPORT_FAILED_INTERNAL' }),
|
|
ontrigger
|
|
}
|
|
});
|
|
|
|
await getByRole('button').click();
|
|
expect(ontrigger).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it('calls ontrigger when start button is clicked in IDLE state', async () => {
|
|
const ontrigger = vi.fn();
|
|
const { getByRole } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'IDLE', statusCode: 'IMPORT_IDLE' }),
|
|
ontrigger
|
|
}
|
|
});
|
|
|
|
await getByRole('button').click();
|
|
expect(ontrigger).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it('shows skipped count when DONE and skipped > 0', async () => {
|
|
const { getByTestId } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({
|
|
state: 'DONE',
|
|
statusCode: 'IMPORT_DONE',
|
|
processed: 10,
|
|
skipped: 3,
|
|
skippedFiles: [
|
|
{ filename: 'fake.pdf', reason: 'Keine gültige PDF-Signatur' },
|
|
{ filename: 'other.pdf', reason: 'Keine gültige PDF-Signatur' },
|
|
{ filename: 'tiny.pdf', reason: 'Keine gültige PDF-Signatur' }
|
|
]
|
|
}),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByTestId('skipped-count')).toHaveTextContent('3');
|
|
});
|
|
|
|
it('shows skipped filenames in collapsible list when DONE and skipped > 0', async () => {
|
|
const { getByText } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({
|
|
state: 'DONE',
|
|
statusCode: 'IMPORT_DONE',
|
|
processed: 5,
|
|
skipped: 1,
|
|
skippedFiles: [{ filename: 'fake.pdf', reason: 'Keine gültige PDF-Signatur' }]
|
|
}),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByText('fake.pdf')).toBeInTheDocument();
|
|
});
|
|
|
|
it('does not show skipped section when DONE and skipped is 0', async () => {
|
|
const { getByTestId } = render(ImportStatusCard, {
|
|
props: {
|
|
importStatus: makeStatus({ state: 'DONE', statusCode: 'IMPORT_DONE', processed: 5 }),
|
|
ontrigger: () => {}
|
|
}
|
|
});
|
|
|
|
await expect.element(getByTestId('skipped-count')).not.toBeInTheDocument();
|
|
});
|
|
});
|