-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [M3-8546] - Add unit tests for
DialogTitle
component (#11340)
* test: [M3-8546] - Add unit tests for DialogTitle component * Added changeset: unit test cases for `DialogTitle` component * Fix capitalization nitpicks in test file * update changeset `Type` and `Description`
- Loading branch information
1 parent
2581eb5
commit f45fd17
Showing
3 changed files
with
60 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tests | ||
--- | ||
|
||
Add unit test cases for `DialogTitle` component ([#11340](https://github.com/linode/manager/pull/11340)) |
54 changes: 54 additions & 0 deletions
54
packages/manager/src/components/DialogTitle/DialogTitle.test.tsx
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,54 @@ | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { DialogTitle } from './DialogTitle'; | ||
|
||
import type { DialogTitleProps } from './DialogTitle'; | ||
|
||
const mockId = '1'; | ||
const mockSubtitle = 'This a basic dialog'; | ||
const mockTitle = 'This is a Dialog'; | ||
|
||
const defaultProps: DialogTitleProps = { | ||
id: mockId, | ||
subtitle: mockSubtitle, | ||
title: mockTitle, | ||
}; | ||
|
||
describe('DialogTitle', () => { | ||
it('should render title, subtitle and id', () => { | ||
const { getByRole, getByText } = renderWithTheme( | ||
<DialogTitle {...defaultProps} /> | ||
); | ||
expect(getByText(mockTitle)).toBeVisible(); | ||
expect(getByText(mockSubtitle)).toBeVisible(); | ||
const titleElement = getByRole('heading'); | ||
expect(titleElement).toHaveAttribute('id', mockId); | ||
}); | ||
|
||
it('should not render title when isFetching is true', () => { | ||
const { queryByText } = renderWithTheme( | ||
<DialogTitle isFetching {...defaultProps} /> | ||
); | ||
expect(queryByText(mockTitle)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should close the dialog Box if the close button is clicked', async () => { | ||
const onCloseMock = vi.fn(); | ||
const { getByRole } = renderWithTheme( | ||
<DialogTitle | ||
onClose={onCloseMock({}, 'escapeKeyDown')} | ||
{...defaultProps} | ||
/> | ||
); | ||
const closeButton = getByRole('button', { | ||
name: 'Close', | ||
}); | ||
expect(closeButton).toBeInTheDocument(); | ||
await userEvent.click(closeButton); | ||
expect(onCloseMock).toHaveBeenCalledTimes(1); | ||
expect(onCloseMock).toHaveBeenCalledWith({}, 'escapeKeyDown'); | ||
}); | ||
}); |
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