input-visuals.cy.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. // To update snapshots, run `pnpm cypress:snapshots`
  3. // DO NOT update snapshots, when running with --open flag (Cypress GUI)
  4. import { mountFormField, checkFormMatchesSnapshot } from '#cy/utils.ts'
  5. import { FormValidationVisibility } from '#shared/components/Form/types.ts'
  6. describe('testing visuals for "FieldInput"', () => {
  7. const inputs = [
  8. { type: 'text', input: 'Some Text' },
  9. { type: 'email', input: 'some@mail.com' },
  10. { type: 'number', input: '100' },
  11. { type: 'tel', input: '123456789' },
  12. { type: 'time', input: '12:12' },
  13. ]
  14. inputs.forEach(({ type, input }) => {
  15. it(`renders usual ${type}`, () => {
  16. mountFormField(type, { label: type })
  17. checkFormMatchesSnapshot({ type })
  18. cy.get('input')
  19. .focus()
  20. .then(() => {
  21. checkFormMatchesSnapshot({ subTitle: 'focused', type })
  22. })
  23. cy.get('input')
  24. .type(input)
  25. .then(() => {
  26. checkFormMatchesSnapshot({ subTitle: 'filled', type })
  27. })
  28. })
  29. it(`renders required ${type}`, () => {
  30. mountFormField(type, { label: type, required: true })
  31. checkFormMatchesSnapshot({ type })
  32. cy.get('input')
  33. .focus()
  34. .then(() => {
  35. checkFormMatchesSnapshot({ subTitle: 'focused', type })
  36. })
  37. cy.get('input')
  38. .type(input)
  39. .then(() => {
  40. checkFormMatchesSnapshot({ subTitle: 'filled', type })
  41. })
  42. })
  43. it(`renders invalid ${type}`, () => {
  44. mountFormField(type, {
  45. label: type,
  46. required: true,
  47. validationVisibility: FormValidationVisibility.Live,
  48. })
  49. checkFormMatchesSnapshot({ type })
  50. })
  51. it(`renders ${type} with help`, () => {
  52. mountFormField(type, {
  53. label: type,
  54. help: 'Help message!',
  55. })
  56. checkFormMatchesSnapshot({ type })
  57. })
  58. it(`renders linked ${type}`, () => {
  59. mountFormField(type, { label: type, link: '/' })
  60. checkFormMatchesSnapshot({ type })
  61. cy.get('input')
  62. .focus()
  63. .then(() => {
  64. checkFormMatchesSnapshot({ subTitle: 'focused', type })
  65. })
  66. cy.get('input')
  67. .type(input)
  68. .then(() => {
  69. checkFormMatchesSnapshot({ subTitle: 'filled', type })
  70. })
  71. })
  72. it(`renders disabled ${type}`, () => {
  73. mountFormField(type, { label: type, disabled: true })
  74. checkFormMatchesSnapshot({ type })
  75. })
  76. it(`renders hidden ${type}`, () => {
  77. mountFormField(type, { label: type, labelSrOnly: true })
  78. checkFormMatchesSnapshot({ type })
  79. cy.get('input')
  80. .type(input)
  81. .then(() => {
  82. checkFormMatchesSnapshot({ subTitle: 'filled', type })
  83. })
  84. })
  85. })
  86. })