index.spec.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. describe('Test the /structures page', () => {
  2. beforeEach(() => {
  3. // visit the structures index
  4. cy.visit('/structures?parent=12097')
  5. // wait for the page to be completely loaded
  6. cy.get('.structure-card', { timeout: 8000 })
  7. cy.contains('Nos Structures adhérentes')
  8. })
  9. it('Map, filters, and all results shall display by default', () => {
  10. // leaflet map is visible and was correctly instanciated
  11. cy.get('#map', { timeout: 8000 })
  12. .should('be.visible')
  13. .children('.leaflet-pane')
  14. // an input exists with the label 'Quoi ?'
  15. cy.getByLabel('input', 'Quoi ?')
  16. .should('be.enabled')
  17. // an input exists with the label 'Où ?'
  18. cy.getByLabel('input', 'Où ?')
  19. .should('be.enabled')
  20. // a select exists with the label 'Type'
  21. cy.getByLabel('input', 'Type')
  22. .should('be.enabled')
  23. // a select exists with the label 'Département'
  24. cy.getByLabel('input', 'Département')
  25. .should('be.enabled')
  26. // a select exists with the label 'Fédération'
  27. cy.getByLabel('input', 'Fédération')
  28. .should('be.enabled')
  29. // a select exists with the label 'Distance'
  30. cy.getByLabel('input', 'Distance')
  31. .should('be.enabled')
  32. // there are results displayed
  33. cy.get('.structure-card').should('exist')
  34. })
  35. it('If view is set on list mode, map shall be hidden', () => {
  36. cy.get('button').contains('Liste').click()
  37. // map shall not be visible in list view
  38. cy.get('#map', { timeout: 8000 })
  39. .should('not.be.visible')
  40. // results should still be visible
  41. cy.get('.structure-card')
  42. .should('have.length', 8)
  43. })
  44. it('When list view is activated, displayed results and filters shall stay the same', () => {
  45. // extract the number of results
  46. let resultsCount
  47. cy.get('.results-count').then(($elt) => {
  48. resultsCount = parseInt($elt.text().match(/(\d+) \w+/gi))
  49. // switch to list mode
  50. cy.get('button').contains('Liste').click()
  51. // number of results shall be the same
  52. cy.get('.results-count')
  53. .invoke('text')
  54. .should('match', new RegExp('' + resultsCount + / \w+/.source, 'gi'))
  55. })
  56. })
  57. it('The results shall be paginated', () => {
  58. // 8 results are displayed (a whole page)
  59. cy.get('.structure-card')
  60. .should('have.length', 8)
  61. // 8 pages are displayed in the pagination bar (max authorized)
  62. cy.get('.v-pagination')
  63. .find('button')
  64. .filter((_, elt) => { return elt && elt.innerText.match(/\d+/) })
  65. .should('have.length.gte', 2)
  66. // Filter everything (there should be 0 results after that)
  67. cy.getByLabel('input', 'Quoi ?').type('some long text that will hopefully match no result')
  68. cy.get('button').contains('Rechercher').click()
  69. // Without any results, only page 1 is displayed
  70. cy.get('.v-pagination')
  71. .find('button')
  72. .filter((_, elt) => { return elt && elt.innerText.match(/\d+/) })
  73. .should('have.length', 1)
  74. })
  75. it('The number of results shall match the current search', () => {
  76. // extract the number of results, it should be greater than 0
  77. let resultsCount
  78. cy.get('.results-count').then(($elt) => {
  79. resultsCount = parseInt($elt.text().match(/(\d+) \w+/gi))
  80. expect(resultsCount).to.be.gt(0)
  81. })
  82. cy.getByLabel('input', 'Quoi ?').type('some long text that will hopefully match no result')
  83. cy.get('button').contains('Rechercher').click()
  84. cy.get('.results-count').invoke('text').should('match', /0 \w+/gi)
  85. })
  86. it('The results shall be filtered according to the text filter', () => {
  87. cy.getByLabel('input', 'Quoi ?').type('tambour')
  88. cy.get('button').contains('Rechercher').click()
  89. cy.get('.structure-card .title')
  90. .invoke('text')
  91. .then((s) => { return s.toLowerCase() })
  92. .should('match', /.*tambour.*/m)
  93. })
  94. it('The results shall be filtered according to the location filter', () => {
  95. cy.getByLabel('input:visible', 'Où ?').type('strasbourg')
  96. cy.get('.v-list-item__title').contains(/Strasbourg \(\d{5}\)/).click()
  97. cy.get('button').contains('Rechercher').click()
  98. // we check that there is not a postal code that is not like '67xxx'
  99. // note: we're forced to make this negative assertion, because some structures
  100. // could have no postal code displayed. So we consider the test passed if
  101. // there is no postal code that would'nt have a 6 in first position
  102. // and a 7 in second position
  103. cy.get('.structure-card .postalCode')
  104. .should('not.match', /.*[012345789]\d{4}.*/)
  105. .and('not.match', /.*\d[012345789]\d{3}.*/)
  106. })
  107. it('The results shall be filtered according to the practice filter', () => {
  108. cy.getByLabel('input:visible', 'Type').click()
  109. cy.get('.v-list-item__title').contains('Big band').click()
  110. cy.get('button').contains('Rechercher').click()
  111. cy.get('.structure-card').should('contain.text', 'Big band')
  112. })
  113. it('The results shall be filtered according to the department filter', () => {
  114. cy.getByLabel('input:visible', 'Département').click()
  115. cy.get('.v-list-item__title').contains('01 - Ain').click()
  116. cy.get('button').contains('Rechercher').click()
  117. // we check that there is not a postal code that is not like '01xxx' (@see note from location filter test)
  118. cy.get('.structure-card .postalCode')
  119. .should('not.match', /.*[123456789]\d{4}.*/)
  120. .and('not.match', /.*\d[023456789]\d{3}.*/)
  121. })
  122. it('The results shall be filtered according to the federation filter', () => {
  123. cy.getByLabel('input:visible', 'Fédération').click()
  124. cy.get('.v-list-item__title').contains('CONFÉDÉRATION MUSICALE DE FRANCE').click()
  125. cy.get('button').contains('Rechercher').click()
  126. // I don't know how to test this...
  127. cy.get('.structure-card').should('have.length.gte', 1)
  128. })
  129. it('The results shall be filtered according to the map bounds', () => {
  130. // dragging the map there should lead in the middle of the atlantic, where we have no clients (for now)
  131. cy.get('#map', { timeout: 6000 })
  132. .dragMapFromCenter({ xMoveFactor: 2, yMoveFactor: 0 })
  133. cy.get('.structure-card')
  134. .should('have.length', 0)
  135. })
  136. it('Reinitialize shall clear each filter field, display all results, and reset map bounds (in both map and list view)', () => {
  137. cy.getByLabel('input', 'Quoi ?').type('some long text that will hopefully match no result')
  138. cy.getByLabel('input:visible', 'Où ?').type('vesoul')
  139. cy.get('.v-list-item div').contains(/Vesoul \(\d{5}\)/).click()
  140. cy.getByLabel('input:visible', 'Type').click()
  141. cy.get('.v-list-item').contains('Big band').click()
  142. cy.getByLabel('input:visible', 'Département').click()
  143. cy.get('.v-list-item').contains('01 - Ain').click()
  144. cy.getByLabel('input:visible', 'Fédération').click()
  145. cy.get('.v-list-item').contains('CONFÉDÉRATION MUSICALE DE FRANCE').click()
  146. cy.getByLabel('.v-select__selections', 'Distance').click()
  147. cy.get('.v-list-item').contains('10km').click()
  148. // no structure will match these criterias
  149. cy.get('button').contains('Rechercher').click()
  150. cy.get('.structure-card')
  151. .should('have.length', 0)
  152. cy.contains('Réinitialiser').click()
  153. cy.getByLabel('input', 'Quoi ?').should('not.have.value', 'foo')
  154. cy.getByLabel('input:visible', 'Où ?').should('not.have.value', 'bar')
  155. cy.getByLabel('input:visible', 'Type').should('not.have.value', 'Big band')
  156. cy.getByLabel('input:visible', 'Département').should('not.have.value', '01 - Ain')
  157. cy.getByLabel('input:visible', 'Fédération').should('not.have.value', 'CONFÉDÉRATION MUSICALE DE FRANCE')
  158. cy.getByLabel('input:visible', 'Distance').should('not.have.value', '10km')
  159. cy.get('.structure-card')
  160. .should('have.length.gt', 0)
  161. })
  162. it('The see-more button of a structure card shall lead to the details page of the structure', () => {
  163. cy.get('.structure-card').contains('Voir plus').click()
  164. cy.url().should('match', /.*structures\/\d+/)
  165. })
  166. })