import { beforeEach, describe, expect, it } from 'vitest' import DropdownMenu from './story/_DropdownMenu.vue' import type { VueWrapper } from '@vue/test-utils' import { mount } from '@vue/test-utils' import { axe } from 'vitest-axe' import { findByRole } from '@testing-library/vue' describe('given default DropdownMenu', () => { let wrapper: VueWrapper> globalThis.ResizeObserver = class ResizeObserver { observe() {} unobserve() {} disconnect() {} } beforeEach(() => { document.body.innerHTML = '' wrapper = mount(DropdownMenu, { attachTo: document.body }) }) it('should render trigger button', () => { expect(wrapper.find('button').exists()).toBeTruthy() }) it('should pass axe accessibility tests', async () => { expect(await axe(wrapper.element)).toHaveNoViolations() }) describe('after opening the dropdown', () => { beforeEach(async () => { await wrapper.find('button').trigger('click') }) it('should pass axe accessibility tests', async () => { expect(await axe(wrapper.element)).toHaveNoViolations() }) it('should render the menu', async () => { expect(await findByRole(wrapper.element as HTMLElement, 'menu')).toBeTruthy() }) describe('after selecting the first item', () => { beforeEach(async () => { const item = wrapper.find('[role="menuitem"]') await item.trigger('click') }) it('should close the modal', () => { expect(wrapper.find('[role="menu"]').exists()).toBeFalsy() }) it('should emit select event', () => { expect(wrapper.emitted('select')?.length).toBe(1) }) }) }) })