import { test, expect } from 'vitest'; import { render, screen } from '@testing-library/react'; import BackLink from './BackLink'; const LINK_HREF = '#home'; const DEFAULT_TEXT = 'Back'; test('back link renders correctly', () => { render( ); const backLink = screen.getByRole('link'); expect(backLink).toHaveClass('ds_back-link'); expect(backLink).toHaveAttribute('href', LINK_HREF); expect(backLink.tagName).toEqual('A'); expect(backLink.textContent).toEqual(DEFAULT_TEXT); }); test('renders back link with custom element', () => { render( ( )} /> ); const backLink = screen.getByRole('link'); expect(backLink.tagName).toEqual('SPAN'); expect(backLink.textContent).toEqual(DEFAULT_TEXT); }); test('renders back link as span if no href supplied (invalid use)', () => { render( ); const backLink = screen.getByTestId('no-href'); expect(backLink.tagName).toEqual('SPAN'); expect(backLink.textContent).toEqual(DEFAULT_TEXT); }); test('back link with custom link text', () => { const LINK_TEXT = 'my link text'; render( {LINK_TEXT} ); const backLink = screen.getByRole('link'); expect(backLink).toHaveClass('ds_back-link'); expect(backLink.textContent).toEqual(LINK_TEXT); }); test('passing additional props', () => { render( ); const backLink = screen.getByRole('link'); expect(backLink?.dataset.test).toEqual('foo'); }); test('passing additional CSS classes', () => { render( ); const backLink = screen.getByRole('link'); expect(backLink).toHaveClass('foo'); });