Editor Tests
The Editor page (src/pages/Editor/index.jsx) is interaction-heavy, so coverage focuses on end-to-end behavior with React Testing Library.
Current coverageβ
- src/pages/Editor/Editor.test.jsx:
- renders fallback when
location.state.svgis missing - renders provided SVG content
- adds
coloredRegionon tap in color mode (one-way reveal) - switches to preview mode (disables toggling) via the
GlassSwitch
- renders fallback when
- src/pages/Editor/EditorHelmet.test.jsx: title, robots, description, and canonical meta.
High-value behaviors to keep coveredβ
- Empty state: direct navigation shows the βNo SVG data foundβ panel.
- Mode switch:
aria-labelflips and the container class toggles betweencolorModeandpreviewMode. - Shape reveal: tapping a supported primitive (
path,rect,circle,polygon,ellipse) addscoloredRegionand keeps it applied on repeat taps (no toggle-off).
Supplying SVG in testsβ
Render the page inside a router and pass state through MemoryRouter entries:
render(
<MemoryRouter initialEntries={[{ pathname: '/editor', state: { svg: '<svg><path /></svg>' } }]}>
<Editor />
</MemoryRouter>
);
This avoids mocking useLocation and matches production usage.
Pointer and wheel events (practical notes)β
document.elementFromPointcan be stubbed to return the shape you want to toggle; restore it after each test.- Pan tests should move more than the ~5px threshold to be treated as a drag.
- Wheel zoom can be asserted by reading the inline
transformon the wrapper. - Pinch is multi-pointer; prefer unit-testing math in a helper if the logic is extracted.
Common pitfallsβ
- Remember
act(...)around pointer/wheel interactions that change React state. - CSS modules hash class names; check
.classList.contains(styles.coloredRegion)rather than string literals. - Keep tests colocated under
src/pages/Editor/(page-local) for discoverability.