DocumentThumbnail: thumbnailUrl→img branch, no-thumbnail→placeholder icon branch, sm vs lg size container class, lazy/async loading attrs. UnsavedWarningBanner: warning text, discard button, callback wiring. PersonsStatsBar: count rendering, singular/plural label switching for both persons and documents (4 branches), zero-count plural fallback. 14 tests across three small primitive files. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { describe, it, expect, afterEach } from 'vitest';
|
|
import { cleanup, render } from 'vitest-browser-svelte';
|
|
import DocumentThumbnail from './DocumentThumbnail.svelte';
|
|
|
|
afterEach(cleanup);
|
|
|
|
describe('DocumentThumbnail', () => {
|
|
it('renders the supplied thumbnail image when thumbnailUrl is set', async () => {
|
|
render(DocumentThumbnail, {
|
|
props: {
|
|
doc: { id: 'd1', thumbnailUrl: '/api/d1/thumb', contentType: 'application/pdf' }
|
|
}
|
|
});
|
|
|
|
const img = document.querySelector('img') as HTMLImageElement;
|
|
expect(img).not.toBeNull();
|
|
expect(img.src).toContain('/api/d1/thumb');
|
|
});
|
|
|
|
it('renders the placeholder icon when thumbnailUrl is missing', async () => {
|
|
render(DocumentThumbnail, {
|
|
props: { doc: { id: 'd1', thumbnailUrl: null, contentType: 'application/pdf' } }
|
|
});
|
|
|
|
const svg = document.querySelector('svg');
|
|
expect(svg).not.toBeNull();
|
|
});
|
|
|
|
it('uses the small container size by default', async () => {
|
|
render(DocumentThumbnail, {
|
|
props: { doc: { id: 'd1', thumbnailUrl: null, contentType: 'application/pdf' } }
|
|
});
|
|
|
|
const container = document.querySelector('.h-\\[84px\\]');
|
|
expect(container).not.toBeNull();
|
|
});
|
|
|
|
it('uses the large container size when size="lg"', async () => {
|
|
render(DocumentThumbnail, {
|
|
props: {
|
|
doc: { id: 'd1', thumbnailUrl: null, contentType: 'application/pdf' },
|
|
size: 'lg'
|
|
}
|
|
});
|
|
|
|
const container = document.querySelector('.h-\\[168px\\]');
|
|
expect(container).not.toBeNull();
|
|
});
|
|
|
|
it('uses lazy loading attributes on the thumbnail image', async () => {
|
|
render(DocumentThumbnail, {
|
|
props: {
|
|
doc: { id: 'd1', thumbnailUrl: '/api/d1/thumb', contentType: 'application/pdf' }
|
|
}
|
|
});
|
|
|
|
const img = document.querySelector('img') as HTMLImageElement;
|
|
expect(img.loading).toBe('lazy');
|
|
expect(img.decoding).toBe('async');
|
|
});
|
|
});
|