navigation-bar-settings.cy.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. const admin = new User('admin', 'admin')
  8. describe('Admin theming set default apps', () => {
  9. before(function() {
  10. // Just in case previous test failed
  11. cy.resetAdminTheming()
  12. cy.login(admin)
  13. })
  14. it('See the current default app is the dashboard', () => {
  15. cy.visit('/')
  16. cy.url().should('match', /apps\/dashboard/)
  17. // Also check the top logo link
  18. cy.get('#nextcloud').click()
  19. cy.url().should('match', /apps\/dashboard/)
  20. })
  21. it('See the default app settings', () => {
  22. cy.visit('/settings/admin/theming')
  23. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  24. cy.get('[data-cy-switch-default-app]').should('exist')
  25. cy.get('[data-cy-switch-default-app]').scrollIntoView()
  26. })
  27. it('Toggle the "use custom default app" switch', () => {
  28. cy.get('[data-cy-switch-default-app] input').should('not.be.checked')
  29. cy.get('[data-cy-switch-default-app] .checkbox-content').click()
  30. cy.get('[data-cy-switch-default-app] input').should('be.checked')
  31. })
  32. it('See the default app order selector', () => {
  33. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  34. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  35. expect(appIDs).to.deep.eq(['dashboard', 'files'])
  36. })
  37. })
  38. it('Change the default app', () => {
  39. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"]').scrollIntoView()
  40. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  41. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  42. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  43. })
  44. it('See the default app is changed', () => {
  45. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  46. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  47. expect(appIDs).to.deep.eq(['files', 'dashboard'])
  48. })
  49. // Check the redirect to the default app works
  50. cy.request({ url: '/', followRedirect: false }).then((response) => {
  51. expect(response.status).to.eq(302)
  52. expect(response).to.have.property('headers')
  53. expect(response.headers.location).to.contain('/apps/files')
  54. })
  55. })
  56. it('Toggle the "use custom default app" switch back to reset the default apps', () => {
  57. cy.visit('/settings/admin/theming')
  58. cy.get('[data-cy-switch-default-app]').scrollIntoView()
  59. cy.get('[data-cy-switch-default-app] input').should('be.checked')
  60. cy.get('[data-cy-switch-default-app] .checkbox-content').click()
  61. cy.get('[data-cy-switch-default-app] input').should('be.not.checked')
  62. })
  63. it('See the default app is changed back to default', () => {
  64. // Check the redirect to the default app works
  65. cy.request({ url: '/', followRedirect: false }).then((response) => {
  66. expect(response.status).to.eq(302)
  67. expect(response).to.have.property('headers')
  68. expect(response.headers.location).to.contain('/apps/dashboard')
  69. })
  70. })
  71. })
  72. describe('User theming set app order', () => {
  73. let user: User
  74. before(() => {
  75. cy.resetAdminTheming()
  76. // Create random user for this test
  77. cy.createRandomUser().then(($user) => {
  78. user = $user
  79. cy.login($user)
  80. })
  81. })
  82. after(() => cy.deleteUser(user))
  83. it('See the app order settings', () => {
  84. cy.visit('/settings/user/theming')
  85. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  86. cy.get('[data-cy-app-order]').scrollIntoView()
  87. })
  88. it('See that the dashboard app is the first one', () => {
  89. // Check the app order settings UI
  90. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  91. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  92. expect(appIDs).to.deep.eq(['dashboard', 'files'])
  93. })
  94. // Check the top app menu order
  95. cy.get('.app-menu-main .app-menu-entry').then(elements => {
  96. const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
  97. expect(appIDs).to.deep.eq(['dashboard', 'files'])
  98. })
  99. })
  100. it('Change the app order', () => {
  101. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  102. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  103. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  104. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  105. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  106. expect(appIDs).to.deep.eq(['files', 'dashboard'])
  107. })
  108. })
  109. it('See the app menu order is changed', () => {
  110. cy.reload()
  111. cy.get('.app-menu-main .app-menu-entry').then(elements => {
  112. const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
  113. expect(appIDs).to.deep.eq(['files', 'dashboard'])
  114. })
  115. })
  116. })
  117. describe('User theming set app order with default app', () => {
  118. let user: User
  119. before(() => {
  120. cy.resetAdminTheming()
  121. // install a third app
  122. installTestApp()
  123. // set files as default app
  124. cy.runOccCommand('config:system:set --value "files" defaultapp')
  125. // Create random user for this test
  126. cy.createRandomUser().then(($user) => {
  127. user = $user
  128. cy.login($user)
  129. })
  130. })
  131. after(() => {
  132. cy.deleteUser(user)
  133. uninstallTestApp()
  134. })
  135. it('See files is the default app', () => {
  136. // Check the redirect to the default app works
  137. cy.request({ url: '/', followRedirect: false }).then((response) => {
  138. expect(response.status).to.eq(302)
  139. expect(response).to.have.property('headers')
  140. expect(response.headers.location).to.contain('/apps/files')
  141. })
  142. })
  143. it('See the app order settings: files is the first one', () => {
  144. cy.visit('/settings/user/theming')
  145. cy.get('[data-cy-app-order]').scrollIntoView()
  146. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  147. expect(elements).to.have.length(4)
  148. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  149. expect(appIDs).to.deep.eq(['files', 'dashboard', 'testapp1', 'testapp'])
  150. })
  151. })
  152. it('Can not change the default app', () => {
  153. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  154. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.be.visible')
  155. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('not.be.visible')
  156. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible')
  157. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('be.visible')
  158. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="down"]').should('not.be.visible')
  159. })
  160. it('Change the order of the other apps', () => {
  161. cy.intercept('POST', '**/apps/provisioning_api/api/v1/config/users/core/apporder').as('setAppOrder')
  162. // Move the testapp up twice, it should be the first one after files
  163. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click()
  164. cy.wait('@setAppOrder')
  165. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click()
  166. cy.wait('@setAppOrder')
  167. // Can't get up anymore, files is enforced as default app
  168. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('not.be.visible')
  169. // Check the final list order
  170. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  171. expect(elements).to.have.length(4)
  172. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  173. expect(appIDs).to.deep.eq(['files', 'testapp', 'dashboard', 'testapp1'])
  174. })
  175. })
  176. it('See the app menu order is changed', () => {
  177. cy.reload()
  178. cy.get('.app-menu-main .app-menu-entry').then(elements => {
  179. expect(elements).to.have.length(4)
  180. const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
  181. expect(appIDs).to.deep.eq(['files', 'testapp', 'dashboard', 'testapp1'])
  182. })
  183. })
  184. })
  185. describe('User theming app order list accessibility', () => {
  186. let user: User
  187. before(() => {
  188. cy.resetAdminTheming()
  189. // Create random user for this test
  190. cy.createRandomUser().then(($user) => {
  191. user = $user
  192. cy.login($user)
  193. })
  194. })
  195. after(() => {
  196. cy.deleteUser(user)
  197. })
  198. it('See the app order settings', () => {
  199. cy.visit('/settings/user/theming')
  200. cy.get('[data-cy-app-order]').scrollIntoView()
  201. cy.get('[data-cy-app-order] [data-cy-app-order-element]').should('have.length', 2)
  202. })
  203. it('click the first button', () => {
  204. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible').focus()
  205. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').click()
  206. })
  207. it('see the same app kept the focus', () => {
  208. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  209. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.have.focus')
  210. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('not.have.focus')
  211. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('have.focus')
  212. })
  213. it('click the last button', () => {
  214. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('be.visible').focus()
  215. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').click()
  216. })
  217. it('see the same app kept the focus', () => {
  218. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  219. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.have.focus')
  220. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('not.have.focus')
  221. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('have.focus')
  222. })
  223. })
  224. describe('User theming reset app order', () => {
  225. let user: User
  226. before(() => {
  227. cy.resetAdminTheming()
  228. // Create random user for this test
  229. cy.createRandomUser().then(($user) => {
  230. user = $user
  231. cy.login($user)
  232. })
  233. })
  234. after(() => cy.deleteUser(user))
  235. it('See the app order settings', () => {
  236. cy.visit('/settings/user/theming')
  237. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  238. cy.get('[data-cy-app-order]').scrollIntoView()
  239. })
  240. it('See that the dashboard app is the first one', () => {
  241. // Check the app order settings UI
  242. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  243. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  244. expect(appIDs).to.deep.eq(['dashboard', 'files'])
  245. })
  246. // Check the top app menu order
  247. cy.get('.app-menu-main .app-menu-entry').then(elements => {
  248. const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
  249. expect(appIDs).to.deep.eq(['dashboard', 'files'])
  250. })
  251. })
  252. it('See the reset button is disabled', () => {
  253. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  254. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  255. })
  256. it('Change the app order', () => {
  257. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  258. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  259. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  260. // Check the app order settings UI
  261. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  262. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  263. expect(appIDs).to.deep.eq(['files', 'dashboard'])
  264. })
  265. })
  266. it('See the reset button is no longer disabled', () => {
  267. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  268. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('not.have.attr', 'disabled')
  269. })
  270. it('Reset the app order', () => {
  271. cy.get('[data-test-id="btn-apporder-reset"]').click({ force: true })
  272. })
  273. it('See the app order is restored', () => {
  274. cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
  275. const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
  276. expect(appIDs).to.deep.eq(['dashboard', 'files'])
  277. })
  278. })
  279. it('See the reset button is disabled again', () => {
  280. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  281. })
  282. })