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

[Unit Test] - Selectable Tag #17711

Merged
merged 20 commits into from
Oct 16, 2024
Merged
Changes from all 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
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
Loading