-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathuse-dashboard-extensions.spec.tsx
More file actions
64 lines (51 loc) · 1.89 KB
/
Copy pathuse-dashboard-extensions.spec.tsx
File metadata and controls
64 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { i18n } from '@lingui/core';
import { act } from 'react';
import { createRoot } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { defaultLocale } from '../../providers/i18n-provider.js';
import { useDashboardExtensions } from './use-dashboard-extensions.js';
const runDashboardExtensions = vi.hoisted(() => vi.fn());
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
vi.mock('virtual:dashboard-extensions', () => ({
runDashboardExtensions,
}));
vi.mock('./define-dashboard-extension.js', () => ({
onExtensionSourceChange: vi.fn(),
}));
describe('useDashboardExtensions', () => {
let container: HTMLDivElement;
let root: ReturnType<typeof createRoot>;
beforeEach(() => {
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);
});
afterEach(async () => {
await act(async () => {
root.unmount();
});
container.remove();
vi.clearAllMocks();
});
it('can evaluate translations before the full locale catalog has loaded', async () => {
let extensionError: unknown;
runDashboardExtensions.mockImplementation(async () => {
try {
const extensionMessageId = ['Extension', 'label'].join(' ');
i18n._(extensionMessageId);
} catch (error) {
extensionError = error;
}
});
function DashboardBootstrap() {
useDashboardExtensions();
return null;
}
await act(async () => {
root.render(<DashboardBootstrap />);
});
expect(runDashboardExtensions).toHaveBeenCalledOnce();
expect(i18n.locale).toBe(defaultLocale);
expect(extensionError).toBeUndefined();
});
});