CommonSelectPill.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '@tests/support/components'
  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. })