toggle-visuals.cy.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { checkFormMatchesSnapshot, mountFormField } from '#cy/utils.ts'
  3. import { FormValidationVisibility } from '#shared/components/Form/types.ts'
  4. // To update snapshots, run `pnpm cypress:snapshots`
  5. // DO NOT update snapshots, when running with --open flag (Cypress GUI)
  6. const variants = {
  7. true: 'Yes',
  8. false: 'No',
  9. }
  10. describe('testing visuals for "FieldToggle"', () => {
  11. it('renders basic toggle', () => {
  12. mountFormField('toggle', { label: 'Toggle', variants, value: false })
  13. checkFormMatchesSnapshot()
  14. cy.get('[tabindex="0"]')
  15. .focus()
  16. .then(() => {
  17. checkFormMatchesSnapshot({ subTitle: 'focused' })
  18. })
  19. })
  20. it('renders checked toggle', () => {
  21. mountFormField('toggle', { label: 'Toggle', variants, value: true })
  22. checkFormMatchesSnapshot()
  23. })
  24. it('renders disabled toggle', () => {
  25. mountFormField('toggle', { label: 'Toggle', variants, disabled: true })
  26. checkFormMatchesSnapshot()
  27. })
  28. it('renders invalid toggle', () => {
  29. mountFormField('toggle', {
  30. label: 'Toggle',
  31. required: true,
  32. variants,
  33. validationVisibility: FormValidationVisibility.Live,
  34. })
  35. checkFormMatchesSnapshot()
  36. })
  37. it('renders required toggle', () => {
  38. mountFormField('toggle', { label: 'Toggle', variants, required: true })
  39. checkFormMatchesSnapshot()
  40. })
  41. it(`renders hidden toggle`, () => {
  42. mountFormField('toggle', { label: 'Toggle', labelSrOnly: true })
  43. checkFormMatchesSnapshot()
  44. })
  45. it(`renders toggle with help`, () => {
  46. mountFormField('toggle', {
  47. label: 'Toggle',
  48. variants,
  49. help: 'Help Message!',
  50. })
  51. checkFormMatchesSnapshot()
  52. })
  53. })