|
2 | 2 | * @vitest-environment jsdom |
3 | 3 | */ |
4 | 4 |
|
5 | | -import { describe, it, expect } from 'vitest'; |
6 | | -import { render } from '@testing-library/react'; |
| 5 | +import { describe, it, expect, afterEach } from 'vitest'; |
| 6 | +import { render, screen, waitFor } from '@testing-library/react'; |
7 | 7 | import { StoreProvider } from '../../state/StoreContext'; |
8 | 8 | import { App } from '../../App'; |
| 9 | +import { overrideFlags, restoreFlags } from '../../featureFlags'; |
| 10 | +import { makeTestWorkspace } from '../helpers/test-fixtures'; |
9 | 11 |
|
10 | 12 | /** |
11 | 13 | * Integration tests for ARIA landmarks (P1.1.4) |
@@ -144,4 +146,90 @@ describe('ARIA Landmarks', () => { |
144 | 146 | }); |
145 | 147 | }); |
146 | 148 | }); |
| 149 | + |
| 150 | + describe('Per-route landmarks (new workspace UI)', () => { |
| 151 | + const renderRoute = (hash) => { |
| 152 | + window.location.hash = hash; |
| 153 | + return render( |
| 154 | + <StoreProvider initialState={{ workspace: makeTestWorkspace() }}> |
| 155 | + <App /> |
| 156 | + </StoreProvider> |
| 157 | + ); |
| 158 | + }; |
| 159 | + |
| 160 | + afterEach(() => { |
| 161 | + restoreFlags(); |
| 162 | + window.location.hash = ''; |
| 163 | + }); |
| 164 | + |
| 165 | + // makeTestWorkspace seeds animal "remy" + day "remy_20230622". |
| 166 | + it('Home: one main + one #main-content, a navigation landmark, and a Workspace link', () => { |
| 167 | + overrideFlags({ animalWorkspace: true }); |
| 168 | + const { container } = renderRoute('#/home'); |
| 169 | + |
| 170 | + expect(container.querySelectorAll('[role="main"]')).toHaveLength(1); |
| 171 | + expect(container.querySelectorAll('#main-content')).toHaveLength(1); |
| 172 | + expect(container.querySelector('[role="navigation"]')).toBeTruthy(); |
| 173 | + // Escape to the workspace exists via the primary nav. |
| 174 | + expect(screen.getByRole('link', { name: /^workspace$/i })).toBeInTheDocument(); |
| 175 | + }); |
| 176 | + |
| 177 | + it('Workspace: one main + one #main-content, a navigation landmark, escape to Home', () => { |
| 178 | + overrideFlags({ animalWorkspace: true }); |
| 179 | + const { container } = renderRoute('#/workspace'); |
| 180 | + |
| 181 | + expect(container.querySelectorAll('[role="main"]')).toHaveLength(1); |
| 182 | + expect(container.querySelectorAll('#main-content')).toHaveLength(1); |
| 183 | + expect(container.querySelector('[role="navigation"]')).toBeTruthy(); |
| 184 | + expect(screen.getByRole('link', { name: /^home$/i })).toBeInTheDocument(); |
| 185 | + }); |
| 186 | + |
| 187 | + it('DayEditor: one main + one #main-content + one banner/contentinfo; back-to-workspace link', async () => { |
| 188 | + overrideFlags({ animalWorkspace: true, newDayEditor: true }); |
| 189 | + const { container } = renderRoute('#/day/remy_20230622'); |
| 190 | + |
| 191 | + // useDayIdFromUrl resolves the day id in an effect, so wait for the real stepper. |
| 192 | + const back = await screen.findByRole('link', { name: /back to workspace/i }); |
| 193 | + expect(back).toBeInTheDocument(); |
| 194 | + expect(container.querySelectorAll('[role="main"]')).toHaveLength(1); |
| 195 | + expect(container.querySelectorAll('#main-content')).toHaveLength(1); |
| 196 | + // The stepper header/footer are plain divs, so AppLayout owns the only banner |
| 197 | + // and contentinfo landmarks (no duplicates). |
| 198 | + expect(container.querySelectorAll('[role="banner"], header')).toHaveLength(1); |
| 199 | + expect(container.querySelectorAll('[role="contentinfo"], footer')).toHaveLength(1); |
| 200 | + }); |
| 201 | + |
| 202 | + it('AnimalEditor: exactly one main + one #main-content (duplicate removed); back-to-workspace link', async () => { |
| 203 | + overrideFlags({ animalWorkspace: true }); |
| 204 | + const { container } = renderRoute('#/animal/remy/editor'); |
| 205 | + |
| 206 | + // AnimalEditor is lazy-loaded behind Suspense. |
| 207 | + await waitFor(() => { |
| 208 | + expect(container.querySelectorAll('[role="main"]')).toHaveLength(1); |
| 209 | + }); |
| 210 | + expect(container.querySelectorAll('#main-content')).toHaveLength(1); |
| 211 | + // Stepper header/footer are plain divs → AppLayout owns the only banner/contentinfo. |
| 212 | + expect(container.querySelectorAll('[role="banner"], header')).toHaveLength(1); |
| 213 | + expect(container.querySelectorAll('[role="contentinfo"], footer')).toHaveLength(1); |
| 214 | + expect(screen.getByRole('link', { name: /back to workspace/i })).toBeInTheDocument(); |
| 215 | + }); |
| 216 | + |
| 217 | + it('keeps the default route (#/) on the legacy form even with flags enabled', () => { |
| 218 | + overrideFlags({ animalWorkspace: true, newDayEditor: true }); |
| 219 | + window.location.hash = '#/'; |
| 220 | + // No seeded workspace here: the legacy form reads the flat formData model, so |
| 221 | + // seeding only { workspace } would leave formData without its fields. |
| 222 | + const { container } = render( |
| 223 | + <StoreProvider> |
| 224 | + <App /> |
| 225 | + </StoreProvider> |
| 226 | + ); |
| 227 | + |
| 228 | + // Default stays legacy this phase (cutover flips the default in a later phase). |
| 229 | + expect(container.querySelector('form')).toBeTruthy(); |
| 230 | + // Legacy supplies a single main; the primary nav is not rendered on legacy. |
| 231 | + expect(container.querySelectorAll('[role="main"]')).toHaveLength(1); |
| 232 | + expect(screen.queryByRole('navigation', { name: /primary/i })).not.toBeInTheDocument(); |
| 233 | + }); |
| 234 | + }); |
147 | 235 | }); |
0 commit comments