You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user-background.cy.ts 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 type { User } from '@nextcloud/cypress'
  23. import { pickRandomColor, validateBodyThemingCss } from './themingUtils'
  24. const defaultPrimary = '#006aa3'
  25. const defaultBackground = 'kamil-porembinski-clouds.jpg'
  26. describe('User default background settings', function() {
  27. before(function() {
  28. cy.createRandomUser().then((user: User) => {
  29. cy.login(user)
  30. })
  31. })
  32. it('See the user background settings', function() {
  33. cy.visit('/settings/user/theming')
  34. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  35. })
  36. // Default cloud background is not rendered if admin theming background remains unchanged
  37. it('Default cloud background is not rendered', function() {
  38. cy.get(`[data-user-theming-background-shipped="${defaultBackground}"]`).should('not.exist')
  39. })
  40. it('Default is selected on new users', function() {
  41. cy.get('[data-user-theming-background-default]').should('be.visible')
  42. cy.get('[data-user-theming-background-default]').should('have.class', 'background--active')
  43. })
  44. })
  45. describe('User select shipped backgrounds and remove background', function() {
  46. before(function() {
  47. cy.createRandomUser().then((user: User) => {
  48. cy.login(user)
  49. })
  50. })
  51. it('See the user background settings', function() {
  52. cy.visit('/settings/user/theming')
  53. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  54. })
  55. it('Select a shipped background', function() {
  56. const background = 'anatoly-mikhaltsov-butterfly-wing-scale.jpg'
  57. cy.intercept('*/apps/theming/background/shipped').as('setBackground')
  58. // Select background
  59. cy.get(`[data-user-theming-background-shipped="${background}"]`).click()
  60. // Validate changed background and primary
  61. cy.wait('@setBackground')
  62. cy.waitUntil(() => validateBodyThemingCss('#a53c17', background))
  63. })
  64. it('Select a bright shipped background', function() {
  65. const background = 'bernie-cetonia-aurata-take-off-composition.jpg'
  66. cy.intercept('*/apps/theming/background/shipped').as('setBackground')
  67. // Select background
  68. cy.get(`[data-user-theming-background-shipped="${background}"]`).click()
  69. // Validate changed background and primary
  70. cy.wait('@setBackground')
  71. cy.waitUntil(() => validateBodyThemingCss('#56633d', background, true))
  72. })
  73. it('Remove background', function() {
  74. cy.intercept('*/apps/theming/background/custom').as('clearBackground')
  75. // Clear background
  76. cy.get('[data-user-theming-background-clear]').click()
  77. // Validate clear background
  78. cy.wait('@clearBackground')
  79. cy.waitUntil(() => validateBodyThemingCss('#56633d', ''))
  80. })
  81. })
  82. describe('User select a custom color', function() {
  83. before(function() {
  84. cy.createRandomUser().then((user: User) => {
  85. cy.login(user)
  86. })
  87. })
  88. it('See the user background settings', function() {
  89. cy.visit('/settings/user/theming')
  90. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  91. })
  92. it('Select a custom color', function() {
  93. cy.intercept('*/apps/theming/background/color').as('setColor')
  94. pickRandomColor('[data-user-theming-background-color]')
  95. // Validate custom colour change
  96. cy.wait('@setColor')
  97. cy.waitUntil(() => cy.window().then((win) => {
  98. const primary = getComputedStyle(win.document.body).getPropertyValue('--color-primary')
  99. return primary !== defaultPrimary
  100. }))
  101. })
  102. })
  103. describe('User select a bright custom color and remove background', function() {
  104. before(function() {
  105. cy.createRandomUser().then((user: User) => {
  106. cy.login(user)
  107. })
  108. })
  109. it('See the user background settings', function() {
  110. cy.visit('/settings/user/theming')
  111. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  112. })
  113. it('Remove background', function() {
  114. cy.intercept('*/apps/theming/background/custom').as('clearBackground')
  115. // Clear background
  116. cy.get('[data-user-theming-background-clear]').click()
  117. // Validate clear background
  118. cy.wait('@clearBackground')
  119. cy.waitUntil(() => validateBodyThemingCss(undefined, ''))
  120. })
  121. it('Select a custom color', function() {
  122. cy.intercept('*/apps/theming/background/color').as('setColor')
  123. // Pick one of the bright color preset
  124. cy.get('[data-user-theming-background-color]').click()
  125. cy.get('.color-picker__simple-color-circle:eq(4)').click()
  126. // Validate custom colour change
  127. cy.wait('@setColor')
  128. })
  129. it('See the header being inverted', function() {
  130. cy.waitUntil(() => cy.window().then((win) => {
  131. const firstEntry = win.document.querySelector('.app-menu-main li')
  132. if (!firstEntry) {
  133. return false
  134. }
  135. return getComputedStyle(firstEntry).filter === 'invert(1)'
  136. }))
  137. })
  138. it('Select a shipped background', function() {
  139. const background = 'anatoly-mikhaltsov-butterfly-wing-scale.jpg'
  140. cy.intercept('*/apps/theming/background/shipped').as('setBackground')
  141. // Select background
  142. cy.get(`[data-user-theming-background-shipped="${background}"]`).click()
  143. // Validate changed background and primary
  144. cy.wait('@setBackground')
  145. cy.waitUntil(() => validateBodyThemingCss('#a53c17', background))
  146. })
  147. it('See the header NOT being inverted', function() {
  148. cy.waitUntil(() => cy.window().then((win) => {
  149. const firstEntry = win.document.querySelector('.app-menu-main li')
  150. if (!firstEntry) {
  151. return false
  152. }
  153. return getComputedStyle(firstEntry).filter === 'none'
  154. }))
  155. })
  156. })
  157. describe('User select a custom background', function() {
  158. const image = 'image.jpg'
  159. before(function() {
  160. cy.createRandomUser().then((user: User) => {
  161. cy.uploadFile(user, image, 'image/jpeg')
  162. cy.login(user)
  163. })
  164. })
  165. it('See the user background settings', function() {
  166. cy.visit('/settings/user/theming')
  167. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  168. })
  169. it('Select a custom background', function() {
  170. cy.intercept('*/apps/theming/background/custom').as('setBackground')
  171. // Pick background
  172. cy.get('[data-user-theming-background-custom]').click()
  173. cy.get(`#picker-filestable tr[data-entryname="${image}"]`).click()
  174. cy.get('#oc-dialog-filepicker-content ~ .oc-dialog-buttonrow button.primary').click()
  175. // Wait for background to be set
  176. cy.wait('@setBackground')
  177. cy.waitUntil(() => validateBodyThemingCss('#4c0c04', 'apps/theming/background?v='))
  178. })
  179. })
  180. describe('User changes settings and reload the page', function() {
  181. const image = 'image.jpg'
  182. const primaryFromImage = '#4c0c04'
  183. let selectedColor = ''
  184. before(function() {
  185. cy.createRandomUser().then((user: User) => {
  186. cy.uploadFile(user, image, 'image/jpeg')
  187. cy.login(user)
  188. })
  189. })
  190. it('See the user background settings', function() {
  191. cy.visit('/settings/user/theming')
  192. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  193. })
  194. it('Select a custom background', function() {
  195. cy.intercept('*/apps/theming/background/custom').as('setBackground')
  196. // Pick background
  197. cy.get('[data-user-theming-background-custom]').click()
  198. cy.get(`#picker-filestable tr[data-entryname="${image}"]`).click()
  199. cy.get('#oc-dialog-filepicker-content ~ .oc-dialog-buttonrow button.primary').click()
  200. // Wait for background to be set
  201. cy.wait('@setBackground')
  202. cy.waitUntil(() => validateBodyThemingCss(primaryFromImage, 'apps/theming/background?v='))
  203. })
  204. it('Select a custom color', function() {
  205. cy.intercept('*/apps/theming/background/color').as('setColor')
  206. cy.get('[data-user-theming-background-color]').click()
  207. cy.get('.color-picker__simple-color-circle:eq(5)').click()
  208. // Validate clear background
  209. cy.wait('@setColor')
  210. cy.waitUntil(() => cy.window().then((win) => {
  211. selectedColor = getComputedStyle(win.document.body).getPropertyValue('--color-primary')
  212. return selectedColor !== primaryFromImage
  213. }))
  214. })
  215. it('Reload the page and validate persistent changes', function() {
  216. cy.reload()
  217. cy.waitUntil(() => validateBodyThemingCss(selectedColor, 'apps/theming/background?v='))
  218. })
  219. })