Skip to content

Commit 2763885

Browse files
feat: add frontend test for custom custom background selection from file picker
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
1 parent c60255e commit 2763885

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

tests/playwright/e2e/theming/user-settings-background.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import { expect } from '@playwright/test'
77
import { test } from '../../support/fixtures/random-user-session.ts'
8+
import { BackgroundFilePickerDialogPage } from '../../support/sections/BackgroundFilePickerDialogPage.ts'
9+
import { mkdir, uploadContent } from '../../support/utils/dav.ts'
810
import { getBodyThemingSnapshot, pickColor } from '../../support/utils/theming.ts'
911

1012
test('User can configure background and plain color', async ({ page }) => {
@@ -32,3 +34,26 @@ test('User can configure background and plain color', async ({ page }) => {
3234
await page.reload()
3335
await expect.poll(async () => (await getBodyThemingSnapshot(page)).backgroundImage).toBe('none')
3436
})
37+
38+
test('User can pick a custom background from their files', async ({ page, user }) => {
39+
await mkdir(page.request, user, '/folder')
40+
41+
// this is a minimal image (1x1 red pixel), encoded as base64
42+
const imageBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4AWL6z8DwHwAAAP//A3ONEwAAAAZJREFUAwAFCgIByRpMngAAAABJRU5ErkJggg=='
43+
// Buffer.alloc(0) did not work when selecting image as background, using base64 image instead
44+
await uploadContent(page.request, user, Buffer.from(imageBase64, 'base64'), 'image/jpeg', '/folder/image.jpg')
45+
46+
await page.goto('settings/user/theming')
47+
await page.getByRole('heading', { name: 'Background and color' }).waitFor({ state: 'visible' })
48+
49+
await page.getByRole('button', { name: 'Custom background' }).click()
50+
51+
const filePicker = new BackgroundFilePickerDialogPage(page)
52+
await filePicker.openFolder('folder')
53+
await filePicker.selectFile('image.jpg')
54+
await filePicker.confirm()
55+
56+
await expect(page.getByRole('button', { name: 'Custom background', pressed: true })).toBeVisible()
57+
// backgroundImage is like this: "url(\"<nc-instance>/apps/theming/background?v=<hash>\")"
58+
await expect.poll(async () => (await getBodyThemingSnapshot(page)).backgroundImage).toContain('/apps/theming/background?')
59+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import type { Locator, Page } from '@playwright/test'
7+
8+
/**
9+
* The file-picker dialog opened by the "Custom background" card/button on
10+
* Personal settings > Appearance and accessibility > Background and color
11+
*/
12+
export class BackgroundFilePickerDialogPage {
13+
constructor(private readonly page: Page) {}
14+
15+
/** The open file-picker dialog. */
16+
dialog(): Locator {
17+
return this.page.getByRole('dialog')
18+
}
19+
20+
/**
21+
* Returns a row (file or folder) from inside the picker.
22+
*/
23+
getRow(name: string): Locator {
24+
return this.dialog().getByTestId('row-name').filter({ hasText: name })
25+
}
26+
27+
/** Navigate into a folder. */
28+
async openFolder(name: string): Promise<void> {
29+
await this.getRow(name).click()
30+
}
31+
32+
/** Select a file row. */
33+
async selectFile(name: string): Promise<void> {
34+
await this.getRow(name).click()
35+
}
36+
37+
/** Confirm the current selection as the new background. */
38+
async confirm(): Promise<void> {
39+
await this.dialog().getByRole('button', { name: 'Select background', exact: true }).click()
40+
}
41+
}

0 commit comments

Comments
 (0)