-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathApp.test.tsx
More file actions
95 lines (81 loc) · 2.61 KB
/
App.test.tsx
File metadata and controls
95 lines (81 loc) · 2.61 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { Provider } from 'react-redux';
import { createMockStore } from '@deephaven/redux';
import { TestUtils } from '@deephaven/test-utils';
import { ApiContext } from '@deephaven/jsapi-bootstrap';
import type { dh as DhType } from '@deephaven/jsapi-types';
import App from './App';
// Mock the modules that App depends on
jest.mock('@deephaven/app-utils', () => ({
AppDashboards: () => <div>AppDashboards</div>,
GrpcLayoutStorage: jest.fn(),
LocalWorkspaceStorage: jest.fn(() => ({
load: jest.fn().mockResolvedValue({
data: { settings: {} },
}),
})),
useConnection: jest.fn(() => ({
getObject: jest.fn(),
getStorageService: jest.fn(),
})),
useServerConfig: jest.fn(() => ({})),
useUser: jest.fn(() => ({ name: 'test-user' })),
}));
jest.mock('@deephaven/dashboard', () => ({
getAllDashboardsData: jest.fn(() => ({})),
setDashboardPluginData: jest.fn(),
emitPanelOpen: jest.fn(),
useCreateDashboardListener: jest.fn(),
}));
jest.mock('@deephaven/plugin', () => ({
useDashboardPlugins: jest.fn(() => []),
}));
jest.mock('@deephaven/jsapi-bootstrap', () => ({
...jest.requireActual('@deephaven/jsapi-bootstrap'),
getVariableDescriptor: jest.fn(),
useApi: jest.fn(() => ({})),
useClient: jest.fn(() => ({
getStorageService: jest.fn(() => ({})),
})),
}));
jest.mock('@deephaven/jsapi-utils', () => ({
fetchVariableDefinition: jest.fn(),
}));
describe('App', () => {
const mockApi = TestUtils.createMockProxy<typeof DhType>();
let store: ReturnType<typeof createMockStore>;
beforeEach(() => {
// Create a minimal Redux store
store = createMockStore();
// Reset document.title before each test
document.title = 'Deephaven Embedded Widget';
// Mock window.location.search
window.history.pushState({}, '', '/?name=testWidget');
});
it('should update document title with widget name from URL parameter', async () => {
render(
<Provider store={store}>
<ApiContext.Provider value={mockApi}>
<App />
</ApiContext.Provider>
</Provider>
);
await waitFor(() => {
expect(document.title).toBe('testWidget - Deephaven');
});
});
it('should not update document title when name parameter is missing', async () => {
window.history.pushState({}, '', '/');
render(
<Provider store={store}>
<ApiContext.Provider value={mockApi}>
<App />
</ApiContext.Provider>
</Provider>
);
await waitFor(() => {
expect(document.title).toBe('Deephaven Embedded Widget');
});
});
});