user-background.cy.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. const defaultPrimary = '#006aa3'
  24. const defaultBackground = 'kamil-porembinski-clouds.jpg'
  25. import { colord } from 'colord'
  26. const validateThemingCss = function(expectedPrimary = '#0082c9', expectedBackground = 'kamil-porembinski-clouds.jpg', bright = false) {
  27. return cy.window().then((win) => {
  28. const backgroundColor = getComputedStyle(win.document.body).backgroundColor
  29. const backgroundImage = getComputedStyle(win.document.body).backgroundImage
  30. const invertIfBright = getComputedStyle(win.document.body).getPropertyValue('--background-image-invert-if-bright')
  31. // Returning boolean for cy.waitUntil usage
  32. return colord(backgroundColor).isEqual(expectedPrimary)
  33. && backgroundImage.includes(expectedBackground)
  34. && invertIfBright === (bright ? 'invert(100%)' : 'no')
  35. })
  36. }
  37. describe('User default background settings', function() {
  38. before(function() {
  39. cy.createRandomUser().then((user: User) => {
  40. cy.login(user)
  41. })
  42. })
  43. it('See the user background settings', function() {
  44. cy.visit('/settings/user/theming')
  45. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  46. })
  47. // Default cloud background is not rendered if admin theming background remains unchanged
  48. it('Default cloud background is not rendered', function() {
  49. cy.get(`[data-user-theming-background-shipped="${defaultBackground}"]`).should('not.exist')
  50. })
  51. it('Default is selected on new users', function() {
  52. cy.get('[data-user-theming-background-default]').should('be.visible')
  53. cy.get('[data-user-theming-background-default]').should('have.class', 'background--active')
  54. })
  55. })
  56. describe('User select shipped backgrounds', function() {
  57. before(function() {
  58. cy.createRandomUser().then((user: User) => {
  59. cy.login(user)
  60. })
  61. })
  62. it('See the user background settings', function() {
  63. cy.visit('/settings/user/theming')
  64. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  65. })
  66. it('Select a shipped background', function() {
  67. const background = 'anatoly-mikhaltsov-butterfly-wing-scale.jpg'
  68. cy.intercept('*/apps/theming/background/shipped').as('setBackground')
  69. // Select background
  70. cy.get(`[data-user-theming-background-shipped="${background}"]`).click()
  71. // Validate changed background and primary
  72. cy.wait('@setBackground')
  73. cy.waitUntil(() => validateThemingCss('#a53c17', background))
  74. })
  75. it('Select a bright shipped background', function() {
  76. const background = 'bernie-cetonia-aurata-take-off-composition.jpg'
  77. cy.intercept('*/apps/theming/background/shipped').as('setBackground')
  78. // Select background
  79. cy.get(`[data-user-theming-background-shipped="${background}"]`).click()
  80. // Validate changed background and primary
  81. cy.wait('@setBackground')
  82. cy.waitUntil(() => validateThemingCss('#56633d', background, true))
  83. })
  84. it('Remove background', function() {
  85. cy.intercept('*/apps/theming/background/custom').as('clearBackground')
  86. // Clear background
  87. cy.get('[data-user-theming-background-clear]').click()
  88. // Validate clear background
  89. cy.wait('@clearBackground')
  90. cy.waitUntil(() => validateThemingCss('#56633d', ''))
  91. })
  92. })
  93. describe('User select a custom color', function() {
  94. before(function() {
  95. cy.createRandomUser().then((user: User) => {
  96. cy.login(user)
  97. })
  98. })
  99. it('See the user background settings', function() {
  100. cy.visit('/settings/user/theming')
  101. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  102. })
  103. it('Select a custom color', function() {
  104. cy.intercept('*/apps/theming/background/color').as('setColor')
  105. cy.get('[data-user-theming-background-color]').click()
  106. cy.get('.color-picker__simple-color-circle:eq(3)').click()
  107. // Validate clear background
  108. cy.wait('@setColor')
  109. cy.waitUntil(() => cy.window().then((win) => {
  110. const primary = getComputedStyle(win.document.body).getPropertyValue('--color-primary')
  111. return primary !== defaultPrimary
  112. }))
  113. })
  114. })
  115. describe('User select a custom background', function() {
  116. const image = 'image.jpg'
  117. before(function() {
  118. cy.createRandomUser().then((user: User) => {
  119. cy.uploadFile(user, image, 'image/jpeg')
  120. cy.login(user)
  121. })
  122. })
  123. it('See the user background settings', function() {
  124. cy.visit('/settings/user/theming')
  125. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  126. })
  127. it('Select a custom background', function() {
  128. cy.intercept('*/apps/theming/background/custom').as('setBackground')
  129. // Pick background
  130. cy.get('[data-user-theming-background-custom]').click()
  131. cy.get(`#picker-filestable tr[data-entryname="${image}"]`).click()
  132. cy.get('#oc-dialog-filepicker-content ~ .oc-dialog-buttonrow button.primary').click()
  133. // Wait for background to be set
  134. cy.wait('@setBackground')
  135. cy.waitUntil(() => validateThemingCss('#4c0c04', 'apps/theming/background?v='))
  136. })
  137. })
  138. describe('User changes settings and reload the page', function() {
  139. const image = 'image.jpg'
  140. const primaryFromImage = '#4c0c04'
  141. let selectedColor = ''
  142. before(function() {
  143. cy.createRandomUser().then((user: User) => {
  144. cy.uploadFile(user, image, 'image/jpeg')
  145. cy.login(user)
  146. })
  147. })
  148. it('See the user background settings', function() {
  149. cy.visit('/settings/user/theming')
  150. cy.get('[data-user-theming-background-settings]').scrollIntoView().should('be.visible')
  151. })
  152. it('Select a custom background', function() {
  153. cy.intercept('*/apps/theming/background/custom').as('setBackground')
  154. // Pick background
  155. cy.get('[data-user-theming-background-custom]').click()
  156. cy.get(`#picker-filestable tr[data-entryname="${image}"]`).click()
  157. cy.get('#oc-dialog-filepicker-content ~ .oc-dialog-buttonrow button.primary').click()
  158. // Wait for background to be set
  159. cy.wait('@setBackground')
  160. cy.waitUntil(() => validateThemingCss(primaryFromImage, 'apps/theming/background?v='))
  161. })
  162. it('Select a custom color', function() {
  163. cy.intercept('*/apps/theming/background/color').as('setColor')
  164. cy.get('[data-user-theming-background-color]').click()
  165. cy.get('.color-picker__simple-color-circle:eq(5)').click()
  166. // Validate clear background
  167. cy.wait('@setColor')
  168. cy.waitUntil(() => cy.window().then((win) => {
  169. selectedColor = getComputedStyle(win.document.body).getPropertyValue('--color-primary')
  170. return selectedColor !== primaryFromImage
  171. }))
  172. })
  173. it('Reload the page and validate persistent changes', function() {
  174. cy.reload()
  175. cy.waitUntil(() => validateThemingCss(selectedColor, 'apps/theming/background?v='))
  176. })
  177. })