diff --git a/packages/react/src/components/Tag/Tag-test.js b/packages/react/src/components/Tag/Tag-test.js index 526a3d0fb3e9..d6c91848b07d 100644 --- a/packages/react/src/components/Tag/Tag-test.js +++ b/packages/react/src/components/Tag/Tag-test.js @@ -11,6 +11,7 @@ import React from 'react'; import Tag, { TagSkeleton } from './'; import DismissibleTag from './DismissibleTag'; import { AILabel } from '../AILabel'; +import { Asleep } from '@carbon/icons-react'; const prefix = 'cds'; @@ -83,4 +84,76 @@ describe('Tag', () => { expect(skeletonTag).toHaveClass(`${prefix}--layout--size-sm`); }); }); + + it('should render with different types', () => { + const types = [ + 'red', + 'magenta', + 'purple', + 'blue', + 'cyan', + 'teal', + 'green', + 'gray', + 'cool-gray', + 'warm-gray', + 'high-contrast', + 'outline', + ]; + + types.forEach((type) => { + const { container } = render(Tag content); + expect(container.firstChild).toHaveClass(`${prefix}--tag--${type}`); + }); + }); + + it('should render with custom className', () => { + const { container } = render(Tag content); + expect(container.firstChild).toHaveClass('some-class'); + }); + + it('should render with icon', () => { + render(Tag content); + expect(screen.getByText('Tag content')).toBeInTheDocument(); + expect(document.querySelector('svg')).toBeInTheDocument(); + }); + + it('should render as a filter tag', () => { + const spy = jest.spyOn(console, 'warn').mockImplementation(() => {}); + const { container } = render(Tag content); + expect(container.firstChild).toHaveClass(`${prefix}--tag--filter`); + expect(spy).toHaveBeenCalled(); + spy.mockRestore(); + }); + + it('should render with different sizes', () => { + const sizes = ['sm', 'md', 'lg']; + + sizes.forEach((size) => { + const { container } = render(Tag content); + expect(container.firstChild).toHaveClass( + `${prefix}--tag ${prefix}--tag--${size} ${prefix}--layout--size-${size}` + ); + }); + }); + + it('should render as disabled', () => { + const { container } = render(Disabled Tag); + expect(container.firstChild).toHaveClass(`${prefix}--tag--disabled`); + }); + + it('should handle close button click', () => { + const spy = jest.spyOn(console, 'warn').mockImplementation(() => {}); + const mockOnClose = jest.fn(); + render( + + onClose + + ); + const closeButton = screen.getByTitle('Close tag'); + closeButton.click(); + expect(mockOnClose).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalled(); + spy.mockRestore(); + }); });