55 lines
2.5 KiB
TypeScript
55 lines
2.5 KiB
TypeScript
/**
|
|||
|
|
* The module that ends the stranding: before it, a school page's only anchor
|
||
|
|
* pointed at the school's own website, so ~27k pages sent authority off-site
|
||
|
|
* and none of it reached the location layer.
|
||
|
|
*/
|
||
|
|
import { render, screen } from '@testing-library/react';
|
||
|
|
import { NearbyPlaces } from '@/components/school/NearbyPlaces';
|
||
|
|
|
||
|
|
const essex = { kind: 'authority', slug: 'essex', name: 'Essex', count: 480, url: '/schools/authority/essex' };
|
||
|
|
const brentwood = { kind: 'town', slug: 'brentwood', name: 'Brentwood', count: 37, url: '/schools/brentwood' };
|
||
|
|
const cm15 = { kind: 'outcode', slug: 'cm15', name: 'CM15', count: 12, url: '/schools/near/cm15' };
|
||
|
|
|
||
|
|
describe('NearbyPlaces', () => {
|
||
|
|
it('links to every place the school belongs to', () => {
|
||
|
|
render(<NearbyPlaces places={[essex, brentwood, cm15]} />);
|
||
|
|
|
||
|
|
expect(screen.getByRole('link', { name: /Brentwood/ }))
|
||
|
|
.toHaveAttribute('href', '/schools/brentwood');
|
||
|
|
expect(screen.getByRole('link', { name: /Essex/ }))
|
||
|
|
.toHaveAttribute('href', '/schools/authority/essex');
|
||
|
|
expect(screen.getByRole('link', { name: /CM15/ }))
|
||
|
|
.toHaveAttribute('href', '/schools/near/cm15');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('says how many schools each link leads to', () => {
|
||
|
|
// An anchor that states its destination's size is worth more to a reader
|
||
|
|
// and to a crawler than "see more".
|
||
|
|
render(<NearbyPlaces places={[brentwood]} />);
|
||
|
|
expect(screen.getByRole('link', { name: /37 schools in Brentwood/ }))
|
||
|
|
.toBeInTheDocument();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('renders nothing at all when the school has no published places', () => {
|
||
|
|
// Not an empty heading. A school whose town and authority both fall below
|
||
|
|
// the threshold has nowhere to point, and the page should look as it did
|
||
|
|
// before the module existed.
|
||
|
|
const { container } = render(<NearbyPlaces places={[]} />);
|
||
|
|
expect(container).toBeEmptyDOMElement();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('puts the narrowest place first, which is the most useful link', () => {
|
||
|
|
// The API orders widest-first for the breadcrumb; a reader on a school
|
||
|
|
// page wants its town before its county.
|
||
|
|
render(<NearbyPlaces places={[essex, brentwood, cm15]} />);
|
||
|
|
const hrefs = screen.getAllByRole('link').map((a) => a.getAttribute('href'));
|
||
|
|
expect(hrefs.indexOf('/schools/brentwood'))
|
||
|
|
.toBeLessThan(hrefs.indexOf('/schools/authority/essex'));
|
||
|
|
});
|
||
|
|
|
||
|
|
it('handles a singular count without saying "1 schools"', () => {
|
||
|
|
render(<NearbyPlaces places={[{ ...brentwood, count: 1 }]} />);
|
||
|
|
expect(screen.getByRole('link', { name: /1 school in Brentwood/ }))
|
||
|
|
.toBeInTheDocument();
|
||
|
|
});
|
||
|
|
});
|