feat(admin/system): extract ImportStatusCard — spinner, text-base count, statusCode i18n
Extracts the mass-import block from +page.svelte into ImportStatusCard.svelte. Changes per the three UX fixes from issue #533: - RUNNING: animated spinner (animate-spin) + processed count at text-base; auto-poll at 2 s was already in place - DONE: processed count at text-base, label at text-xs uppercase tracking-widest - FAILED: maps statusCode (IMPORT_FAILED_NO_SPREADSHEET / IMPORT_FAILED_INTERNAL) to Paraglide messages — no raw German backend string rendered Adds vitest-browser tests covering spinner visibility, count display, and per-statusCode FAILED message selection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { describe, it } from 'vitest';
|
||||
import { render } from 'vitest-browser-svelte';
|
||||
import { expect } from '@vitest/browser/context';
|
||||
import ImportStatusCard from './ImportStatusCard.svelte';
|
||||
|
||||
type ImportStatus = {
|
||||
state: 'IDLE' | 'RUNNING' | 'DONE' | 'FAILED';
|
||||
statusCode: string;
|
||||
message: string;
|
||||
processed: number;
|
||||
startedAt: string | null;
|
||||
};
|
||||
|
||||
const makeStatus = (overrides: Partial<ImportStatus> = {}): ImportStatus => ({
|
||||
state: 'IDLE',
|
||||
statusCode: 'IMPORT_IDLE',
|
||||
message: '',
|
||||
processed: 0,
|
||||
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')).toBeVisible();
|
||||
});
|
||||
|
||||
it('shows processed count at text-base while RUNNING', async () => {
|
||||
const { getByText } = render(ImportStatusCard, {
|
||||
props: {
|
||||
importStatus: makeStatus({ state: 'RUNNING', statusCode: 'IMPORT_RUNNING', processed: 7 }),
|
||||
ontrigger: () => {}
|
||||
}
|
||||
});
|
||||
|
||||
await expect.element(getByText('7')).toBeVisible();
|
||||
});
|
||||
|
||||
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',
|
||||
message: 'Keine Tabellendatei...'
|
||||
}),
|
||||
ontrigger: () => {}
|
||||
}
|
||||
});
|
||||
|
||||
await expect.element(getByText('No spreadsheet file found.')).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user