// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ import { flushPromises } from '@vue/test-utils' import { ref } from 'vue' import { renderComponent } from '#tests/support/components/index.ts' import CommonSectionPopup from '../CommonSectionPopup.vue' import type { PopupItemDescriptor } from '../types.ts' const html = String.raw describe('popup behaviour', () => { it('renders list', async () => { const onAction = vi.fn() const messages: PopupItemDescriptor[] = [ { type: 'link', label: 'Link', link: '/', }, { type: 'button', label: 'Action', onAction, }, ] const view = renderComponent(CommonSectionPopup, { props: { messages, }, router: true, vModel: { state: true, }, }) const [linkItem, actionItem] = messages const link = view.getByText(linkItem.label) const action = view.getByText(actionItem.label) expect(link).toBeInTheDocument() expect(action).toBeInTheDocument() expect(view.getLinkFromElement(link)).toHaveAttribute('href', '/mobile/') await view.events.click(action) expect(onAction).toHaveBeenCalledOnce() }) it('can close list', async () => { const state = ref(true) const view = renderComponent(CommonSectionPopup, { props: { messages: [], }, vModel: { state, }, }) await view.events.click(view.getByText('Cancel')) expect(view.queryByTestId('popupWindow')).not.toBeInTheDocument() state.value = true await flushPromises() expect(view.queryByTestId('popupWindow')).toBeInTheDocument() await view.events.click(document.body) expect(view.queryByTestId('popupWindow')).not.toBeInTheDocument() }) it('autofocuses fist element and traps focus inside', async () => { const externalForm = document.createElement('form') externalForm.innerHTML = html`