CommonStepper.spec.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. import { renderComponent } from '#tests/support/components/index.ts'
  4. import type { FormStep } from '#shared/components/Form/types.ts'
  5. import CommonStepper from '../CommonStepper.vue'
  6. describe('stepper component', () => {
  7. test('renders valid steps', async () => {
  8. const modelValue = ref('step1')
  9. const steps: Record<string, FormStep> = {
  10. step1: {
  11. label: '1',
  12. order: 1,
  13. errorCount: 0,
  14. valid: true,
  15. disabled: false,
  16. completed: true,
  17. },
  18. step2: {
  19. label: '2',
  20. order: 2,
  21. errorCount: 0,
  22. valid: true,
  23. disabled: false,
  24. completed: false,
  25. },
  26. step3: {
  27. label: '3',
  28. order: 3,
  29. errorCount: 0,
  30. valid: true,
  31. completed: false,
  32. disabled: true,
  33. },
  34. step4: {
  35. label: '4',
  36. order: 4,
  37. errorCount: 3,
  38. valid: false,
  39. completed: true,
  40. disabled: true,
  41. },
  42. }
  43. const view = renderComponent(CommonStepper, {
  44. props: {
  45. steps,
  46. },
  47. vModel: {
  48. modelValue,
  49. },
  50. })
  51. await view.events.click(view.getByText('2'))
  52. expect(modelValue.value).toBe('step2')
  53. expect(
  54. view.getByRole('status', { name: 'Invalid values in step 4' }),
  55. ).toHaveTextContent('3')
  56. expect(
  57. view.getByRole('button', { name: 'Step 1 is completed' }),
  58. ).toBeInTheDocument()
  59. await view.events.click(view.getByRole('button', { name: '3' }))
  60. expect(modelValue.value).toBe('step2')
  61. })
  62. })