38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/**
|
|||
|
|
* The trail has to be written by something, and it has to be written on every
|
||
|
|
* route — not only the ones that happen to track an event.
|
||
|
|
*/
|
||
|
|
import { render } from '@testing-library/react';
|
||
|
|
|
||
|
|
const recordVisitedPath = jest.fn();
|
||
|
|
let pathname = '/schools/brentwood';
|
||
|
|
|
||
|
|
jest.mock('next/navigation', () => ({ usePathname: () => pathname }));
|
||
|
|
jest.mock('@/lib/analytics', () => ({
|
||
|
|
recordVisitedPath: (p: string) => recordVisitedPath(p),
|
||
|
|
}));
|
||
|
|
|
||
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||
|
|
const { RouteTrail } = require('@/components/RouteTrail');
|
||
|
|
|
||
|
|
describe('RouteTrail', () => {
|
||
|
|
beforeEach(() => recordVisitedPath.mockClear());
|
||
|
|
|
||
|
|
it('records the page it is mounted on', () => {
|
||
|
|
render(<RouteTrail />);
|
||
|
|
expect(recordVisitedPath).toHaveBeenCalledWith('/schools/brentwood');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('records each new route as the user moves through the app', () => {
|
||
|
|
const { rerender } = render(<RouteTrail />);
|
||
|
|
pathname = '/school/115429-brentwood-school';
|
||
|
|
rerender(<RouteTrail />);
|
||
|
|
expect(recordVisitedPath).toHaveBeenLastCalledWith(
|
||
|
|
'/school/115429-brentwood-school');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('renders nothing, so it can sit anywhere in the layout', () => {
|
||
|
|
const { container } = render(<RouteTrail />);
|
||
|
|
expect(container).toBeEmptyDOMElement();
|
||
|
|
});
|
||
|
|
});
|