forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleGuide.test.tsx
More file actions
55 lines (49 loc) · 2.27 KB
/
StyleGuide.test.tsx
File metadata and controls
55 lines (49 loc) · 2.27 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
import React from 'react';
import { render } from '@testing-library/react';
import { ChartThemeProvider } from '@deephaven/chart';
import { type ThemeData, ThemeProvider } from '@deephaven/components';
import { dh } from '@deephaven/jsapi-shim';
import { ApiContext } from '@deephaven/jsapi-bootstrap';
import StyleGuide from './StyleGuide';
window.HTMLElement.prototype.scroll = jest.fn();
window.HTMLElement.prototype.scrollIntoView = jest.fn();
/**
* Mock a dimension property of a ListView element.
*/
function mockListViewDimension(propName: keyof HTMLElement, value: number) {
jest
.spyOn(window.HTMLElement.prototype, propName, 'get')
.mockImplementation(function getDimension() {
const isSpectrumListView =
this instanceof HTMLElement &&
this.className.includes('_react-spectrum-ListView');
// For non ListView, just return zero which is the default value anyway.
return isSpectrumListView === true ? value : 0;
});
}
describe('<StyleGuide /> mounts', () => {
test('h1 text of StyleGuide renders', () => {
// Provide a non-null array to ThemeProvider to tell it to initialize
const customThemes: ThemeData[] = [];
// React Spectrum `useVirtualizerItem` depends on `scrollWidth` and `scrollHeight`.
// Mocking these to avoid React "Maximum update depth exceeded" errors.
// https://github.com/adobe/react-spectrum/blob/0b2a838b36ad6d86eee13abaf68b7e4d2b4ada6c/packages/%40react-aria/virtualizer/src/useVirtualizerItem.ts#L49C3-L49C60
// From preview docs: https://reactspectrum.blob.core.windows.net/reactspectrum/726a5e8f0ed50fc8d98e39c74bd6dfeb3660fbdf/docs/react-spectrum/testing.html#virtualized-components
// The virtualizer will now think it has a visible area of 1000px x 1000px and that the items within it are 40px x 40px
mockListViewDimension('clientWidth', 1000);
mockListViewDimension('clientHeight', 1000);
mockListViewDimension('scrollHeight', 40);
mockListViewDimension('scrollWidth', 40);
expect(() =>
render(
<ApiContext.Provider value={dh}>
<ThemeProvider themes={customThemes}>
<ChartThemeProvider>
<StyleGuide />
</ChartThemeProvider>
</ThemeProvider>
</ApiContext.Provider>
)
).not.toThrow();
});
});