Skip to content

Commit

Permalink
[Unit Test] - Selectable Tag (#17711)
Browse files Browse the repository at this point in the history
* chore(release): v11.66.0 (#17413)

Co-authored-by: tay1orjones <3360588+tay1orjones@users.noreply.github.com>
Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>

* test: added test to skeleton

* test: removed tests for tag

* test: removed function

* test: added test for size prop

* test: added tests to Selectable Tag

* test: added test to selectable tag

* fix: removed wrong import

* fix: added icon back

* test: change selector

* fix: fixed imports

---------

Co-authored-by: carbon-automation[bot] <103539138+carbon-automation[bot]@users.noreply.github.com>
Co-authored-by: tay1orjones <3360588+tay1orjones@users.noreply.github.com>
Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 16, 2024
1 parent 1c34943 commit cb0764c
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions packages/react/src/components/Tag/Tag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/

import { Add } from '@carbon/icons-react';
import { render, screen } from '@testing-library/react';
import React from 'react';
import Tag, { OperationalTag, TagSkeleton } from './';
import DismissibleTag from './DismissibleTag';
import { render, screen } from '@testing-library/react';
import Tag, {
OperationalTag,
SelectableTag,
DismissibleTag,
TagSkeleton,
} from './';
import { AILabel } from '../AILabel';
import { Asleep } from '@carbon/icons-react';
import userEvent from '@testing-library/user-event';
import { Asleep, Add } from '@carbon/icons-react';

const prefix = 'cds';

Expand Down Expand Up @@ -95,6 +98,26 @@ describe('Tag', () => {
).toBeInTheDocument();
});

describe('Selectable Tag', () => {
it('should render a selectable tag', () => {
const { container } = render(<SelectableTag text="Tag content" />);

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

it('should select the selectable tag', async () => {
const { container } = render(<SelectableTag text="Tag content" />);

const selectableTag = container.querySelector(
`.${prefix}--tag--selectable`
);

await userEvent.click(selectableTag);
expect(selectableTag).toHaveAttribute('aria-pressed', 'true');
expect(selectableTag).toHaveClass(`${prefix}--tag--selectable-selected`);
});
});

describe('Skeleton Tag', () => {
it('should render a skeleton state', () => {
const { container } = render(<TagSkeleton />);
Expand Down

0 comments on commit cb0764c

Please sign in to comment.