|
1 | 1 | import { render, screen } from '@testing-library/react'; |
2 | 2 | import { NHSNotifyFooter } from '@molecules/Footer/Footer'; |
3 | | -import content from '@content/content'; |
4 | 3 |
|
5 | | -const footerContent = content.components.footer; |
| 4 | +type FooterLinkSpec = { |
| 5 | + testId: string; |
| 6 | + text: string; |
| 7 | + href: string; |
| 8 | +}; |
| 9 | + |
| 10 | +const expectedFooterLinks: Array<Array<string | FooterLinkSpec>> = [ |
| 11 | + [ |
| 12 | + 'acceptable use policy', |
| 13 | + { |
| 14 | + testId: 'acceptable-use-policy-statement-link', |
| 15 | + text: 'Acceptable use policy', |
| 16 | + href: 'https://digital.nhs.uk/services/nhs-notify/acceptable-use-policy', |
| 17 | + }, |
| 18 | + ], |
| 19 | + [ |
| 20 | + 'accessibility statement', |
| 21 | + { |
| 22 | + testId: 'accessibility-statement-link', |
| 23 | + text: 'Accessibility statement', |
| 24 | + href: '/accessibility', |
| 25 | + }, |
| 26 | + ], |
| 27 | + [ |
| 28 | + 'cookies statement', |
| 29 | + { |
| 30 | + testId: 'cookies-statement-link', |
| 31 | + text: 'Cookies', |
| 32 | + href: '/cookies', |
| 33 | + }, |
| 34 | + ], |
| 35 | + [ |
| 36 | + 'privacy statement', |
| 37 | + { |
| 38 | + testId: 'privacy-statement-link', |
| 39 | + text: 'Privacy', |
| 40 | + href: 'https://digital.nhs.uk/services/nhs-notify/transparency-notice', |
| 41 | + }, |
| 42 | + ], |
| 43 | + [ |
| 44 | + 'terms and conditions statement', |
| 45 | + { |
| 46 | + testId: 'terms-and-conditions-statement-link', |
| 47 | + text: 'Terms and conditions', |
| 48 | + href: 'https://digital.nhs.uk/services/nhs-notify/terms-and-conditions', |
| 49 | + }, |
| 50 | + ], |
| 51 | +]; |
6 | 52 |
|
7 | 53 | describe('Footer component', () => { |
| 54 | + test.each(expectedFooterLinks)('Check %s footer link', (_, spec) => { |
| 55 | + const linkSpec = spec as FooterLinkSpec; |
| 56 | + |
| 57 | + render(<NHSNotifyFooter />); |
| 58 | + |
| 59 | + const link = screen.getByTestId(linkSpec.testId); |
| 60 | + expect(link).toBeInTheDocument(); |
| 61 | + expect(link.getAttribute('href')).toBe(linkSpec.href); |
| 62 | + expect(link.textContent).toBe(linkSpec.text); |
| 63 | + }); |
| 64 | + |
8 | 65 | it('renders component correctly', () => { |
9 | 66 | render(<NHSNotifyFooter />); |
10 | 67 |
|
11 | 68 | expect(screen.getByTestId('page-footer')).toBeInTheDocument(); |
12 | 69 | expect(screen.getByTestId('support-links')).toBeInTheDocument(); |
13 | 70 |
|
14 | | - expect( |
15 | | - screen.getByTestId('accessibility-statement-link') |
16 | | - ).toBeInTheDocument(); |
17 | | - expect(screen.getByTestId('accessibility-statement-link')).toHaveAttribute( |
18 | | - 'href', |
19 | | - `${footerContent.links.accessibilityStatement.url}` |
20 | | - ); |
21 | | - |
22 | | - expect(screen.getByTestId('contact-us-link')).toBeInTheDocument(); |
23 | | - expect(screen.getByTestId('contact-us-link')).toHaveAttribute('href', '#'); |
24 | | - |
25 | | - expect(screen.getByTestId('cookies-link')).toBeInTheDocument(); |
26 | | - expect(screen.getByTestId('cookies-link')).toHaveAttribute('href', '#'); |
27 | | - |
28 | | - expect(screen.getByTestId('privacy-policy-link')).toBeInTheDocument(); |
29 | | - expect(screen.getByTestId('privacy-policy-link')).toHaveAttribute( |
30 | | - 'href', |
31 | | - '#' |
32 | | - ); |
| 71 | + const footerListItems = screen |
| 72 | + .getByTestId('footer-links') |
| 73 | + .querySelectorAll('li'); |
| 74 | + const footerLinksOrdered = [...footerListItems] |
| 75 | + .map((footerListItem) => footerListItem.querySelectorAll('a').item(0)) |
| 76 | + .filter((link) => !!link) |
| 77 | + .map((footerLink) => footerLink.dataset.testid); |
33 | 78 |
|
34 | | - expect(screen.getByTestId('terms-and-conditions-link')).toBeInTheDocument(); |
35 | | - expect(screen.getByTestId('terms-and-conditions-link')).toHaveAttribute( |
36 | | - 'href', |
37 | | - '#' |
| 79 | + expect(footerLinksOrdered).toEqual( |
| 80 | + expectedFooterLinks.map( |
| 81 | + (linkSpec) => (linkSpec[1] as FooterLinkSpec).testId |
| 82 | + ) |
38 | 83 | ); |
39 | 84 | expect( |
40 | 85 | screen.getByTestId('nhs-england-copyright-text') |
|
0 commit comments