treeselect-visuals.cy.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. children: [
  11. {
  12. value: 1,
  13. label: 'Item 1',
  14. children: [
  15. {
  16. value: 2,
  17. label: 'Item I',
  18. },
  19. {
  20. value: 3,
  21. label: 'Item II',
  22. },
  23. {
  24. value: 4,
  25. label: 'Item III',
  26. },
  27. ],
  28. },
  29. {
  30. value: 5,
  31. label:
  32. 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vestibulum sem quis purus elementum pulvinar.',
  33. children: [
  34. {
  35. value: 6,
  36. label: 'Item IV',
  37. },
  38. ],
  39. },
  40. {
  41. value: 7,
  42. label: 'Item 3',
  43. },
  44. ],
  45. },
  46. {
  47. value: 8,
  48. label: 'Item B',
  49. },
  50. {
  51. value: 9,
  52. label: 'Ítem C',
  53. },
  54. ]
  55. const value = 0
  56. describe('testing visuals for "FieldTreeSelect"', () => {
  57. it('renders basic disabled select', () => {
  58. mountFormField('treeselect', {
  59. label: 'treeselect',
  60. disabled: true,
  61. })
  62. checkFormMatchesSnapshot()
  63. })
  64. it('renders basic required select', () => {
  65. mountFormField('treeselect', {
  66. label: 'treeselect',
  67. required: true,
  68. })
  69. checkFormMatchesSnapshot()
  70. })
  71. it('renders basic invalid treeselect', () => {
  72. mountFormField('treeselect', {
  73. label: 'treeselect',
  74. required: true,
  75. validationVisibility: FormValidationVisibility.Live,
  76. })
  77. checkFormMatchesSnapshot()
  78. })
  79. it(`renders focused treeselect`, () => {
  80. mountFormField('treeselect', { label: 'treeselect' })
  81. cy.get('output')
  82. .focus()
  83. .then(() => {
  84. checkFormMatchesSnapshot()
  85. })
  86. })
  87. it(`renders focused linked treeselect`, () => {
  88. mountFormField('treeselect', { label: 'treeselect', link: '/' })
  89. cy.get('output')
  90. .focus()
  91. .then(() => {
  92. checkFormMatchesSnapshot()
  93. })
  94. })
  95. it('renders linked select', () => {
  96. mountFormField('treeselect', { label: 'treeselect', link: '/' })
  97. checkFormMatchesSnapshot()
  98. })
  99. it('renders selected select', () => {
  100. mountFormField('treeselect', { label: 'treeselect', options, value })
  101. checkFormMatchesSnapshot()
  102. })
  103. it('renders selected disabled select', () => {
  104. mountFormField('treeselect', {
  105. label: 'treeselect',
  106. options,
  107. value,
  108. disabled: true,
  109. })
  110. checkFormMatchesSnapshot()
  111. })
  112. it('renders selected required select', () => {
  113. mountFormField('treeselect', {
  114. label: 'treeselect',
  115. options,
  116. value,
  117. required: true,
  118. })
  119. checkFormMatchesSnapshot()
  120. })
  121. it('renders selected select linked', () => {
  122. mountFormField('treeselect', {
  123. label: 'treeselect',
  124. options,
  125. value,
  126. link: '/',
  127. })
  128. checkFormMatchesSnapshot()
  129. })
  130. it('renders multiple selected select', () => {
  131. mountFormField('treeselect', {
  132. label: 'treeselect',
  133. options,
  134. value: [0, 1],
  135. multiple: true,
  136. })
  137. checkFormMatchesSnapshot()
  138. })
  139. it('renders multiple selected disabled select', () => {
  140. mountFormField('treeselect', {
  141. label: 'treeselect',
  142. options,
  143. value: [0, 1],
  144. multiple: true,
  145. disabled: true,
  146. })
  147. checkFormMatchesSnapshot()
  148. })
  149. it('renders multiple selected required select', () => {
  150. mountFormField('treeselect', {
  151. label: 'treeselect',
  152. options,
  153. value: [0, 1],
  154. multiple: true,
  155. required: true,
  156. })
  157. checkFormMatchesSnapshot()
  158. })
  159. it('renders long multiple selected', () => {
  160. mountFormField('treeselect', {
  161. label: 'treeselect',
  162. options,
  163. value: [0, 1, 2, 3, 4, 6, 7, 8],
  164. multiple: true,
  165. })
  166. checkFormMatchesSnapshot()
  167. })
  168. it('renders long selected', () => {
  169. mountFormField('treeselect', {
  170. label: 'treeselect',
  171. options,
  172. value: 5,
  173. })
  174. checkFormMatchesSnapshot()
  175. })
  176. it(`renders hidden treeselect`, () => {
  177. mountFormField('treeselect', { label: 'treeselect', labelSrOnly: true })
  178. checkFormMatchesSnapshot()
  179. })
  180. it(`renders treeselect with help`, () => {
  181. mountFormField('treeselect', { label: 'treeselect', help: 'Help Message!' })
  182. checkFormMatchesSnapshot()
  183. })
  184. it(`renders selected hidden treeselect`, () => {
  185. mountFormField('treeselect', {
  186. label: 'treeselect',
  187. value: 1,
  188. options,
  189. labelSrOnly: true,
  190. })
  191. checkFormMatchesSnapshot()
  192. })
  193. })