-
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
- Loading branch information
1 parent
0285c7a
commit 0297ba5
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
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 when clciked on close Button', 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