選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

admin-settings.cy.ts 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /**
  2. * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  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 { colord } from 'colord'
  24. import { pickRandomColor, validateBodyThemingCss, validateUserThemingDefaultCss } from './themingUtils'
  25. const admin = new User('admin', 'admin')
  26. const defaultPrimary = '#0082c9'
  27. const defaultBackground = 'kamil-porembinski-clouds.jpg'
  28. describe('Admin theming settings', function() {
  29. before(function() {
  30. // Just in case previous test failed
  31. cy.resetAdminTheming()
  32. cy.login(admin)
  33. })
  34. it('See the admin theming section', function() {
  35. cy.visit('/settings/admin/theming')
  36. cy.get('[data-admin-theming-settings]').scrollIntoView().should('be.visible')
  37. })
  38. it('See the default settings', function() {
  39. cy.get('[data-admin-theming-setting-primary-color-picker]').should('contain.text', defaultPrimary)
  40. cy.get('[data-admin-theming-setting-primary-color-reset]').should('not.exist')
  41. cy.get('[data-admin-theming-setting-file-reset]').should('not.exist')
  42. cy.get('[data-admin-theming-setting-file-remove]').should('be.visible')
  43. })
  44. })
  45. describe('Change the primary colour and reset it', function() {
  46. let selectedColor = ''
  47. before(function() {
  48. // Just in case previous test failed
  49. cy.resetAdminTheming()
  50. cy.login(admin)
  51. })
  52. it('See the admin theming section', function() {
  53. cy.visit('/settings/admin/theming')
  54. cy.get('[data-admin-theming-settings]').scrollIntoView().should('be.visible')
  55. })
  56. it('Change the primary colour', function() {
  57. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
  58. pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
  59. .then(color => selectedColor = color)
  60. cy.wait('@setColor')
  61. cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
  62. })
  63. it('Screenshot the login page', function() {
  64. cy.logout()
  65. cy.visit('/')
  66. cy.screenshot()
  67. })
  68. it('Undo theming settings', function() {
  69. cy.resetAdminTheming()
  70. })
  71. it('Screenshot the login page', function() {
  72. cy.visit('/')
  73. cy.waitUntil(validateBodyThemingCss)
  74. cy.screenshot()
  75. })
  76. })
  77. describe('Remove the default background and restore it', function() {
  78. before(function() {
  79. // Just in case previous test failed
  80. cy.resetAdminTheming()
  81. cy.login(admin)
  82. })
  83. it('See the admin theming section', function() {
  84. cy.visit('/settings/admin/theming')
  85. cy.get('[data-admin-theming-settings]').scrollIntoView().should('be.visible')
  86. })
  87. it('Remove the default background', function() {
  88. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
  89. cy.get('[data-admin-theming-setting-file-remove]').click()
  90. cy.wait('@removeBackground')
  91. cy.waitUntil(() => cy.window().then((win) => {
  92. const currentBackgroundDefault = getComputedStyle(win.document.body).getPropertyValue('--image-background-default')
  93. const backgroundPlain = getComputedStyle(win.document.body).getPropertyValue('--image-background-plain')
  94. return !currentBackgroundDefault.includes(defaultBackground)
  95. && backgroundPlain !== ''
  96. }))
  97. })
  98. it('Screenshot the login page', function() {
  99. cy.logout()
  100. cy.visit('/')
  101. cy.screenshot()
  102. })
  103. it('Undo theming settings', function() {
  104. cy.resetAdminTheming()
  105. })
  106. it('Screenshot the login page', function() {
  107. cy.visit('/')
  108. cy.waitUntil(validateBodyThemingCss)
  109. cy.screenshot()
  110. })
  111. })
  112. describe.only('Remove the default background with a bright color', function() {
  113. before(function() {
  114. // Just in case previous test failed
  115. cy.resetAdminTheming()
  116. cy.resetUserTheming(admin)
  117. cy.login(admin)
  118. })
  119. it('See the admin theming section', function() {
  120. cy.visit('/settings/admin/theming')
  121. cy.get('[data-admin-theming-settings]').scrollIntoView().should('be.visible')
  122. })
  123. it('Remove the default background', function() {
  124. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
  125. cy.get('[data-admin-theming-setting-file-remove]').click()
  126. cy.wait('@removeBackground')
  127. })
  128. it('Change the primary colour', function() {
  129. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
  130. // Pick one of the bright color preset
  131. cy.get('[data-admin-theming-setting-primary-color-picker]').click()
  132. cy.get('.color-picker__simple-color-circle:eq(4)').click()
  133. cy.wait('@setColor')
  134. cy.waitUntil(() => validateBodyThemingCss('#ddcb55', ''))
  135. })
  136. it('See the header being inverted', function() {
  137. cy.waitUntil(() => cy.window().then((win) => {
  138. const firstEntry = win.document.querySelector('.app-menu-main li')
  139. if (!firstEntry) {
  140. return false
  141. }
  142. return getComputedStyle(firstEntry).filter === 'invert(1)'
  143. }))
  144. })
  145. })
  146. describe('Change the login fields then reset them', function() {
  147. const name = 'ABCdef123'
  148. const url = 'https://example.com'
  149. const slogan = 'Testing is fun'
  150. before(function() {
  151. // Just in case previous test failed
  152. cy.resetAdminTheming()
  153. cy.login(admin)
  154. })
  155. it('See the admin theming section', function() {
  156. cy.visit('/settings/admin/theming')
  157. cy.get('[data-admin-theming-settings]').scrollIntoView().should('be.visible')
  158. })
  159. it('Change the name field', function() {
  160. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('updateFields')
  161. // Name
  162. cy.get('[data-admin-theming-setting-field="name"] input[type="text"]')
  163. .scrollIntoView()
  164. .type('{selectall}')
  165. .type(name)
  166. .type('{enter}')
  167. cy.wait('@updateFields')
  168. // Url
  169. cy.get('[data-admin-theming-setting-field="url"] input[type="url"]')
  170. .scrollIntoView()
  171. .type('{selectall}')
  172. .type(url)
  173. .type('{enter}')
  174. cy.wait('@updateFields')
  175. // Slogan
  176. cy.get('[data-admin-theming-setting-field="slogan"] input[type="text"]')
  177. .scrollIntoView()
  178. .type('{selectall}')
  179. .type(slogan)
  180. .type('{enter}')
  181. cy.wait('@updateFields')
  182. })
  183. it('Ensure undo button presence', function() {
  184. cy.get('[data-admin-theming-setting-field="name"] .input-field__clear-button')
  185. .scrollIntoView().should('be.visible')
  186. cy.get('[data-admin-theming-setting-field="url"] .input-field__clear-button')
  187. .scrollIntoView().should('be.visible')
  188. cy.get('[data-admin-theming-setting-field="slogan"] .input-field__clear-button')
  189. .scrollIntoView().should('be.visible')
  190. })
  191. it('Check login screen changes', function() {
  192. cy.logout()
  193. cy.visit('/')
  194. cy.get('[data-login-form-headline]').should('contain.text', name)
  195. cy.get('footer p a').should('have.text', name)
  196. cy.get('footer p a').should('have.attr', 'href', url)
  197. cy.get('footer p').should('contain.text', `– ${slogan}`)
  198. })
  199. it('Undo theming settings', function() {
  200. cy.resetAdminTheming()
  201. })
  202. it('Check login screen changes', function() {
  203. cy.visit('/')
  204. cy.get('[data-login-form-headline]').should('not.contain.text', name)
  205. cy.get('footer p a').should('not.have.text', name)
  206. cy.get('footer p a').should('not.have.attr', 'href', url)
  207. cy.get('footer p').should('not.contain.text', `– ${slogan}`)
  208. })
  209. })
  210. describe('Disable user theming and enable it back', function() {
  211. before(function() {
  212. // Just in case previous test failed
  213. cy.resetAdminTheming()
  214. cy.login(admin)
  215. })
  216. it('See the admin theming section', function() {
  217. cy.visit('/settings/admin/theming')
  218. cy.get('[data-admin-theming-settings]').scrollIntoView().should('be.visible')
  219. })
  220. it('Disable user theming', function() {
  221. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('disableUserTheming')
  222. cy.get('[data-admin-theming-setting-disable-user-theming]')
  223. .scrollIntoView().should('be.visible')
  224. cy.get('[data-admin-theming-setting-disable-user-theming] input[type="checkbox"]').check({ force: true })
  225. cy.get('[data-admin-theming-setting-disable-user-theming] input[type="checkbox"]').should('be.checked')
  226. cy.wait('@disableUserTheming')
  227. })
  228. it('Login as user', function() {
  229. cy.logout()
  230. cy.createRandomUser().then((user) => {
  231. cy.login(user)
  232. })
  233. })
  234. it('See the user disabled background settings', function() {
  235. cy.visit('/settings/user/theming')
  236. cy.get('[data-user-theming-background-disabled]').scrollIntoView().should('be.visible')
  237. })
  238. })
  239. describe('User default option matches admin theming', function() {
  240. let selectedColor = ''
  241. before(function() {
  242. // Just in case previous test failed
  243. cy.resetAdminTheming()
  244. cy.login(admin)
  245. })
  246. after(function() {
  247. cy.resetAdminTheming()
  248. })
  249. it('See the admin theming section', function() {
  250. cy.visit('/settings/admin/theming')
  251. cy.get('[data-admin-theming-settings]').scrollIntoView().should('be.visible')
  252. })
  253. it('Change the primary colour', function() {
  254. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
  255. pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
  256. .then(color => selectedColor = color)
  257. cy.wait('@setColor')
  258. cy.waitUntil(() => cy.window().then((win) => {
  259. const primary = getComputedStyle(win.document.body).getPropertyValue('--color-primary-default')
  260. return colord(primary).isEqual(selectedColor)
  261. }))
  262. })
  263. it('Change the default background', function() {
  264. cy.intercept('*/apps/theming/ajax/uploadImage').as('setBackground')
  265. cy.fixture('image.jpg', null).as('background')
  266. cy.get('[data-admin-theming-setting-file="background"] input[type="file"]').selectFile('@background', { force: true })
  267. cy.wait('@setBackground')
  268. cy.waitUntil(() => cy.window().then((win) => {
  269. const currentBackgroundDefault = getComputedStyle(win.document.body).getPropertyValue('--image-background-default')
  270. return currentBackgroundDefault.includes('/apps/theming/image/background?v=')
  271. }))
  272. })
  273. it('Logout and check changes', function() {
  274. cy.logout()
  275. cy.visit('/')
  276. cy.waitUntil(() => validateBodyThemingCss(selectedColor, '/apps/theming/image/background?v='))
  277. })
  278. it('Login as user', function() {
  279. cy.createRandomUser().then((user) => {
  280. cy.login(user)
  281. })
  282. })
  283. it('See the user background settings', function() {
  284. cy.visit('/settings/user/theming')
  285. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  286. })
  287. it('See the default background option selected', function() {
  288. cy.get('[data-user-theming-background-default]').should('be.visible')
  289. cy.get('[data-user-theming-background-default]').should('have.class', 'background--active')
  290. cy.waitUntil(() => validateUserThemingDefaultCss(selectedColor, '/apps/theming/image/background?v='))
  291. })
  292. })