-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #589 from UKHSA-Internal/chore/CDD-2370-minimap-ca…
…rd-test Add test for MiniMapCard component
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { render, screen } from '@/config/test-utils' | ||
|
||
import { MiniMapCard } from './MiniMapCard' | ||
|
||
// | ||
jest.mock('./MiniMap', () => ({ | ||
MiniMap: jest.fn(() => <div>MiniMap Mock Component</div>), | ||
})) | ||
|
||
const renderMinimapComponent = (type: 'heat' | 'cold') => { | ||
const title = `${type} Health Alert` | ||
const subTitle = `${type} temperatures expected` | ||
const alertType = type | ||
|
||
const { container } = render(<MiniMapCard title={title} subTitle={subTitle} alertType={alertType} />) | ||
return { | ||
container, | ||
} | ||
} | ||
|
||
describe('MiniMapCard Component', () => { | ||
it('renders the heading with the correct title text', () => { | ||
renderMinimapComponent('heat') | ||
expect(screen.getByRole('heading', { level: 3 })).toHaveTextContent('heat Health Alert') | ||
}) | ||
|
||
it('renders the subtitle correctly', () => { | ||
renderMinimapComponent('cold') | ||
expect(screen.getByText('cold temperatures expected')).toBeInTheDocument() | ||
}) | ||
|
||
it('links to the correct summary page based on alertType (heat)', () => { | ||
renderMinimapComponent('heat') | ||
expect(screen.getByRole('link')).toHaveAttribute('href', '/weather-health-alerts/heat') | ||
}) | ||
|
||
it('links to the correct summary page based on alertType (cold)', () => { | ||
renderMinimapComponent('cold') | ||
expect(screen.getByRole('link')).toHaveAttribute('href', '/weather-health-alerts/cold') | ||
}) | ||
|
||
it('renders the MiniMap component with the correct alertType', () => { | ||
renderMinimapComponent('cold') | ||
expect(screen.getByText('MiniMap Mock Component')).toBeInTheDocument() | ||
}) | ||
|
||
it('has the correct aria-labelledby attribute for accessibility', () => { | ||
renderMinimapComponent('heat') | ||
expect(screen.getByRole('link')).toHaveAttribute('aria-labelledby', 'chart-row-card-heading-x4') | ||
}) | ||
|
||
it('applies the correct CSS classes to minimap card', () => { | ||
const { container } = renderMinimapComponent('heat') | ||
const card = container.querySelector('a') | ||
expect(card).toHaveClass( | ||
'govuk-link--no-visited-state govuk-!-padding-5 ukhsa-chart-card bg-[var(--colour-chart-background)]' | ||
) | ||
expect(card).toHaveClass( | ||
'no-underline transition-colors duration-200 ukhsa-focus hover:bg-[var(--colour-chart-background-hover)] focus:bg-[var(--colour-chart-background-hover)]' | ||
) | ||
}) | ||
}) |
0d4acc2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit tests coverage