|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { createRandomUser, login } from '@nextcloud/e2e-test-server/playwright' |
| 7 | +import { runOcc } from '@nextcloud/e2e-test-server/docker' |
| 8 | +import { expect } from '@playwright/test' |
| 9 | +import { test } from '../../support/fixtures/admin-theming-page.ts' |
| 10 | +import { resolve } from 'node:path' |
| 11 | +import { defaultBackground, defaultPrimary, getBodyThemingSnapshot, pickColor } from '../../support/utils/theming.ts' |
| 12 | + |
| 13 | +test.describe('Admin theming background settings', () => { |
| 14 | + test.describe.configure({ mode: 'serial' }) |
| 15 | + |
| 16 | + test.beforeEach(async ({ adminThemingPage, page }) => { |
| 17 | + await adminThemingPage.reset() |
| 18 | + await adminThemingPage.open() |
| 19 | + if (await adminThemingPage.disableUserThemingCheckbox().isChecked()) { |
| 20 | + await Promise.all([ |
| 21 | + page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/updateStylesheet') && response.request().method() === 'POST'), |
| 22 | + adminThemingPage.disableUserThemingCheckbox().uncheck({ force: true }), |
| 23 | + ]) |
| 24 | + } |
| 25 | + }) |
| 26 | + |
| 27 | + test('Remove default background and restore it', async ({ adminThemingPage, page, context }) => { |
| 28 | + await expect(adminThemingPage.backgroundAndColorHeading()).toBeVisible() |
| 29 | + if (await adminThemingPage.removeBackgroundImageCheckbox().isChecked()) { |
| 30 | + await Promise.all([ |
| 31 | + page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/updateStylesheet') && response.request().method() === 'POST'), |
| 32 | + adminThemingPage.removeBackgroundImageCheckbox().uncheck({ force: true }), |
| 33 | + ]) |
| 34 | + } |
| 35 | + |
| 36 | + await Promise.all([ |
| 37 | + page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/updateStylesheet') && response.request().method() === 'POST'), |
| 38 | + adminThemingPage.removeBackgroundImageCheckbox().check({ force: true }), |
| 39 | + ]) |
| 40 | + |
| 41 | + await page.goto('/index.php/logout') |
| 42 | + await page.goto('/index.php/login') |
| 43 | + await expect.poll(async () => (await getBodyThemingSnapshot(page)).backgroundImage).toBe('none') |
| 44 | + |
| 45 | + await adminThemingPage.reset() |
| 46 | + await page.goto('settings/admin/theming') |
| 47 | + await expect(adminThemingPage.backgroundAndColorHeading()).toBeVisible() |
| 48 | + }) |
| 49 | + |
| 50 | + test('Disable user theming', async ({ adminThemingPage, page, context }) => { |
| 51 | + await expect(adminThemingPage.disableUserThemingCheckbox()).not.toBeChecked() |
| 52 | + await Promise.all([ |
| 53 | + page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/updateStylesheet') && response.request().method() === 'POST'), |
| 54 | + adminThemingPage.disableUserThemingCheckbox().check({ force: true }), |
| 55 | + ]) |
| 56 | + |
| 57 | + const user = await createRandomUser() |
| 58 | + try { |
| 59 | + await login(context.request, user) |
| 60 | + await page.goto('settings/user/theming') |
| 61 | + await expect(page.getByText('Customization has been disabled by your administrator')).toBeVisible() |
| 62 | + } finally { |
| 63 | + await runOcc(['user:delete', user.userId]) |
| 64 | + } |
| 65 | + }) |
| 66 | + |
| 67 | + test('Remove default background with custom color', async ({ adminThemingPage, page, context }) => { |
| 68 | + await expect(adminThemingPage.backgroundAndColorHeading()).toBeVisible() |
| 69 | + const backgroundColorButton = page.getByRole('button', { name: /Background color/ }) |
| 70 | + const selectedColor = await pickColor(page, backgroundColorButton, 2) |
| 71 | + expect(selectedColor).toBeTruthy() |
| 72 | + |
| 73 | + await Promise.all([ |
| 74 | + page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/updateStylesheet') && response.request().method() === 'POST'), |
| 75 | + adminThemingPage.removeBackgroundImageCheckbox().check({ force: true }), |
| 76 | + ]) |
| 77 | + |
| 78 | + await page.goto('/index.php/logout') |
| 79 | + await page.goto('/index.php/login') |
| 80 | + await expect.poll(async () => (await getBodyThemingSnapshot(page)).backgroundImage).toBe('none') |
| 81 | + }) |
| 82 | + |
| 83 | + test('User default background reflects admin custom background and color', async ({ adminThemingPage, page, context }) => { |
| 84 | + const imagePath = resolve(process.cwd(), 'cypress/fixtures/image.jpg') |
| 85 | + |
| 86 | + await page.locator('input[type="file"][name="background"]').setInputFiles(imagePath) |
| 87 | + await page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/uploadImage') && response.request().method() === 'POST') |
| 88 | + |
| 89 | + const backgroundColorButton = page.getByRole('button', { name: /Background color/ }) |
| 90 | + await pickColor(page, backgroundColorButton, 1) |
| 91 | + await page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/updateStylesheet') && response.request().method() === 'POST') |
| 92 | + |
| 93 | + await page.goto('/index.php/logout') |
| 94 | + const user = await createRandomUser() |
| 95 | + try { |
| 96 | + await login(context.request, user) |
| 97 | + await page.goto('settings/user/theming') |
| 98 | + await expect(page.getByRole('button', { name: 'Default background' })).toHaveAttribute('aria-pressed', 'true') |
| 99 | + const snapshot = await getBodyThemingSnapshot(page) |
| 100 | + expect(snapshot.backgroundImage).toContain('/apps/theming/image/background?v=') |
| 101 | + } finally { |
| 102 | + await runOcc(['user:delete', user.userId]) |
| 103 | + } |
| 104 | + }) |
| 105 | + |
| 106 | + test('User default background reflects admin removed background', async ({ adminThemingPage, page, context }) => { |
| 107 | + await Promise.all([ |
| 108 | + page.waitForResponse((response) => response.url().includes('/apps/theming/ajax/updateStylesheet') && response.request().method() === 'POST'), |
| 109 | + adminThemingPage.removeBackgroundImageCheckbox().check({ force: true }), |
| 110 | + ]) |
| 111 | + |
| 112 | + await page.goto('/index.php/logout') |
| 113 | + const user = await createRandomUser() |
| 114 | + try { |
| 115 | + await login(context.request, user) |
| 116 | + await page.goto('settings/user/theming') |
| 117 | + await expect(page.getByRole('button', { name: 'Default background' })).toHaveAttribute('aria-pressed', 'true') |
| 118 | + await expect.poll(async () => (await getBodyThemingSnapshot(page)).backgroundImage).toBe('none') |
| 119 | + } finally { |
| 120 | + await runOcc(['user:delete', user.userId]) |
| 121 | + } |
| 122 | + }) |
| 123 | +}) |
0 commit comments