CommonPopover.spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import CommonPopover from '../CommonPopover.vue'
  4. import { usePopover } from '../usePopover.ts'
  5. const html = String.raw
  6. const renderPopover = () => {
  7. const wrapper = renderComponent({
  8. components: { CommonPopover },
  9. template: html`
  10. <CommonPopover ref="popover" :owner="popoverTarget"
  11. ><span>Example Content</span></CommonPopover
  12. >
  13. <button ref="popoverTarget" @click="toggle">Click me</button>
  14. `,
  15. setup() {
  16. const { popover, popoverTarget, toggle } = usePopover()
  17. return {
  18. toggle,
  19. popover,
  20. popoverTarget,
  21. }
  22. },
  23. })
  24. return wrapper
  25. }
  26. describe('CommonPopover.vue', () => {
  27. it('does not render when popover is not open', () => {
  28. const view = renderComponent(CommonPopover, {
  29. props: {
  30. owner: null,
  31. },
  32. slots: {
  33. default: 'Example Content',
  34. },
  35. })
  36. expect(view.queryByText('Example Content')).not.toBeInTheDocument()
  37. })
  38. it('does toggle popover when target was clicked', async () => {
  39. const view = renderPopover()
  40. await view.events.click(view.getByText('Click me'))
  41. expect(view.getByText('Example Content')).toBeInTheDocument()
  42. await view.events.click(view.getByText('Click me'))
  43. expect(view.queryByText('Example Content')).not.toBeInTheDocument()
  44. })
  45. })