Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [M3-8546] - Add unit tests for DialogTitle component #11340

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11340-added-1732789911285.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

unit test cases for `DialogTitle` component ([#11340](https://github.com/linode/manager/pull/11340))
hasyed-akamai marked this conversation as resolved.
Show resolved Hide resolved
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,
hasyed-akamai marked this conversation as resolved.
Show resolved Hide resolved
title: mockTitle,
};

describe('DialogTitle', () => {
it('should render title, subtitle and Id', () => {
hasyed-akamai marked this conversation as resolved.
Show resolved Hide resolved
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 () => {
hasyed-akamai marked this conversation as resolved.
Show resolved Hide resolved
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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as React from 'react';

import type { SxProps, Theme } from '@mui/material';

interface DialogTitleProps {
export interface DialogTitleProps {
className?: string;
id?: string;
isFetching?: boolean;
Expand Down
Loading