From 6323fe7f4c639f78c80e9b9225722a6fbddee30b Mon Sep 17 00:00:00 2001 From: luiqor Date: Mon, 16 Dec 2024 21:30:05 +0200 Subject: [PATCH] add menu item tests --- .../components/menu-item/MenuItem.spec.jsx | 74 +++++++++++++++++++ .../components/menu/Menu.spec.jsx | 17 +---- 2 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 tests/unit/design-system/components/menu-item/MenuItem.spec.jsx diff --git a/tests/unit/design-system/components/menu-item/MenuItem.spec.jsx b/tests/unit/design-system/components/menu-item/MenuItem.spec.jsx new file mode 100644 index 000000000..5d2368c89 --- /dev/null +++ b/tests/unit/design-system/components/menu-item/MenuItem.spec.jsx @@ -0,0 +1,74 @@ +import { render, fireEvent, screen } from '@testing-library/react' +import MenuItem from '~scss-components/menu-item/MenuItem' + +const resourceMenuItemTitle = 'Lesson' + +const icon = + +const checkbox = + +const additionalInfo = 'This is a lesson' + +describe('MenuItem Component', () => { + test('should render menu item', () => { + render() + expect(screen.getByText(resourceMenuItemTitle)).toBeInTheDocument() + }) + + test('should call onClick when menu item is clicked', () => { + const onClick = vi.fn() + render() + fireEvent.click(screen.getByText(resourceMenuItemTitle)) + expect(onClick).toHaveBeenCalled() + }) + + test('should render svg graphics', () => { + render() + expect(screen.getByTestId('lesson-icon')).toBeInTheDocument() + }) + + test('should render checkbox', () => { + render() + expect(screen.getByRole('checkbox')).toBeInTheDocument() + }) + + test('should check checkbox when menu item clicked', () => { + render() + fireEvent.click(screen.getByText(resourceMenuItemTitle)) + expect(screen.getByRole('checkbox')).toBeChecked() + }) + + test('should display close button when removal is enabled', () => { + const { container } = render( + {}} /> + ) + const closeButton = container.querySelector('.s2s-item__close') + + expect(closeButton).toBeInTheDocument() + }) + + test('should not display close button when dropdown is enabled', () => { + const { container } = render( + {}} /> + ) + const closeButton = container.querySelector('.s2s-item__close') + + expect(closeButton).not.toBeInTheDocument() + }) + + test('should call onRemove when close button is clicked', () => { + const onRemove = vi.fn() + const { container } = render( + + ) + fireEvent.click(container.querySelector('.s2s-item__close')) + expect(onRemove).toHaveBeenCalled() + }) + + test('should render additional info', () => { + render( + + ) + expect(screen.getByText(additionalInfo)).toBeInTheDocument() + }) +}) diff --git a/tests/unit/design-system/components/menu/Menu.spec.jsx b/tests/unit/design-system/components/menu/Menu.spec.jsx index 35773880c..2db05eb6e 100644 --- a/tests/unit/design-system/components/menu/Menu.spec.jsx +++ b/tests/unit/design-system/components/menu/Menu.spec.jsx @@ -1,4 +1,4 @@ -import { render, fireEvent, screen, waitFor } from '@testing-library/react' +import { render, fireEvent, screen } from '@testing-library/react' import Menu from '~scss-components/menu/Menu' const resourcesMenuItems = [ @@ -19,18 +19,9 @@ const resourcesMenuItemsWithAdditionalInfo = [ { title: 'Lesson', additionalInfo: 'This is a lesson' } ] -const circleIcon = ( - - - -) - -const resourcesMenuItemsWithIcon = [{ title: 'Lesson', graphics: circleIcon }] +const lessonIcon = + +const resourcesMenuItemsWithIcon = [{ title: 'Lesson', graphics: lessonIcon }] const noItemsCustomMessage = 'No items available.'