From 8eb5c3da5842c42bf9e7b9b7e3a0158331097b67 Mon Sep 17 00:00:00 2001 From: Ed Sungik Choi Date: Mon, 23 Dec 2024 15:20:07 +0900 Subject: [PATCH] test: add unit test --- .../src/components/AlphaIcon/Icon.test.tsx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 packages/bezier-react/src/components/AlphaIcon/Icon.test.tsx diff --git a/packages/bezier-react/src/components/AlphaIcon/Icon.test.tsx b/packages/bezier-react/src/components/AlphaIcon/Icon.test.tsx new file mode 100644 index 000000000..3ff9f3d38 --- /dev/null +++ b/packages/bezier-react/src/components/AlphaIcon/Icon.test.tsx @@ -0,0 +1,43 @@ +import { ChannelBtnFilledIcon } from '@channel.io/bezier-icons' +import { render, screen } from '@testing-library/react' + +import { Icon } from './Icon' + +describe('Icon', () => { + const renderIcon = (props = {}) => + render( + + ) + + it('should render', () => { + renderIcon() + expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument() + }) + + describe('Accessibility', () => { + it('should be decorative by default', () => { + renderIcon() + expect(screen.getByRole('img', { hidden: true })).toHaveAttribute( + 'aria-hidden', + 'true' + ) + }) + + it('should be accessible with aria-label', () => { + renderIcon({ 'aria-label': 'Channel Button' }) + expect(screen.getByRole('img')).toHaveAttribute( + 'aria-label', + 'Channel Button' + ) + expect(screen.getByRole('img')).toBeInTheDocument() + }) + + it('should respect explicit aria-hidden', () => { + renderIcon({ 'aria-hidden': false }) + expect(screen.getByRole('img')).toBeInTheDocument() + }) + }) +})