index.spec.js 7.8 KB

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