Repository navigation
Expand file tree
/
Copy pathlogViewRouting.test.jsx
More file actions
120 lines (114 loc) · 4.05 KB
/
Copy pathlogViewRouting.test.jsx
File metadata and controls
120 lines (114 loc) · 4.05 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import App from './App';
vi.mock('./components/Layout', () => ({
default: ({ children }) => (
<section aria-label="Classic layout">{children}</section>
),
}));
vi.mock('./components/AnimatedRoutes', () => ({
default: () => <p>Classic route</p>,
}));
vi.mock('./pages/discovery/DiscoveryPage', () => ({
default: () => <p>Shelf route</p>,
}));
vi.mock('./context/AnimationContext', () => ({
AnimationProvider: ({ children }) => children,
useAnimation: () => ({ reduceMotion: true }),
}));
vi.mock('./context/ToastContext', () => ({
ToastProvider: ({ children }) => children,
}));
vi.mock('./context/SiteConfigContext', () => ({
SiteConfigProvider: ({ children }) => children,
}));
vi.mock('./context/CloudMusicContext', () => ({
CloudMusicProvider: ({ children }) => children,
}));
vi.mock('./context/DndContext', () => ({
DndProvider: ({ children }) => children,
}));
vi.mock('./context/AchievementContext', () => ({
AchievementProvider: ({ children }) => children,
}));
vi.mock('./context/HomepageOrderContext', () => ({
HomepageOrderProvider: ({ children }) => children,
}));
let mockedDiscoveryViewMode = 'shelf';
vi.mock('./context/VisualSettingsContext', () => ({
VisualSettingsProvider: ({ children }) => children,
useVisualSettings: () => ({ discoveryViewMode: mockedDiscoveryViewMode }),
}));
vi.mock('./context/CommandPaletteContext', () => ({
CommandPaletteProvider: ({ children }) => children,
}));
vi.mock('./context/SidePanelContext', () => ({
SidePanelProvider: ({ children }) => children,
}));
vi.mock('./components/AchievementListeners', () => ({ default: () => null }));
vi.mock('./components/DigitalRain', () => ({ default: () => null }));
vi.mock('./components/BSOD', () => ({ default: () => null }));
vi.mock('./components/ScrollToTop', () => ({ default: () => null }));
vi.mock('./components/ContactModal', () => ({ default: () => null }));
vi.mock('./components/GenericModal', () => ({ default: () => null }));
vi.mock('./app/apps/CloudMusicPlayer/components/TinyCloudPlayer', () => ({
default: () => null,
}));
vi.mock('framer-motion', () => ({ MotionConfig: ({ children }) => children }));
afterEach(() => {
cleanup();
mockedDiscoveryViewMode = 'shelf';
});
describe('log view routing in App', () => {
it.each([
'/logs',
'/logs/game/example',
'/discovery',
'/discovery/game/example',
])('renders %s as the standalone shelf by default', async (path) => {
render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
expect(await screen.findByText('Shelf route')).toBeInTheDocument();
expect(
screen.queryByRole('region', { name: 'Classic layout' }),
).not.toBeInTheDocument();
});
it.each(['/logs?view=classic', '/logs/game/example?view=classic'])(
'keeps %s inside the classic site layout',
async (path) => {
render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
expect(
await screen.findByRole('region', { name: 'Classic layout' }),
).toHaveTextContent('Classic route');
expect(screen.queryByText('Shelf route')).not.toBeInTheDocument();
},
);
it('renders /logs inside the classic layout when classic viewer is permanently selected, while keeping /logs?view=shelf and /discovery on the shelf', async () => {
mockedDiscoveryViewMode = 'classic';
const { unmount } = render(
<MemoryRouter initialEntries={['/logs']}>
<App />
</MemoryRouter>,
);
expect(
await screen.findByRole('region', { name: 'Classic layout' }),
).toHaveTextContent('Classic route');
expect(screen.queryByText('Shelf route')).not.toBeInTheDocument();
unmount();
render(
<MemoryRouter initialEntries={['/logs?view=shelf']}>
<App />
</MemoryRouter>,
);
expect(await screen.findByText('Shelf route')).toBeInTheDocument();
});
});