123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- /**
- * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- /* eslint-disable n/no-unpublished-import */
- import { User } from '@nextcloud/cypress'
- import { colord } from 'colord'
- import { defaultPrimary, defaultBackground, pickRandomColor, validateBodyThemingCss, validateUserThemingDefaultCss } from './themingUtils'
- const admin = new User('admin', 'admin')
- describe('Admin theming settings visibility check', function() {
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('See the default settings', function() {
- cy.get('[data-admin-theming-setting-primary-color-picker]').should('contain.text', defaultPrimary)
- cy.get('[data-admin-theming-setting-primary-color-reset]').should('not.exist')
- cy.get('[data-admin-theming-setting-file-reset]').should('not.exist')
- cy.get('[data-admin-theming-setting-file-remove]').should('be.visible')
- })
- })
- describe('Change the primary color and reset it', function() {
- let selectedColor = ''
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Change the primary color', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
- pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
- .then(color => { selectedColor = color })
- cy.wait('@setColor')
- cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
- })
- it('Screenshot the login page and validate login page', function() {
- cy.logout()
- cy.visit('/')
- cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
- cy.screenshot()
- })
- it('Undo theming settings and validate login page again', function() {
- cy.resetAdminTheming()
- cy.visit('/')
- cy.waitUntil(validateBodyThemingCss)
- cy.screenshot()
- })
- })
- describe('Remove the default background and restore it', function() {
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Remove the default background', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
- cy.get('[data-admin-theming-setting-file-remove]').click()
- cy.wait('@removeBackground')
- cy.waitUntil(() => validateBodyThemingCss(defaultPrimary, null))
- cy.waitUntil(() => cy.window().then((win) => {
- const backgroundPlain = getComputedStyle(win.document.body).getPropertyValue('--image-background-plain')
- return backgroundPlain !== ''
- }))
- })
- it('Screenshot the login page and validate login page', function() {
- cy.logout()
- cy.visit('/')
- cy.waitUntil(() => validateBodyThemingCss(defaultPrimary, null))
- cy.screenshot()
- })
- it('Undo theming settings and validate login page again', function() {
- cy.resetAdminTheming()
- cy.visit('/')
- cy.waitUntil(validateBodyThemingCss)
- cy.screenshot()
- })
- })
- describe('Remove the default background with a custom primary color', function() {
- let selectedColor = ''
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Change the primary color', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
- pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
- .then((color) => { selectedColor = color })
- cy.wait('@setColor')
- cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
- })
- it('Remove the default background', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
- cy.get('[data-admin-theming-setting-file-remove]').click()
- cy.wait('@removeBackground')
- })
- it('Screenshot the login page and validate login page', function() {
- cy.logout()
- cy.visit('/')
- cy.waitUntil(() => validateBodyThemingCss(selectedColor, null))
- cy.screenshot()
- })
- it('Undo theming settings and validate login page again', function() {
- cy.resetAdminTheming()
- cy.visit('/')
- cy.waitUntil(validateBodyThemingCss)
- cy.screenshot()
- })
- })
- describe('Remove the default background with a bright color', function() {
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.resetUserTheming(admin)
- cy.login(admin)
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Remove the default background', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
- cy.get('[data-admin-theming-setting-file-remove]').click()
- cy.wait('@removeBackground')
- })
- it('Change the primary color', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
- // Pick one of the bright color preset
- cy.get('[data-admin-theming-setting-primary-color-picker]').click()
- cy.get('.color-picker__simple-color-circle:eq(4)').click()
- cy.wait('@setColor')
- cy.waitUntil(() => validateBodyThemingCss('#ddcb55', null))
- })
- it('See the header being inverted', function() {
- cy.waitUntil(() => cy.window().then((win) => {
- const firstEntry = win.document.querySelector('.app-menu-main li img')
- if (!firstEntry) {
- return false
- }
- return getComputedStyle(firstEntry).filter === 'invert(1)'
- }))
- })
- })
- describe('Change the login fields then reset them', function() {
- const name = 'ABCdef123'
- const url = 'https://example.com'
- const slogan = 'Testing is fun'
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Change the name field', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('updateFields')
- // Name
- cy.get('[data-admin-theming-setting-field="name"] input[type="text"]')
- .scrollIntoView()
- cy.get('[data-admin-theming-setting-field="name"] input[type="text"]')
- .type(`{selectall}${name}{enter}`)
- cy.wait('@updateFields')
- // Url
- cy.get('[data-admin-theming-setting-field="url"] input[type="url"]')
- .scrollIntoView()
- cy.get('[data-admin-theming-setting-field="url"] input[type="url"]')
- .type(`{selectall}${url}{enter}`)
- cy.wait('@updateFields')
- // Slogan
- cy.get('[data-admin-theming-setting-field="slogan"] input[type="text"]')
- .scrollIntoView()
- cy.get('[data-admin-theming-setting-field="slogan"] input[type="text"]')
- .type(`{selectall}${slogan}{enter}`)
- cy.wait('@updateFields')
- })
- it('Ensure undo button presence', function() {
- cy.get('[data-admin-theming-setting-field="name"] .input-field__trailing-button')
- .scrollIntoView()
- cy.get('[data-admin-theming-setting-field="name"] .input-field__trailing-button')
- .should('be.visible')
- cy.get('[data-admin-theming-setting-field="url"] .input-field__trailing-button')
- .scrollIntoView()
- cy.get('[data-admin-theming-setting-field="url"] .input-field__trailing-button')
- .should('be.visible')
- cy.get('[data-admin-theming-setting-field="slogan"] .input-field__trailing-button')
- .scrollIntoView()
- cy.get('[data-admin-theming-setting-field="slogan"] .input-field__trailing-button')
- .should('be.visible')
- })
- it('Validate login screen changes', function() {
- cy.logout()
- cy.visit('/')
- cy.get('[data-login-form-headline]').should('contain.text', name)
- cy.get('footer p a').should('have.text', name)
- cy.get('footer p a').should('have.attr', 'href', url)
- cy.get('footer p').should('contain.text', `– ${slogan}`)
- })
- it('Undo theming settings', function() {
- cy.resetAdminTheming()
- })
- it('Validate login screen changes again', function() {
- cy.visit('/')
- cy.get('[data-login-form-headline]').should('not.contain.text', name)
- cy.get('footer p a').should('not.have.text', name)
- cy.get('footer p a').should('not.have.attr', 'href', url)
- cy.get('footer p').should('not.contain.text', `– ${slogan}`)
- })
- })
- describe('Disable user theming and enable it back', function() {
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Disable user background theming', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('disableUserTheming')
- cy.get('[data-admin-theming-setting-disable-user-theming]')
- .scrollIntoView()
- cy.get('[data-admin-theming-setting-disable-user-theming]')
- .should('be.visible')
- cy.get('[data-admin-theming-setting-disable-user-theming] input[type="checkbox"]').check({ force: true })
- cy.get('[data-admin-theming-setting-disable-user-theming] input[type="checkbox"]').should('be.checked')
- cy.wait('@disableUserTheming')
- })
- it('Login as user', function() {
- cy.logout()
- cy.createRandomUser().then((user) => {
- cy.login(user)
- })
- })
- it('User cannot not change background settings', function() {
- cy.visit('/settings/user/theming')
- cy.get('[data-user-theming-background-disabled]').scrollIntoView()
- cy.get('[data-user-theming-background-disabled]').should('be.visible')
- })
- })
- describe('The user default background settings reflect the admin theming settings', function() {
- let selectedColor = ''
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- after(function() {
- cy.resetAdminTheming()
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Change the primary color', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')
- pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
- .then(color => { selectedColor = color })
- cy.wait('@setColor')
- cy.waitUntil(() => cy.window().then(($window) => {
- const primary = $window.getComputedStyle($window.document.body).getPropertyValue('--color-primary-default')
- return colord(primary).isEqual(selectedColor)
- }))
- })
- it('Change the default background', function() {
- cy.intercept('*/apps/theming/ajax/uploadImage').as('setBackground')
- cy.fixture('image.jpg', null).as('background')
- cy.get('[data-admin-theming-setting-file="background"] input[type="file"]').selectFile('@background', { force: true })
- cy.wait('@setBackground')
- cy.waitUntil(() => cy.window().then((win) => {
- const currentBackgroundDefault = getComputedStyle(win.document.body).getPropertyValue('--image-background-default')
- return currentBackgroundDefault.includes('/apps/theming/image/background?v=')
- }))
- })
- it('Login page should match admin theming settings', function() {
- cy.logout()
- cy.visit('/')
- cy.waitUntil(() => validateBodyThemingCss(selectedColor, '/apps/theming/image/background?v='))
- })
- it('Login as user', function() {
- cy.createRandomUser().then((user) => {
- cy.login(user)
- })
- })
- it('See the user background settings', function() {
- cy.visit('/settings/user/theming')
- cy.get('[data-user-theming-background-settings]').scrollIntoView()
- cy.get('[data-user-theming-background-settings]').should('be.visible')
- })
- it('Default user background settings should match admin theming settings', function() {
- cy.get('[data-user-theming-background-default]').should('be.visible')
- cy.get('[data-user-theming-background-default]').should('have.class', 'background--active')
- cy.waitUntil(() => validateUserThemingDefaultCss(selectedColor, '/apps/theming/image/background?v='))
- })
- })
- describe('The user default background settings reflect the admin theming settings with background removed', function() {
- before(function() {
- // Just in case previous test failed
- cy.resetAdminTheming()
- cy.login(admin)
- })
- after(function() {
- cy.resetAdminTheming()
- })
- it('See the admin theming section', function() {
- cy.visit('/settings/admin/theming')
- cy.get('[data-admin-theming-settings]').should('exist').scrollIntoView()
- cy.get('[data-admin-theming-settings]').should('be.visible')
- })
- it('Remove the default background', function() {
- cy.intercept('*/apps/theming/ajax/updateStylesheet').as('removeBackground')
- cy.get('[data-admin-theming-setting-file-remove]').click()
- cy.wait('@removeBackground')
- cy.waitUntil(() => validateBodyThemingCss(defaultPrimary, null))
- })
- it('Login page should match admin theming settings', function() {
- cy.logout()
- cy.visit('/')
- cy.waitUntil(() => validateBodyThemingCss(defaultPrimary, null))
- })
- it('Login as user', function() {
- cy.createRandomUser().then((user) => {
- cy.login(user)
- })
- })
- it('See the user background settings', function() {
- cy.visit('/settings/user/theming')
- cy.get('[data-user-theming-background-settings]').scrollIntoView()
- cy.get('[data-user-theming-background-settings]').should('be.visible')
- })
- it('Default user background settings should match admin theming settings', function() {
- cy.get('[data-user-theming-background-default]').should('be.visible')
- cy.get('[data-user-theming-background-default]').should('have.class', 'background--active')
- cy.waitUntil(() => validateUserThemingDefaultCss(defaultPrimary, null))
- })
- })
|