Skip to content

Commit

Permalink
[Unit test] - Dismissible Tag (#17716)
Browse files Browse the repository at this point in the history
* test: added test for dismissible tag

* test: change selector
  • Loading branch information
guidari authored Oct 14, 2024
1 parent 5d65d49 commit 99db933
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions packages/react/src/components/Tag/Tag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,43 @@ describe('Tag', () => {
});
});

it('should have an appropriate aria-label when (filterable)', () => {
const { container } = render(
<DismissibleTag type="red" title="Close tag" text="Tag content" />
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
const button = container.querySelector('[aria-label]');
const accessibilityLabel = button.getAttribute('aria-label');
// This check would mirror our "Accessibility label must contain at least all of visible label"
// requirement
expect(accessibilityLabel).toEqual(expect.stringContaining('Close tag'));
describe('Dismissible Tag', () => {
it('should render a Dismissible Tag state', () => {
const { container } = render(
<DismissibleTag type="red" title="Close tag" text="Tag content" />
);

expect(container.firstChild).toHaveClass(`${prefix}--tag--filter`);
});

it('should support onClose event', async () => {
const onClick = jest.fn();

const { container } = render(
<DismissibleTag
type="red"
title="Close tag"
text="Tag content"
onClose={onClick}
/>
);

await userEvent.click(screen.getByRole('button'));

expect(onClick).toHaveBeenCalled();
});

it('should have an appropriate aria-label when (filterable)', () => {
const { container } = render(
<DismissibleTag type="red" title="Close tag" text="Tag content" />
);
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
const button = container.querySelector('[aria-label]');
const accessibilityLabel = button.getAttribute('aria-label');
// This check would mirror our "Accessibility label must contain at least all of visible label"
// requirement
expect(accessibilityLabel).toEqual(expect.stringContaining('Close tag'));
});
});

it('should allow for a custom label', () => {
Expand Down

0 comments on commit 99db933

Please sign in to comment.