Skip to content

Commit

Permalink
test: [M3-8550] - Add unit tests for EntityHeader component (#11222)
Browse files Browse the repository at this point in the history
* test: [M3-8550] - Add unit tests for EntityHeader component

* Added changeset: unit test cases for EntityHeader component
  • Loading branch information
hasyed-akamai authored Nov 15, 2024
1 parent 26258af commit bd6ddb9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11222-added-1730959236426.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

unit test cases for EntityHeader component ([#11222](https://github.com/linode/manager/pull/11222))
40 changes: 40 additions & 0 deletions packages/manager/src/components/EntityHeader/EntityHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';

import { renderWithTheme } from 'src/utilities/testHelpers';

import { EntityHeader } from './EntityHeader';

import { HeaderProps } from './EntityHeader';

const mockText = 'Hello world';

const defaultProps: HeaderProps = {
title: mockText,
};

describe('EntityHeader', () => {
it('should render title with variant when isSummaryView is True', () => {
const { getByRole } = renderWithTheme(
<EntityHeader variant="h2" isSummaryView {...defaultProps} />
);
const heading = getByRole('heading', { level: 2 });
expect(heading).toBeInTheDocument();
expect(heading).toHaveTextContent(mockText);
});

it('should not render title when isSummaryView is False', () => {
const { queryByText } = renderWithTheme(
<EntityHeader isSummaryView={false} {...defaultProps} />
);
expect(queryByText(mockText)).not.toBeInTheDocument();
});

it('should render children if provided', () => {
const { getByText } = renderWithTheme(
<EntityHeader {...defaultProps}>
<div>Child items can go here!</div>
</EntityHeader>
);
expect(getByText('Child items can go here!')).toBeInTheDocument();
});
});

0 comments on commit bd6ddb9

Please sign in to comment.