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 5.6KB

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