CommonInputSearch.spec.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { onMounted, ref } from 'vue'
  3. import { renderComponent } from '#tests/support/components/index.ts'
  4. import CommonInputSearch, {
  5. type CommonInputSearchExpose,
  6. } from '../CommonInputSearch.vue'
  7. describe('testing input for searching', () => {
  8. it('renders input', async () => {
  9. const view = renderComponent(CommonInputSearch, {
  10. vModel: {
  11. modelValue: '',
  12. },
  13. })
  14. expect(view.getByIconName('search')).toBeInTheDocument()
  15. expect(view.queryByIconName('close-small')).not.toBeInTheDocument()
  16. await view.events.type(view.getByRole('searchbox'), 'test')
  17. const clearButton = view.getByIconName('close-small')
  18. expect(clearButton).toBeInTheDocument()
  19. await view.events.click(clearButton)
  20. expect(view.getByRole('searchbox')).toHaveDisplayValue('')
  21. })
  22. it('can focus outside of the component', async () => {
  23. let focus: () => void
  24. const component = {
  25. components: { CommonInputSearch },
  26. template: `<CommonInputSearch ref="searchInput" />`,
  27. setup() {
  28. const searchInput = ref<null | CommonInputSearchExpose>()
  29. onMounted(() => {
  30. ;({ focus } = searchInput.value!)
  31. })
  32. return { searchInput }
  33. },
  34. }
  35. const view = renderComponent(component)
  36. focus!()
  37. expect(view.getByRole('searchbox')).toHaveFocus()
  38. })
  39. })