1
0

admin-settings.cy.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. /* eslint-disable n/no-unpublished-import */
  23. import { User } from '@nextcloud/cypress'
  24. import { colord } from 'colord'
  25. import { defaultPrimary, defaultBackground, pickRandomColor, validateBodyThemingCss, validateUserThemingDefaultCss } from './themingUtils'
  26. const admin = new User('admin', 'admin')
  27. describe('Admin theming settings visibility check', function() {
  28. before(function() {
  29. // Just in case previous test failed
  30. cy.resetAdminTheming()
  31. cy.login(admin)
  32. })
  33. it('See the admin theming section', function() {
  34. cy.visit('/settings/admin/theming')
  35. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  36. cy.get('[data-admin-theming-settings]').should('be.visible')
  37. })
  38. it('See the default settings', function() {
  39. cy.get('[data-admin-theming-setting-primary-color-picker]').should('exist')
  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 color 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]').should('exist').scrollIntoView()
  55. cy.get('[data-admin-theming-settings]').should('be.visible')
  56. })
  57. it('Change the primary color', function() {
  58. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
  59. pickRandomColor().then(color => { selectedColor = color })
  60. cy.wait('@setColor')
  61. cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
  62. })
  63. it('Screenshot the login page and validate login page', function() {
  64. cy.logout()
  65. cy.visit('/')
  66. cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
  67. cy.screenshot()
  68. })
  69. it('Undo theming settings and validate login page again', function() {
  70. cy.resetAdminTheming()
  71. cy.visit('/')
  72. cy.waitUntil(validateBodyThemingCss)
  73. cy.screenshot()
  74. })
  75. })
  76. describe('Remove the default background and restore it', function() {
  77. before(function() {
  78. // Just in case previous test failed
  79. cy.resetAdminTheming()
  80. cy.login(admin)
  81. })
  82. it('See the admin theming section', function() {
  83. cy.visit('/settings/admin/theming')
  84. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  85. cy.get('[data-admin-theming-settings]').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(() => validateBodyThemingCss(defaultPrimary, null))
  92. cy.waitUntil(() => cy.window().then((win) => {
  93. const backgroundPlain = getComputedStyle(win.document.body).getPropertyValue('--image-background-plain')
  94. return backgroundPlain !== ''
  95. }))
  96. })
  97. it('Screenshot the login page and validate login page', function() {
  98. cy.logout()
  99. cy.visit('/')
  100. cy.waitUntil(() => validateBodyThemingCss(defaultPrimary, null))
  101. cy.screenshot()
  102. })
  103. it('Undo theming settings and validate login page again', function() {
  104. cy.resetAdminTheming()
  105. cy.visit('/')
  106. cy.waitUntil(validateBodyThemingCss)
  107. cy.screenshot()
  108. })
  109. })
  110. describe('Remove the default background with a custom primary color', function() {
  111. let selectedColor = ''
  112. before(function() {
  113. // Just in case previous test failed
  114. cy.resetAdminTheming()
  115. cy.login(admin)
  116. })
  117. it('See the admin theming section', function() {
  118. cy.visit('/settings/admin/theming')
  119. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  120. cy.get('[data-admin-theming-settings]').should('be.visible')
  121. })
  122. it('Change the primary color', function() {
  123. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
  124. pickRandomColor().then(color => { selectedColor = color })
  125. cy.wait('@setColor')
  126. cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
  127. })
  128. it('Remove the default background', function() {
  129. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
  130. cy.get('[data-admin-theming-setting-file-remove]').click()
  131. cy.wait('@removeBackground')
  132. })
  133. it('Screenshot the login page and validate login page', function() {
  134. cy.logout()
  135. cy.visit('/')
  136. cy.waitUntil(() => validateBodyThemingCss(selectedColor, null))
  137. cy.screenshot()
  138. })
  139. it('Undo theming settings and validate login page again', function() {
  140. cy.resetAdminTheming()
  141. cy.visit('/')
  142. cy.waitUntil(validateBodyThemingCss)
  143. cy.screenshot()
  144. })
  145. })
  146. describe('Remove the default background with a bright color', function() {
  147. before(function() {
  148. // Just in case previous test failed
  149. cy.resetAdminTheming()
  150. cy.resetUserTheming(admin)
  151. cy.login(admin)
  152. })
  153. it('See the admin theming section', function() {
  154. cy.visit('/settings/admin/theming')
  155. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  156. cy.get('[data-admin-theming-settings]').should('be.visible')
  157. })
  158. it('Remove the default background', function() {
  159. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
  160. cy.get('[data-admin-theming-setting-file-remove]').click()
  161. cy.wait('@removeBackground')
  162. })
  163. it('Change the primary color', function() {
  164. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
  165. // Pick one of the bright color preset
  166. cy.get('[data-admin-theming-setting-primary-color-picker]').click()
  167. cy.get('.color-picker__simple-color-circle:eq(4)').click()
  168. cy.wait('@setColor')
  169. cy.waitUntil(() => validateBodyThemingCss('#ddcb55', null))
  170. })
  171. it('See the header being inverted', function() {
  172. cy.waitUntil(() => cy.window().then((win) => {
  173. const firstEntry = win.document.querySelector('.app-menu-main li img')
  174. if (!firstEntry) {
  175. return false
  176. }
  177. return getComputedStyle(firstEntry).filter === 'invert(1)'
  178. }))
  179. })
  180. })
  181. describe('Change the login fields then reset them', function() {
  182. const name = 'ABCdef123'
  183. const url = 'https://example.com'
  184. const slogan = 'Testing is fun'
  185. before(function() {
  186. // Just in case previous test failed
  187. cy.resetAdminTheming()
  188. cy.login(admin)
  189. })
  190. it('See the admin theming section', function() {
  191. cy.visit('/settings/admin/theming')
  192. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  193. cy.get('[data-admin-theming-settings]').should('be.visible')
  194. })
  195. it('Change the name field', function() {
  196. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('updateFields')
  197. // Name
  198. cy.get('[data-admin-theming-setting-field="name"] input[type="text"]')
  199. .scrollIntoView()
  200. cy.get('[data-admin-theming-setting-field="name"] input[type="text"]')
  201. .type(`{selectall}${name}{enter}`)
  202. cy.wait('@updateFields')
  203. // Url
  204. cy.get('[data-admin-theming-setting-field="url"] input[type="url"]')
  205. .scrollIntoView()
  206. cy.get('[data-admin-theming-setting-field="url"] input[type="url"]')
  207. .type(`{selectall}${url}{enter}`)
  208. cy.wait('@updateFields')
  209. // Slogan
  210. cy.get('[data-admin-theming-setting-field="slogan"] input[type="text"]')
  211. .scrollIntoView()
  212. cy.get('[data-admin-theming-setting-field="slogan"] input[type="text"]')
  213. .type(`{selectall}${slogan}{enter}`)
  214. cy.wait('@updateFields')
  215. })
  216. it('Ensure undo button presence', function() {
  217. cy.get('[data-admin-theming-setting-field="name"] .input-field__trailing-button')
  218. .scrollIntoView()
  219. cy.get('[data-admin-theming-setting-field="name"] .input-field__trailing-button')
  220. .should('be.visible')
  221. cy.get('[data-admin-theming-setting-field="url"] .input-field__trailing-button')
  222. .scrollIntoView()
  223. cy.get('[data-admin-theming-setting-field="url"] .input-field__trailing-button')
  224. .should('be.visible')
  225. cy.get('[data-admin-theming-setting-field="slogan"] .input-field__trailing-button')
  226. .scrollIntoView()
  227. cy.get('[data-admin-theming-setting-field="slogan"] .input-field__trailing-button')
  228. .should('be.visible')
  229. })
  230. it('Validate login screen changes', function() {
  231. cy.logout()
  232. cy.visit('/')
  233. cy.get('[data-login-form-headline]').should('contain.text', name)
  234. cy.get('footer p a').should('have.text', name)
  235. cy.get('footer p a').should('have.attr', 'href', url)
  236. cy.get('footer p').should('contain.text', `– ${slogan}`)
  237. })
  238. it('Undo theming settings', function() {
  239. cy.resetAdminTheming()
  240. })
  241. it('Validate login screen changes again', function() {
  242. cy.visit('/')
  243. cy.get('[data-login-form-headline]').should('not.contain.text', name)
  244. cy.get('footer p a').should('not.have.text', name)
  245. cy.get('footer p a').should('not.have.attr', 'href', url)
  246. cy.get('footer p').should('not.contain.text', `– ${slogan}`)
  247. })
  248. })
  249. describe('Disable user theming and enable it back', function() {
  250. before(function() {
  251. // Just in case previous test failed
  252. cy.resetAdminTheming()
  253. cy.login(admin)
  254. })
  255. it('See the admin theming section', function() {
  256. cy.visit('/settings/admin/theming')
  257. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  258. cy.get('[data-admin-theming-settings]').should('be.visible')
  259. })
  260. it('Disable user background theming', function() {
  261. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('disableUserTheming')
  262. cy.get('[data-admin-theming-setting-disable-user-theming]')
  263. .scrollIntoView()
  264. cy.get('[data-admin-theming-setting-disable-user-theming]')
  265. .should('be.visible')
  266. cy.get('[data-admin-theming-setting-disable-user-theming] input[type="checkbox"]').check({ force: true })
  267. cy.get('[data-admin-theming-setting-disable-user-theming] input[type="checkbox"]').should('be.checked')
  268. cy.wait('@disableUserTheming')
  269. })
  270. it('Login as user', function() {
  271. cy.logout()
  272. cy.createRandomUser().then((user) => {
  273. cy.login(user)
  274. })
  275. })
  276. it('User cannot not change background settings', function() {
  277. cy.visit('/settings/user/theming')
  278. cy.get('[data-user-theming-background-disabled]').scrollIntoView()
  279. cy.get('[data-user-theming-background-disabled]').should('be.visible')
  280. })
  281. })
  282. describe('The user default background settings reflect the admin theming settings', function() {
  283. let selectedColor = ''
  284. before(function() {
  285. // Just in case previous test failed
  286. cy.resetAdminTheming()
  287. cy.login(admin)
  288. })
  289. after(function() {
  290. cy.resetAdminTheming()
  291. })
  292. it('See the admin theming section', function() {
  293. cy.visit('/settings/admin/theming')
  294. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  295. cy.get('[data-admin-theming-settings]').should('be.visible')
  296. })
  297. it('Change the primary color', function() {
  298. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
  299. pickRandomColor().then(color => { selectedColor = color })
  300. cy.wait('@setColor')
  301. cy.waitUntil(() => cy.window().then(($window) => {
  302. const primary = $window.getComputedStyle($window.document.body).getPropertyValue('--color-primary-default')
  303. return colord(primary).isEqual(selectedColor)
  304. }))
  305. })
  306. it('Change the default background', function() {
  307. cy.intercept('*/apps/theming/ajax/uploadImage').as('setBackground')
  308. cy.fixture('image.jpg', null).as('background')
  309. cy.get('[data-admin-theming-setting-file="background"] input[type="file"]').selectFile('@background', { force: true })
  310. cy.wait('@setBackground')
  311. cy.waitUntil(() => cy.window().then((win) => {
  312. const currentBackgroundDefault = getComputedStyle(win.document.body).getPropertyValue('--image-background-default')
  313. return currentBackgroundDefault.includes('/apps/theming/image/background?v=')
  314. }))
  315. })
  316. it('Login page should match admin theming settings', function() {
  317. cy.logout()
  318. cy.visit('/')
  319. cy.waitUntil(() => validateBodyThemingCss(selectedColor, '/apps/theming/image/background?v='))
  320. })
  321. it('Login as user', function() {
  322. cy.createRandomUser().then((user) => {
  323. cy.login(user)
  324. })
  325. })
  326. it('See the user background settings', function() {
  327. cy.visit('/settings/user/theming')
  328. cy.get('[data-user-theming-background-settings]').scrollIntoView()
  329. cy.get('[data-user-theming-background-settings]').should('be.visible')
  330. })
  331. it('Default user background settings should match admin theming settings', function() {
  332. cy.get('[data-user-theming-background-default]').should('be.visible')
  333. cy.get('[data-user-theming-background-default]').should('have.class', 'background--active')
  334. cy.waitUntil(() => validateUserThemingDefaultCss(selectedColor, '/apps/theming/image/background?v='))
  335. })
  336. })
  337. describe('The user default background settings reflect the admin theming settings with background removed', function() {
  338. before(function() {
  339. // Just in case previous test failed
  340. cy.resetAdminTheming()
  341. cy.login(admin)
  342. })
  343. after(function() {
  344. cy.resetAdminTheming()
  345. })
  346. it('See the admin theming section', function() {
  347. cy.visit('/settings/admin/theming')
  348. cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
  349. cy.get('[data-admin-theming-settings]').should('be.visible')
  350. })
  351. it('Remove the default background', function() {
  352. cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
  353. cy.get('[data-admin-theming-setting-file-remove]').click()
  354. cy.wait('@removeBackground')
  355. cy.waitUntil(() => validateBodyThemingCss(defaultPrimary, null))
  356. })
  357. it('Login page should match admin theming settings', function() {
  358. cy.logout()
  359. cy.visit('/')
  360. cy.waitUntil(() => validateBodyThemingCss(defaultPrimary, null))
  361. })
  362. it('Login as user', function() {
  363. cy.createRandomUser().then((user) => {
  364. cy.login(user)
  365. })
  366. })
  367. it('See the user background settings', function() {
  368. cy.visit('/settings/user/theming')
  369. cy.get('[data-user-theming-background-settings]').scrollIntoView()
  370. cy.get('[data-user-theming-background-settings]').should('be.visible')
  371. })
  372. it('Default user background settings should match admin theming settings', function() {
  373. cy.get('[data-user-theming-background-default]').should('be.visible')
  374. cy.get('[data-user-theming-background-default]').should('have.class', 'background--active')
  375. cy.waitUntil(() => validateUserThemingDefaultCss(defaultPrimary, null))
  376. })
  377. })