navigation-bar-settings.cy.ts 12 KB

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