CommonSelectPill.spec.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import CommonSelectPill from '../CommonSelectPill.vue'
  4. const options = [
  5. { value: '1', label: 'Option 1' },
  6. { value: '2', label: 'Option 2' },
  7. ]
  8. describe('testing small button to trigger select', () => {
  9. // most of the select functionality is tested inside CommonSelect, this is just a wrapper
  10. it('should open select dialog', async () => {
  11. const view = renderComponent(CommonSelectPill, {
  12. props: {
  13. placeholder: 'Label',
  14. options,
  15. },
  16. vModel: {
  17. modelValue: null,
  18. },
  19. dialog: true,
  20. })
  21. const button = view.getByRole('button', { name: 'Label' })
  22. expect(button).toBeInTheDocument()
  23. await view.events.click(button)
  24. expect(view.getByRole('dialog')).toBeInTheDocument()
  25. await view.events.click(view.getByRole('option', { name: 'Option 1' }))
  26. expect(view.getByRole('button', { name: 'Option 1' })).toBeInTheDocument()
  27. })
  28. it('should render slot', () => {
  29. const view = renderComponent(CommonSelectPill, {
  30. props: {
  31. options,
  32. },
  33. slots: {
  34. default: '<div data-test-id="slot">Slot</div>',
  35. },
  36. })
  37. expect(view.getByTestId('slot')).toBeInTheDocument()
  38. })
  39. it('returns focus when closing dialog', async () => {
  40. const view = renderComponent(CommonSelectPill, {
  41. props: {
  42. placeholder: 'Label',
  43. options,
  44. },
  45. vModel: {
  46. modelValue: null,
  47. },
  48. dialog: true,
  49. })
  50. const openButton = view.getByRole('button', { name: 'Label' })
  51. expect(openButton).toBeInTheDocument()
  52. await view.events.click(openButton)
  53. expect(view.getByRole('option', { name: 'Option 1' })).toBeInTheDocument()
  54. await view.events.keyboard('{Escape}')
  55. expect(openButton).toHaveFocus()
  56. })
  57. })