navigation-bar-settings.cy.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /**
  2. * @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
  3. *
  4. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { User } from '@nextcloud/cypress'
  23. import { installTestApp, uninstallTestApp } from '../../support/commonUtils'
  24. const admin = new User('admin', 'admin')
  25. describe('Admin theming set default apps', () => {
  26. before(function() {
  27. // Just in case previous test failed
  28. cy.resetAdminTheming()
  29. cy.login(admin)
  30. })
  31. it('See the current default app is the dashboard', () => {
  32. cy.visit('/')
  33. cy.url().should('match', /apps\/dashboard/)
  34. cy.get('#nextcloud').click()
  35. cy.url().should('match', /apps\/dashboard/)
  36. })
  37. it('See the default app settings', () => {
  38. cy.visit('/settings/admin/theming')
  39. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  40. cy.get('[data-cy-switch-default-app]').should('exist')
  41. cy.get('[data-cy-switch-default-app]').scrollIntoView()
  42. })
  43. it('Toggle the "use custom default app" switch', () => {
  44. cy.get('[data-cy-switch-default-app] input').should('not.be.checked')
  45. cy.get('[data-cy-switch-default-app] .checkbox-content').click()
  46. cy.get('[data-cy-switch-default-app] input').should('be.checked')
  47. })
  48. it('See the default app order selector', () => {
  49. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  50. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  51. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  52. })
  53. })
  54. it('Change the default app', () => {
  55. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"]').scrollIntoView()
  56. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  57. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  58. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  59. })
  60. it('See the default app is changed', () => {
  61. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  62. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  63. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  64. })
  65. cy.get('#nextcloud').click()
  66. cy.url().should('match', /apps\/files/)
  67. })
  68. it('Toggle the "use custom default app" switch back to reset the default apps', () => {
  69. cy.visit('/settings/admin/theming')
  70. cy.get('[data-cy-switch-default-app]').scrollIntoView()
  71. cy.get('[data-cy-switch-default-app] input').should('be.checked')
  72. cy.get('[data-cy-switch-default-app] .checkbox-content').click()
  73. cy.get('[data-cy-switch-default-app] input').should('be.not.checked')
  74. })
  75. it('See the default app is changed back to default', () => {
  76. cy.reload()
  77. cy.get('#nextcloud').click()
  78. cy.url().should('match', /apps\/dashboard/)
  79. })
  80. })
  81. describe('User theming set app order', () => {
  82. let user: User
  83. before(() => {
  84. cy.resetAdminTheming()
  85. // Create random user for this test
  86. cy.createRandomUser().then(($user) => {
  87. user = $user
  88. cy.login($user)
  89. })
  90. })
  91. after(() => cy.deleteUser(user))
  92. it('See the app order settings', () => {
  93. cy.visit('/settings/user/theming')
  94. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  95. cy.get('[data-cy-app-order]').scrollIntoView()
  96. })
  97. it('See that the dashboard app is the first one', () => {
  98. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  99. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  100. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  101. })
  102. cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
  103. if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
  104. else cy.wrap($el).should('have.attr', 'data-app-id', 'files')
  105. })
  106. })
  107. it('Change the app order', () => {
  108. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  109. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  110. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  111. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  112. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  113. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  114. })
  115. })
  116. it('See the app menu order is changed', () => {
  117. cy.reload()
  118. cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
  119. if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files')
  120. else cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
  121. })
  122. })
  123. })
  124. describe('User theming set app order with default app', () => {
  125. let user: User
  126. before(() => {
  127. cy.resetAdminTheming()
  128. // install a third app
  129. installTestApp()
  130. // set files as default app
  131. cy.runOccCommand('config:system:set --value "files" defaultapp')
  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. uninstallTestApp()
  141. })
  142. it('See files is the default app', () => {
  143. cy.visit('/')
  144. cy.url().should('match', /apps\/files/)
  145. cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
  146. if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files')
  147. })
  148. })
  149. it('See the app order settings: files is the first one', () => {
  150. cy.visit('/settings/user/theming')
  151. cy.get('[data-cy-app-order]').scrollIntoView()
  152. cy.get('[data-cy-app-order] [data-cy-app-order-element]').should('have.length', 4).each(($el, idx) => {
  153. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  154. else if (idx === 1) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  155. })
  156. })
  157. it('Can not change the default app', () => {
  158. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  159. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.be.visible')
  160. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('not.be.visible')
  161. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible')
  162. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('be.visible')
  163. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="down"]').should('not.be.visible')
  164. })
  165. it('Change the order of the other apps', () => {
  166. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click()
  167. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('not.be.visible')
  168. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  169. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  170. else if (idx === 1) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'testapp')
  171. else if (idx === 2) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  172. })
  173. })
  174. it('See the app menu order is changed', () => {
  175. cy.reload()
  176. cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
  177. if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files')
  178. else if (idx === 1) cy.wrap($el).should('have.attr', 'data-app-id', 'testapp')
  179. else if (idx === 2) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
  180. })
  181. })
  182. })
  183. describe('User theming app order list accessibility', () => {
  184. let user: User
  185. before(() => {
  186. cy.resetAdminTheming()
  187. // Create random user for this test
  188. cy.createRandomUser().then(($user) => {
  189. user = $user
  190. cy.login($user)
  191. })
  192. })
  193. after(() => {
  194. cy.deleteUser(user)
  195. })
  196. it('See the app order settings', () => {
  197. cy.visit('/settings/user/theming')
  198. cy.get('[data-cy-app-order]').scrollIntoView()
  199. cy.get('[data-cy-app-order] [data-cy-app-order-element]').should('have.length', 2)
  200. })
  201. it('click the first button', () => {
  202. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible').focus()
  203. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').click()
  204. })
  205. it('see the same app kept the focus', () => {
  206. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  207. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.have.focus')
  208. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('not.have.focus')
  209. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('have.focus')
  210. })
  211. it('click the last button', () => {
  212. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('be.visible').focus()
  213. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').click()
  214. })
  215. it('see the same app kept the focus', () => {
  216. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  217. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.have.focus')
  218. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('not.have.focus')
  219. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('have.focus')
  220. })
  221. })
  222. describe('User theming reset app order', () => {
  223. let user: User
  224. before(() => {
  225. cy.resetAdminTheming()
  226. // Create random user for this test
  227. cy.createRandomUser().then(($user) => {
  228. user = $user
  229. cy.login($user)
  230. })
  231. })
  232. after(() => cy.deleteUser(user))
  233. it('See the app order settings', () => {
  234. cy.visit('/settings/user/theming')
  235. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  236. cy.get('[data-cy-app-order]').scrollIntoView()
  237. })
  238. it('See that the dashboard app is the first one', () => {
  239. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  240. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  241. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  242. })
  243. cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
  244. if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
  245. else cy.wrap($el).should('have.attr', 'data-app-id', 'files')
  246. })
  247. })
  248. it('See the reset button is disabled', () => {
  249. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  250. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  251. })
  252. it('Change the app order', () => {
  253. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  254. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  255. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  256. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  257. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  258. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  259. })
  260. })
  261. it('See the reset button is no longer disabled', () => {
  262. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  263. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('not.have.attr', 'disabled')
  264. })
  265. it('Reset the app order', () => {
  266. cy.get('[data-test-id="btn-apporder-reset"]').click({ force: true })
  267. })
  268. it('See the app order is restored', () => {
  269. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  270. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  271. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  272. })
  273. })
  274. it('See the reset button is disabled again', () => {
  275. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  276. })
  277. })