|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import type { User } from '@nextcloud/e2e-test-server' |
| 7 | +import type { Locator, Page } from '@playwright/test' |
| 8 | + |
| 9 | +import { expect } from '@playwright/test' |
| 10 | +import { saveAccountProperty } from '../utils/account-properties.ts' |
| 11 | +import { expectSelectedOption, pickSelectOption } from '../utils/select.ts' |
| 12 | + |
| 13 | +/** |
| 14 | + * Page object for the personal "Language & locale" settings section. |
| 15 | + * |
| 16 | + * Saving the language or the locale reloads the page, so the result of such a |
| 17 | + * change is asserted on the reloaded page. |
| 18 | + */ |
| 19 | +export class LanguageLocaleSettingsPage { |
| 20 | + constructor( |
| 21 | + private readonly page: Page, |
| 22 | + private readonly user: User, |
| 23 | + ) {} |
| 24 | + |
| 25 | + async open(): Promise<void> { |
| 26 | + await this.page.goto('settings/user/language-locale') |
| 27 | + await expect(this.page.getByRole('heading', { name: 'Language & locale', level: 2 })).toBeVisible() |
| 28 | + } |
| 29 | + |
| 30 | + languageSelect(): Locator { |
| 31 | + return this.page.getByRole('combobox', { name: 'Language' }) |
| 32 | + } |
| 33 | + |
| 34 | + localeSelect(): Locator { |
| 35 | + return this.page.getByRole('combobox', { name: 'Locale' }) |
| 36 | + } |
| 37 | + |
| 38 | + firstDayOfWeekSelect(): Locator { |
| 39 | + return this.page.getByRole('combobox', { name: 'First day of week' }) |
| 40 | + } |
| 41 | + |
| 42 | + /** Date and time as rendered in the currently selected locale */ |
| 43 | + localeExample(): Locator { |
| 44 | + return this.page.getByText('Example:') |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Select a language, which reloads the page in that language. |
| 49 | + * |
| 50 | + * @param language - Name of the language, as listed in the select |
| 51 | + * @param search - Search term to filter the languages with |
| 52 | + */ |
| 53 | + async selectLanguage(language: string, search: string): Promise<void> { |
| 54 | + await this.selectOption(this.languageSelect(), language, search) |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Select a locale, which reloads the page using that locale. |
| 59 | + * |
| 60 | + * @param locale - Name of the locale, as listed in the select |
| 61 | + * @param search - Search term to filter the locales with |
| 62 | + */ |
| 63 | + async selectLocale(locale: string, search: string): Promise<void> { |
| 64 | + await this.selectOption(this.localeSelect(), locale, search) |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Select the day to use as the first day of week and wait for it to be persisted. |
| 69 | + * |
| 70 | + * @param day - Name of the day, as listed in the select |
| 71 | + */ |
| 72 | + async selectFirstDayOfWeek(day: string): Promise<void> { |
| 73 | + await saveAccountProperty(this.page, this.user.password, () => pickSelectOption(this.page, this.firstDayOfWeekSelect(), day)) |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Assert the option a select currently has selected. |
| 78 | + * |
| 79 | + * @param select - The select to read, see `languageSelect` and friends |
| 80 | + * @param value - Text of the expected option |
| 81 | + */ |
| 82 | + async expectSelected(select: Locator, value: string | RegExp): Promise<void> { |
| 83 | + await expectSelectedOption(this.page, select, value) |
| 84 | + } |
| 85 | + |
| 86 | + private async selectOption(select: Locator, option: string, search?: string): Promise<void> { |
| 87 | + await pickSelectOption(this.page, select, option, search) |
| 88 | + } |
| 89 | +} |
0 commit comments