import { test, expect } from 'vitest'; import { render, screen, within } from '@testing-library/react'; import SiteFooter from './SiteFooter'; const LINK_HREF = '#cookies'; const LINK_TEXT = 'Cookies'; test('site footer renders correctly', () => { render( ); const siteFooter = screen.getByTestId('sitefooter'); const siteFooterWrapper = siteFooter.children[0]; const siteFooterContent = siteFooterWrapper.children[0]; const siteFooterLinksContainer = screen.getByTestId('sitefooterlinks'); const siteFooterLicenseContainer = screen.getByTestId('sitefooterlicense'); const siteFooterOrgContainer = screen.getByTestId('sitefooterorg'); expect(siteFooter).toHaveClass('ds_site-footer'); expect(siteFooter.tagName).toEqual('FOOTER'); expect(siteFooterWrapper).toHaveClass('ds_wrapper'); expect(siteFooterWrapper.tagName).toEqual('DIV'); expect(siteFooterContent).toHaveClass('ds_site-footer__content'); expect(siteFooterContent.tagName).toEqual('DIV'); expect(siteFooterLinksContainer).toHaveClass('ds_site-footer__site-items'); expect(siteFooterLinksContainer.tagName).toEqual('UL'); expect(siteFooterLicenseContainer).toHaveClass('ds_site-footer__copyright'); expect(siteFooterLicenseContainer.tagName).toEqual('DIV'); expect(siteFooterOrgContainer).toHaveClass('ds_site-footer__org'); expect(siteFooterOrgContainer.tagName).toEqual('DIV'); }); test('site footer links render correctly', () => { render( {LINK_TEXT} ); const listItem = screen.getByRole('listitem'); const link = within(listItem).getByRole('link'); expect(listItem).toHaveClass('ds_site-items__item'); expect(link).toHaveAttribute('href', LINK_HREF); expect(link.textContent).toEqual(LINK_TEXT); }); test('site footer links with custom element render correctly', () => { render( ( )}> {LINK_TEXT} ); const listItem = screen.getByRole('listitem'); const link = within(listItem).getByRole('link'); expect(listItem).toHaveClass('ds_site-items__item'); expect(link).toHaveAttribute('href', LINK_HREF); expect(link.textContent).toEqual(LINK_TEXT); expect(link.tagName).toEqual('SPAN'); }); test('site footer links with no href render correctly', () => { render( {LINK_TEXT} ); const listItem = screen.getByRole('listitem'); const link = within(listItem).queryByRole('link'); expect(listItem).toHaveClass('ds_site-items__item'); expect(listItem.textContent).toEqual(LINK_TEXT); expect(link).not.toBeInTheDocument(); }); test('site footer org renders correctly', () => { const CHILDREN = 'Foo'; render( {CHILDREN} ); const siteFooterOrgContainer = screen.getByTestId('sitefooterorg'); const siteFooterOrgLink = within(siteFooterOrgContainer).getByRole('link'); expect(siteFooterOrgContainer).toHaveClass('ds_site-footer__org'); expect(siteFooterOrgContainer.tagName).toEqual('DIV'); expect(siteFooterOrgLink).toHaveClass('ds_site-footer__org-link'); expect(siteFooterOrgLink.tagName).toEqual('A'); }); test('site footer org with image renders correctly', () => { const CHILDREN = Foo render( {CHILDREN} ); const siteFooterOrgContainer = screen.getByTestId('sitefooterorg'); const siteFooterOrgImage = within(siteFooterOrgContainer).getByRole('img'); expect(siteFooterOrgImage).toHaveClass('ds_site-footer__org-logo'); }); test('site footer license renders correctly', () => { const CHILDREN = 'Hello'; render( {CHILDREN} ); const siteFooterLicenseContainer = screen.getByTestId('sitefooterlicense'); expect(siteFooterLicenseContainer.innerHTML).toEqual(CHILDREN); }); test('passing additional props', () => { render( ); const siteFooter = screen.getByTestId('sitefooter'); expect(siteFooter?.dataset.test).toEqual('foo'); }); test('passing additional CSS classes', () => { render( ); const siteFooter = screen.getByTestId('sitefooter'); expect(siteFooter).toHaveClass('foo'); });