1
0

user-settings_app-order.cy.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /**
  2. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { User } from '@nextcloud/cypress'
  6. import { installTestApp, uninstallTestApp } from '../../support/commonUtils'
  7. import { NavigationHeader } from '../../pages/NavigationHeader'
  8. /**
  9. * Intercept setting the app order as `updateAppOrder`
  10. */
  11. function interceptAppOrder() {
  12. cy.intercept('POST', '/ocs/v2.php/apps/provisioning_api/api/v1/config/users/core/apporder').as('updateAppOrder')
  13. }
  14. before(() => uninstallTestApp())
  15. describe('User theming set app order', () => {
  16. const navigationHeader = new NavigationHeader()
  17. let user: User
  18. before(() => {
  19. cy.resetAdminTheming()
  20. // Create random user for this test
  21. cy.createRandomUser().then(($user) => {
  22. user = $user
  23. cy.login($user)
  24. })
  25. })
  26. after(() => cy.deleteUser(user))
  27. it('See the app order settings', () => {
  28. cy.visit('/settings/user/theming')
  29. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  30. cy.get('[data-cy-app-order]').scrollIntoView()
  31. })
  32. it('See that the dashboard app is the first one', () => {
  33. const appOrder = ['Dashboard', 'Files']
  34. // Check the app order settings UI
  35. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  36. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  37. // Check the top app menu order
  38. navigationHeader.getNavigationEntries()
  39. .each((entry, index) => expect(entry).contain.text(appOrder[index]))
  40. })
  41. it('Change the app order', () => {
  42. interceptAppOrder()
  43. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  44. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  45. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  46. cy.wait('@updateAppOrder')
  47. const appOrder = ['Files', 'Dashboard']
  48. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  49. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  50. })
  51. it('See the app menu order is changed', () => {
  52. cy.reload()
  53. const appOrder = ['Files', 'Dashboard']
  54. // Check the app order settings UI
  55. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  56. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  57. // Check the top app menu order
  58. navigationHeader.getNavigationEntries()
  59. .each((entry, index) => expect(entry).contain.text(appOrder[index]))
  60. })
  61. })
  62. describe('User theming set app order with default app', () => {
  63. const navigationHeader = new NavigationHeader()
  64. let user: User
  65. before(() => {
  66. cy.resetAdminTheming()
  67. // install a third app
  68. installTestApp()
  69. // set files as default app
  70. cy.runOccCommand('config:system:set --value "files" defaultapp')
  71. // Create random user for this test
  72. cy.createRandomUser().then(($user) => {
  73. user = $user
  74. cy.login($user)
  75. })
  76. })
  77. after(() => {
  78. cy.deleteUser(user)
  79. uninstallTestApp()
  80. })
  81. it('See files is the default app', () => {
  82. // Check the redirect to the default app works
  83. cy.request({ url: '/', followRedirect: false }).then((response) => {
  84. expect(response.status).to.eq(302)
  85. expect(response).to.have.property('headers')
  86. expect(response.headers.location).to.contain('/apps/files')
  87. })
  88. })
  89. it('See the app order settings: files is the first one', () => {
  90. cy.visit('/settings/user/theming')
  91. cy.get('[data-cy-app-order]').scrollIntoView()
  92. const appOrder = ['Files', 'Dashboard', 'Test App 2', 'Test App']
  93. // Check the app order settings UI
  94. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  95. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  96. })
  97. it('Can not change the default app', () => {
  98. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  99. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.be.visible')
  100. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('not.be.visible')
  101. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible')
  102. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('be.visible')
  103. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="down"]').should('not.be.visible')
  104. })
  105. it('Change the order of the other apps', () => {
  106. interceptAppOrder()
  107. // Move the testapp up twice, it should be the first one after files
  108. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click()
  109. cy.wait('@updateAppOrder')
  110. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click()
  111. cy.wait('@updateAppOrder')
  112. // Can't get up anymore, files is enforced as default app
  113. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('not.be.visible')
  114. // Check the final list order
  115. const appOrder = ['Files', 'Test App', 'Dashboard', 'Test App 2']
  116. // Check the app order settings UI
  117. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  118. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  119. })
  120. it('See the app menu order is changed', () => {
  121. cy.reload()
  122. const appOrder = ['Files', 'Test App', 'Dashboard', 'Test App 2']
  123. // Check the top app menu order
  124. navigationHeader.getNavigationEntries()
  125. .each((entry, index) => expect(entry).contain.text(appOrder[index]))
  126. })
  127. })
  128. describe('User theming app order list accessibility', () => {
  129. let user: User
  130. before(() => {
  131. cy.resetAdminTheming()
  132. // Create random user for this test
  133. cy.createRandomUser().then(($user) => {
  134. user = $user
  135. cy.login($user)
  136. })
  137. })
  138. after(() => {
  139. cy.deleteUser(user)
  140. })
  141. it('See the app order settings', () => {
  142. cy.visit('/settings/user/theming')
  143. cy.get('[data-cy-app-order]').scrollIntoView()
  144. cy.get('[data-cy-app-order] [data-cy-app-order-element]').should('have.length', 2)
  145. })
  146. it('click the first button', () => {
  147. interceptAppOrder()
  148. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible').focus()
  149. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').click()
  150. cy.wait('@updateAppOrder')
  151. })
  152. it('see the same app kept the focus', () => {
  153. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  154. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.have.focus')
  155. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('not.have.focus')
  156. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('have.focus')
  157. })
  158. it('click the last button', () => {
  159. interceptAppOrder()
  160. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('be.visible').focus()
  161. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').click()
  162. cy.wait('@updateAppOrder')
  163. })
  164. it('see the same app kept the focus', () => {
  165. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  166. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.have.focus')
  167. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('not.have.focus')
  168. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('have.focus')
  169. })
  170. })
  171. describe('User theming reset app order', () => {
  172. const navigationHeader = new NavigationHeader()
  173. let user: User
  174. before(() => {
  175. cy.resetAdminTheming()
  176. // Create random user for this test
  177. cy.createRandomUser().then(($user) => {
  178. user = $user
  179. cy.login($user)
  180. })
  181. })
  182. after(() => cy.deleteUser(user))
  183. it('See the app order settings', () => {
  184. cy.visit('/settings/user/theming')
  185. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  186. cy.get('[data-cy-app-order]').scrollIntoView()
  187. })
  188. it('See that the dashboard app is the first one', () => {
  189. const appOrder = ['Dashboard', 'Files']
  190. // Check the app order settings UI
  191. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  192. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  193. // Check the top app menu order
  194. navigationHeader.getNavigationEntries()
  195. .each((entry, index) => expect(entry).contain.text(appOrder[index]))
  196. })
  197. it('See the reset button is disabled', () => {
  198. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  199. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  200. })
  201. it('Change the app order', () => {
  202. interceptAppOrder()
  203. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  204. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  205. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  206. cy.wait('@updateAppOrder')
  207. // Check the app order settings UI
  208. const appOrder = ['Files', 'Dashboard']
  209. // Check the app order settings UI
  210. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  211. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  212. })
  213. it('See the reset button is no longer disabled', () => {
  214. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  215. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('not.have.attr', 'disabled')
  216. })
  217. it('Reset the app order', () => {
  218. cy.intercept('GET', '/ocs/v2.php/core/navigation/apps').as('loadApps')
  219. interceptAppOrder()
  220. cy.get('[data-test-id="btn-apporder-reset"]').click({ force: true })
  221. cy.wait('@updateAppOrder')
  222. .its('request.body')
  223. .should('have.property', 'configValue', '[]')
  224. cy.wait('@loadApps')
  225. })
  226. it('See the app order is restored', () => {
  227. const appOrder = ['Dashboard', 'Files']
  228. // Check the app order settings UI
  229. cy.get('[data-cy-app-order] [data-cy-app-order-element]')
  230. .each((element, index) => expect(element).to.contain.text(appOrder[index]))
  231. // Check the top app menu order
  232. navigationHeader.getNavigationEntries()
  233. .each((entry, index) => expect(entry).contain.text(appOrder[index]))
  234. })
  235. it('See the reset button is disabled again', () => {
  236. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  237. })
  238. })