autocomplete-visuals.cy.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. const options = [
  7. {
  8. value: 0,
  9. label: 'Item A',
  10. },
  11. {
  12. value: 1,
  13. label: 'Item B',
  14. },
  15. {
  16. value: 2,
  17. label: 'Item C',
  18. },
  19. {
  20. value: 3,
  21. label: 'Item D',
  22. },
  23. {
  24. value: 4,
  25. label: 'Item E',
  26. },
  27. {
  28. value: 5,
  29. label:
  30. 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vestibulum sem quis purus elementum pulvinar.',
  31. },
  32. {
  33. value: 6,
  34. label: 'Item F',
  35. },
  36. {
  37. value: 7,
  38. label: 'Item G',
  39. },
  40. {
  41. value: 8,
  42. label: 'Item H',
  43. },
  44. ]
  45. describe('testing visuals for "FieldAutocomplete"', () => {
  46. const inputs = [
  47. { type: 'customer' },
  48. { type: 'organization' },
  49. { type: 'autocomplete' },
  50. { type: 'recipient' },
  51. ]
  52. inputs.forEach(({ type }) => {
  53. it(`renders basic ${type}`, () => {
  54. mountFormField(type, { label: type, options })
  55. checkFormMatchesSnapshot({ type })
  56. })
  57. it(`renders basic disabled ${type}`, () => {
  58. mountFormField(type, { label: type, options, disabled: true })
  59. checkFormMatchesSnapshot({ type })
  60. })
  61. it(`renders basic required ${type}`, () => {
  62. mountFormField(type, { label: type, options, required: true })
  63. checkFormMatchesSnapshot({ type })
  64. })
  65. it(`renders basic invalid ${type}`, () => {
  66. mountFormField(type, {
  67. label: type,
  68. options,
  69. required: true,
  70. validationVisibility: FormValidationVisibility.Live,
  71. })
  72. checkFormMatchesSnapshot({ type })
  73. })
  74. it(`renders basic ${type} with help`, () => {
  75. mountFormField(type, { label: type, options, help: 'Help Message!' })
  76. checkFormMatchesSnapshot({ type })
  77. })
  78. it(`renders selected ${type}`, () => {
  79. mountFormField(type, { label: type, options, value: 0 })
  80. checkFormMatchesSnapshot({ type })
  81. })
  82. it(`renders selected disabled ${type}`, () => {
  83. mountFormField(type, { label: type, options, value: 0, disabled: true })
  84. checkFormMatchesSnapshot({ type })
  85. })
  86. it(`renders selected required ${type}`, () => {
  87. mountFormField(type, { label: type, options, value: 0, required: true })
  88. checkFormMatchesSnapshot({ type })
  89. })
  90. it(`renders focused ${type}`, () => {
  91. mountFormField(type, { label: type, options })
  92. cy.get('output')
  93. .focus()
  94. .then(() => {
  95. checkFormMatchesSnapshot({ type })
  96. })
  97. })
  98. it(`renders focused linked ${type}`, () => {
  99. mountFormField(type, { label: type, options, link: '/' })
  100. cy.get('output')
  101. .focus()
  102. .then(() => {
  103. checkFormMatchesSnapshot({ type })
  104. })
  105. })
  106. it(`renders multiple ${type}`, () => {
  107. mountFormField(type, {
  108. label: type,
  109. options,
  110. multiple: true,
  111. value: [0, 1],
  112. })
  113. checkFormMatchesSnapshot({ type })
  114. })
  115. it(`renders multiple disabled ${type}`, () => {
  116. mountFormField(type, {
  117. label: type,
  118. options,
  119. multiple: true,
  120. value: [0, 1],
  121. disabled: true,
  122. })
  123. checkFormMatchesSnapshot({ type })
  124. })
  125. it(`renders multiple required ${type}`, () => {
  126. mountFormField(type, {
  127. label: type,
  128. options,
  129. multiple: true,
  130. value: [0, 1],
  131. required: true,
  132. })
  133. checkFormMatchesSnapshot({ type })
  134. })
  135. it(`renders long ${type}`, () => {
  136. mountFormField(type, { label: type, value: 5, options })
  137. checkFormMatchesSnapshot({
  138. type,
  139. assertion: ($el) => {
  140. expect($el.height()).to.be.above(60)
  141. return $el
  142. },
  143. })
  144. })
  145. it(`renders hidden ${type}`, () => {
  146. mountFormField(type, { label: type, labelSrOnly: true })
  147. checkFormMatchesSnapshot({ type })
  148. })
  149. it(`renders selected hidden ${type}`, () => {
  150. mountFormField(type, {
  151. label: type,
  152. value: 0,
  153. options,
  154. labelSrOnly: true,
  155. })
  156. checkFormMatchesSnapshot({ type })
  157. })
  158. })
  159. })