Some checks failed
CI / Unit & Component Tests (pull_request) Successful in 3m3s
CI / OCR Service Tests (pull_request) Successful in 20s
CI / Backend Unit Tests (pull_request) Failing after 3m2s
CI / fail2ban Regex (pull_request) Successful in 39s
CI / Semgrep Security Scan (pull_request) Successful in 19s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m1s
- remove duplicate List import in AdminControllerTest - derive skipped() from skippedFiles.size() — drop redundant int field - use machine codes for SkippedFile.reason (INVALID_PDF_SIGNATURE, FILE_READ_ERROR) - map reason codes to i18n strings in ImportStatusCard (de/en/es) - replace raw amber Tailwind classes with warning semantic token - fix <summary> accessibility: replace list-none with rotating chevron SVG - replace <p> with <span> inside <summary> (phrasing content rule) - extract setupOneValidOneFakeImport() helper — remove 3x copy-paste - add lenient mock to short-file test for defensive coverage - add IOException path test for isPdfMagicBytes 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: 'INVALID_PDF_SIGNATURE' },
|
|
{ filename: 'other.pdf', reason: 'INVALID_PDF_SIGNATURE' },
|
|
{ filename: 'tiny.pdf', reason: 'INVALID_PDF_SIGNATURE' }
|
|
]
|
|
}),
|
|
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: 'INVALID_PDF_SIGNATURE' }]
|
|
}),
|
|
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();
|
|
});
|
|
});
|