Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoskolodny committed Nov 11, 2024
1 parent 7af7971 commit 7862897
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/__tests__/header-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react';
import {Header} from '../header';
import {makeTheme} from './test-utils';
import {render, screen} from '@testing-library/react';
import ThemeContextProvider from '../theme-context-provider';

const pretitleFirst = 'HeadlinePretitleTitleDescription';
const titleFirst = 'HeadlineTitlePretitleDescription';

test.each`
pretitleAs | titleAs | expectedOrder
${undefined} | ${undefined} | ${titleFirst}
${undefined} | ${'span'} | ${titleFirst}
${undefined} | ${'h1'} | ${titleFirst}
${'span'} | ${undefined} | ${titleFirst}
${'h3'} | ${undefined} | ${titleFirst}
${'h3'} | ${'h1'} | ${titleFirst}
${'span'} | ${'h1'} | ${titleFirst}
${'h1'} | ${undefined} | ${pretitleFirst}
${'h1'} | ${'h3'} | ${pretitleFirst}
${'h1'} | ${'span'} | ${pretitleFirst}
`(
'Header has correct reading order with pretitleAs={$pretitleAs} and titleAs={$titleAs}',
async ({pretitleAs, titleAs, expectedOrder}) => {
render(
<ThemeContextProvider theme={makeTheme()}>
<Header
headline="Headline"
pretitle="Pretitle"
title="Title"
description="Description"
titleAs={titleAs}
pretitleAs={pretitleAs}
dataAttributes={{testid: 'header'}}
/>
</ThemeContextProvider>
);

const header = await screen.findByTestId('header');
expect(header.textContent).toEqual(expectedOrder);
}
);

0 comments on commit 7862897

Please sign in to comment.