index.spec.js 7.1 KB

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