Skip to content

Commit

Permalink
test: port e2e test code from #10207
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Mar 4, 2024
1 parent 38f10ce commit 45a6ed6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/cucumber/features/smoke/languageChange.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Feature: language settings
| resource | recipient | type | role |
| check_message | Alice | user | Can edit |
And "Brian" logs out

And "Alice" logs in
And "Alice" opens the user menu
And "Alice" changes the language to "Deutsch - German"
Then "Alice" should see the following account page title "Konto"
When "Alice" logs out
And "Alice" logs in
Then "Alice" should see the following notifications
Expand Down
13 changes: 12 additions & 1 deletion tests/e2e/cucumber/steps/ui/accountMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ When(
async function (this: World, stepUser: string, language: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const accountObject = new objects.account.Account({ page })
const expectedLanguage = await accountObject.changeLanguage(language)
const isAnonymousUser = stepUser === 'Anonymous'
const expectedLanguage = await accountObject.changeLanguage(language, isAnonymousUser)
expect(expectedLanguage).toBe(language)
}
)

Then(
'{string} should see the following account page title {string}',
async function (this: World, stepUser: string, title: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const accountObject = new objects.account.Account({ page })
const pageTitle = await accountObject.getTitle()
expect(pageTitle).toEqual(title)
}
)
40 changes: 29 additions & 11 deletions tests/e2e/support/objects/account/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const downloadExportButton = '[data-testid="download-export-btn"]'
const languageInput = '[data-testid="language"] .vs__search'
const languageValueDropDown = `.vs__dropdown-menu :text-is("%s")`
const languageValue = '[data-testid="language"] .vs__selected'
const accountPageTitle = '#account-page-title'

export const getQuotaValue = async (args: { page: Page }): Promise<string> => {
const { page } = args
Expand Down Expand Up @@ -79,18 +80,35 @@ export const downloadGdprExport = async (args: { page: Page }): Promise<string>
return download.suggestedFilename()
}

export const changeLanguage = async (args: { page: Page; language: string }): Promise<string> => {
const { page, language } = args
export const changeLanguage = async (args: {
page: Page
language: string
isAnonymousUser: boolean
}): Promise<string> => {
const { page, language, isAnonymousUser } = args
await page.locator(languageInput).waitFor()
await page.locator(languageInput).click()
await page.locator(languageInput).pressSequentially(language)
await Promise.all([
page.waitForResponse(
(res) =>
res.url().includes('graph/v1.0/me') &&
res.request().method() === 'PATCH' &&
res.status() === 200
),
page.locator(util.format(languageValueDropDown, language)).press('Enter')
])
const promises = []

if (!isAnonymousUser) {
promises.push(
page.waitForResponse(
(res) =>
res.url().includes('graph/v1.0/me') &&
res.request().method() === 'PATCH' &&
res.status() === 200
)
)
}

promises.push(page.locator(util.format(languageValueDropDown, language)).press('Enter'))
await Promise.all(promises)

return (await page.locator(languageValue).textContent()).trim()
}

export const getTitle = async (args: { page: Page }): Promise<string> => {
const { page } = args
return page.locator(accountPageTitle).textContent()
}
8 changes: 6 additions & 2 deletions tests/e2e/support/objects/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export class Account {
return po.downloadGdprExport({ page: this.#page })
}

changeLanguage(language): Promise<string> {
return po.changeLanguage({ page: this.#page, language })
changeLanguage(language, isAnonymousUser = false): Promise<string> {
return po.changeLanguage({ page: this.#page, language, isAnonymousUser })
}

getTitle(): Promise<string> {
return po.getTitle({ page: this.#page })
}
}

0 comments on commit 45a6ed6

Please sign in to comment.