select-visuals.cy.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. // To update snapshots, run `yarn 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. Quisque placerat nibh et dignissim tincidunt. Morbi semper tortor at dolor mollis laoreet. Aenean fringilla fermentum leo non finibus. Nulla porttitor lacus diam, at vestibulum risus viverra a',
  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. const value = 0
  46. const values = [0, 1]
  47. describe('testing visuals for "FieldSelect"', () => {
  48. it('renders basic select', () => {
  49. mountFormField('select', { label: 'select' })
  50. checkFormMatchesSnapshot()
  51. })
  52. it('renders basic disabled select', () => {
  53. mountFormField('select', { label: 'select', disabled: true })
  54. checkFormMatchesSnapshot()
  55. })
  56. it('renders basic required select', () => {
  57. mountFormField('select', { label: 'select', required: true })
  58. checkFormMatchesSnapshot()
  59. })
  60. it('renders basic invalid select', () => {
  61. mountFormField('select', {
  62. label: 'select',
  63. required: true,
  64. validationVisibility: FormValidationVisibility.Live,
  65. })
  66. checkFormMatchesSnapshot()
  67. })
  68. it(`renders focused select`, () => {
  69. mountFormField('select', { label: 'select' })
  70. cy.get('output')
  71. .focus()
  72. .then(() => {
  73. checkFormMatchesSnapshot()
  74. })
  75. })
  76. it(`renders focused linked select`, () => {
  77. mountFormField('select', { label: 'select', link: '/' })
  78. cy.get('output')
  79. .focus()
  80. .then(() => {
  81. checkFormMatchesSnapshot()
  82. })
  83. })
  84. it('renders linked select', () => {
  85. mountFormField('select', { label: 'select', link: '/' })
  86. checkFormMatchesSnapshot()
  87. })
  88. it('renders select with help', () => {
  89. mountFormField('select', { label: 'select', help: 'Help Message!' })
  90. checkFormMatchesSnapshot()
  91. })
  92. it('renders selected select', () => {
  93. mountFormField('select', { label: 'select', options, value })
  94. checkFormMatchesSnapshot()
  95. })
  96. it('renders selected disabled select', () => {
  97. mountFormField('select', {
  98. label: 'select',
  99. options,
  100. value,
  101. disabled: true,
  102. })
  103. checkFormMatchesSnapshot()
  104. })
  105. it('renders selected required select', () => {
  106. mountFormField('select', {
  107. label: 'select',
  108. options,
  109. value,
  110. required: true,
  111. })
  112. checkFormMatchesSnapshot()
  113. })
  114. it('renders selected select linked', () => {
  115. mountFormField('select', { label: 'select', options, value, link: '/' })
  116. checkFormMatchesSnapshot()
  117. })
  118. it('renders multiple selected select', () => {
  119. mountFormField('select', {
  120. label: 'select',
  121. options,
  122. value: values,
  123. multiple: true,
  124. })
  125. checkFormMatchesSnapshot()
  126. })
  127. it('renders multiple selected disabled select', () => {
  128. mountFormField('select', {
  129. label: 'select',
  130. options,
  131. value: values,
  132. multiple: true,
  133. disabled: true,
  134. })
  135. checkFormMatchesSnapshot()
  136. })
  137. it('renders multiple selected required select', () => {
  138. mountFormField('select', {
  139. label: 'select',
  140. options,
  141. value: values,
  142. multiple: true,
  143. required: true,
  144. })
  145. checkFormMatchesSnapshot()
  146. })
  147. it('renders long multiple selected', () => {
  148. mountFormField('select', {
  149. label: 'select',
  150. options,
  151. value: [0, 1, 2, 3, 4, 6, 7, 8],
  152. multiple: true,
  153. })
  154. checkFormMatchesSnapshot()
  155. })
  156. it('renders long selected', () => {
  157. mountFormField('select', {
  158. label: 'select',
  159. options,
  160. value: 5,
  161. })
  162. checkFormMatchesSnapshot()
  163. })
  164. it(`renders hidden select`, () => {
  165. mountFormField('select', { label: 'select', labelSrOnly: true })
  166. checkFormMatchesSnapshot()
  167. })
  168. it(`renders selected hidden select`, () => {
  169. mountFormField('select', {
  170. label: 'select',
  171. value: 0,
  172. options,
  173. labelSrOnly: true,
  174. })
  175. checkFormMatchesSnapshot()
  176. })
  177. })