forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-124-Lilly-Protocol-lily-frontend.ts
More file actions
39 lines (34 loc) · 1.22 KB
/
Copy pathgithub-124-Lilly-Protocol-lily-frontend.ts
File metadata and controls
39 lines (34 loc) · 1.22 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
// src/components/SiteHeader/SiteHeader.test.tsx
import React from 'react';
import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import SiteHeader from './SiteHeader';
import { routes } from '../routes'; // Adjust path as needed
describe('SiteHeader', () => {
it('should have links matching all registered routes', () => {
// Collect all route paths from the registry
const routePaths = new Set<string>();
const collectPaths = (route: any) => {
if (route.path) routePaths.add(route.path);
if (route.children) route.children.forEach(collectPaths);
};
routes.forEach(collectPaths);
// Render SiteHeader within router
render(
<MemoryRouter>
<SiteHeader />
</MemoryRouter>
);
// Get all link elements
const links = screen.getAllByRole('link');
const linkPaths = links.map(link => link.getAttribute('href'));
// Assert each route path has a corresponding link
routePaths.forEach(path => {
expect(linkPaths).toContain(path);
});
// Optional: Assert no extra links exist (if strictly required)
// linkPaths.forEach(path => {
// expect(routePaths).toContain(path);
// });
});
});