Skip to content

Commit 582f6f2

Browse files
committed
Add component tests for document title, file browser, and layout switcher; update Vitest config to include component tests
1 parent 055911b commit 582f6f2

4 files changed

Lines changed: 712 additions & 1 deletion

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// @vitest-environment jsdom
2+
import { beforeEach, describe, expect, it, vi } from 'vitest';
3+
4+
const { activePartGet } = vi.hoisted(() => ({
5+
activePartGet: vi.fn(),
6+
}));
7+
8+
vi.mock('../../src/core/appstate', () => ({
9+
activePartSignal: { get: () => activePartGet() },
10+
}));
11+
12+
vi.mock('../../src/core/apploader', () => ({
13+
appLoaderService: { getCurrentApp: vi.fn(() => null) },
14+
}));
15+
16+
vi.mock('../../src/core/signals', () => ({
17+
watchSignal: vi.fn(),
18+
}));
19+
20+
vi.mock('../../src/core/i18n', () => ({
21+
i18n: vi.fn(async () => ({ NO_PART: 'No part' })),
22+
}));
23+
24+
describe('document-title (component helpers)', () => {
25+
beforeEach(() => {
26+
activePartGet.mockReset();
27+
});
28+
29+
it('getActivePartDisplayName returns NO_PART when nothing is focused', async () => {
30+
activePartGet.mockReturnValue(undefined);
31+
const { getActivePartDisplayName } = await import('../../src/components/document-title');
32+
expect(getActivePartDisplayName()).toBe('No part');
33+
});
34+
35+
it('prefers tab contribution label when present', async () => {
36+
activePartGet.mockReturnValue({
37+
tabContribution: { label: 'Editor' },
38+
getAttribute: () => null,
39+
});
40+
const { getActivePartDisplayName } = await import('../../src/components/document-title');
41+
expect(getActivePartDisplayName()).toBe('Editor');
42+
});
43+
44+
it('falls back to element id when label is missing', async () => {
45+
activePartGet.mockReturnValue({
46+
tabContribution: {},
47+
getAttribute: (name: string) => (name === 'id' ? 'part-1' : null),
48+
});
49+
const { getActivePartDisplayName } = await import('../../src/components/document-title');
50+
expect(getActivePartDisplayName()).toBe('part-1');
51+
});
52+
});

0 commit comments

Comments
 (0)