@wise/components-theming 0.0.0-experimental-a1be51d → 0.0.0-experimental-038e5bf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ThemeProvider.spec.tsx +50 -2
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
2
|
|
|
3
|
-
import { ThemeProvider } from './ThemeProvider';
|
|
3
|
+
import { ThemeProvider, ThemeProviderProps } from './ThemeProvider';
|
|
4
|
+
import { useState } from 'react';
|
|
4
5
|
|
|
5
6
|
describe('ThemeProvider', () => {
|
|
6
7
|
it('can nest theme providers', () => {
|
|
@@ -24,6 +25,53 @@ describe('ThemeProvider', () => {
|
|
|
24
25
|
expect(screen.getAllByText('light')[1].parentElement).toHaveClass('np-theme-light');
|
|
25
26
|
});
|
|
26
27
|
|
|
28
|
+
it('updates theming setting based of props updates', async () => {
|
|
29
|
+
const TestComponent = () => {
|
|
30
|
+
const [theme, setTheme] = useState<ThemeProviderProps['theme']>('personal');
|
|
31
|
+
const [screenMode, setScreenMode] = useState<ThemeProviderProps['screenMode']>('light');
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
<button type="button" onClick={() => setTheme('business')}>
|
|
36
|
+
Change to business
|
|
37
|
+
</button>
|
|
38
|
+
<button type="button" onClick={() => setScreenMode('dark')}>
|
|
39
|
+
Change to dark
|
|
40
|
+
</button>
|
|
41
|
+
<ThemeProvider theme={theme} screenMode={screenMode}>
|
|
42
|
+
<div>content</div>
|
|
43
|
+
</ThemeProvider>
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
render(<TestComponent />);
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
51
|
+
expect(screen.getByText('content').parentElement).toHaveClass('np-theme-personal');
|
|
52
|
+
|
|
53
|
+
// Change to business theme
|
|
54
|
+
screen.getByText('Change to business').click();
|
|
55
|
+
await waitFor(() => {
|
|
56
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
57
|
+
expect(screen.getByText('content').parentElement).toHaveClass(
|
|
58
|
+
'np-theme-personal',
|
|
59
|
+
'np-theme-business',
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Change to dark mode
|
|
64
|
+
screen.getByText('Change to dark').click();
|
|
65
|
+
await waitFor(() => {
|
|
66
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
67
|
+
expect(screen.getByText('content').parentElement).toHaveClass(
|
|
68
|
+
'np-theme-personal',
|
|
69
|
+
'np-theme-business',
|
|
70
|
+
'np-theme-business--dark',
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
27
75
|
it('sets platform themes', () => {
|
|
28
76
|
render(
|
|
29
77
|
<ThemeProvider theme="personal">
|