index.spec.js 7.2 KB

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