navigation-bar-settings.cy.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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] label').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] label').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"]').click()
  168. cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('not.be.visible')
  169. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  170. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  171. else if (idx === 1) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'testapp')
  172. else if (idx === 2) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  173. })
  174. })
  175. it('See the app menu order is changed', () => {
  176. cy.reload()
  177. cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
  178. if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files')
  179. else if (idx === 1) cy.wrap($el).should('have.attr', 'data-app-id', 'testapp')
  180. else if (idx === 2) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
  181. })
  182. })
  183. })
  184. describe('User theming app order list accessibility', () => {
  185. let user: User
  186. before(() => {
  187. cy.resetAdminTheming()
  188. // Create random user for this test
  189. cy.createRandomUser().then(($user) => {
  190. user = $user
  191. cy.login($user)
  192. })
  193. })
  194. after(() => {
  195. cy.deleteUser(user)
  196. })
  197. it('See the app order settings', () => {
  198. cy.visit('/settings/user/theming')
  199. cy.get('[data-cy-app-order]').scrollIntoView()
  200. cy.get('[data-cy-app-order] [data-cy-app-order-element]').should('have.length', 2)
  201. })
  202. it('click the first button', () => {
  203. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible').focus()
  204. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').click()
  205. })
  206. it('see the same app kept the focus', () => {
  207. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  208. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.have.focus')
  209. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('not.have.focus')
  210. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('have.focus')
  211. })
  212. it('click the last button', () => {
  213. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('be.visible').focus()
  214. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').click()
  215. })
  216. it('see the same app kept the focus', () => {
  217. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.have.focus')
  218. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [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="up"]').should('not.have.focus')
  220. cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('have.focus')
  221. })
  222. })
  223. describe('User theming reset app order', () => {
  224. let user: User
  225. before(() => {
  226. cy.resetAdminTheming()
  227. // Create random user for this test
  228. cy.createRandomUser().then(($user) => {
  229. user = $user
  230. cy.login($user)
  231. })
  232. })
  233. after(() => cy.deleteUser(user))
  234. it('See the app order settings', () => {
  235. cy.visit('/settings/user/theming')
  236. cy.get('.settings-section').contains('Navigation bar settings').should('exist')
  237. cy.get('[data-cy-app-order]').scrollIntoView()
  238. })
  239. it('See that the dashboard app is the first one', () => {
  240. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  241. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  242. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  243. })
  244. cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
  245. if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
  246. else cy.wrap($el).should('have.attr', 'data-app-id', 'files')
  247. })
  248. })
  249. it('See the reset button is disabled', () => {
  250. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  251. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  252. })
  253. it('Change the app order', () => {
  254. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible')
  255. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
  256. cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')
  257. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  258. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  259. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  260. })
  261. })
  262. it('See the reset button is no longer disabled', () => {
  263. cy.get('[data-test-id="btn-apporder-reset"]').scrollIntoView()
  264. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('not.have.attr', 'disabled')
  265. })
  266. it('Reset the app order', () => {
  267. cy.get('[data-test-id="btn-apporder-reset"]').click({ force: true })
  268. })
  269. it('See the app order is restored', () => {
  270. cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
  271. if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
  272. else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
  273. })
  274. })
  275. it('See the reset button is disabled again', () => {
  276. cy.get('[data-test-id="btn-apporder-reset"]').should('be.visible').and('have.attr', 'disabled')
  277. })
  278. })