-
Notifications
You must be signed in to change notification settings - Fork 143
e2e: Improve setup and utils #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ntatoud
wants to merge
4
commits into
main
Choose a base branch
from
test/improve-base-for-e2e-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { test as setup } from 'e2e/utils'; | ||
| import { | ||
| ADMIN_EMAIL, | ||
| ADMIN_FILE, | ||
| USER_EMAIL, | ||
| USER_FILE, | ||
| } from 'e2e/utils/constants'; | ||
|
|
||
| /** | ||
| * @see https://playwright.dev/docs/auth#multiple-signed-in-roles | ||
| */ | ||
|
|
||
| setup('authenticate as admin', async ({ page }) => { | ||
| await page.to('/login'); | ||
| await page.login({ email: ADMIN_EMAIL }); | ||
|
|
||
| await page.waitForURL('/manager'); | ||
| await expect(page.getByTestId('layout-manager')).toBeVisible(); | ||
|
|
||
| await page.context().storageState({ path: ADMIN_FILE }); | ||
| }); | ||
|
|
||
| setup('authenticate as user', async ({ page }) => { | ||
| await page.to('/login'); | ||
| await page.login({ email: USER_EMAIL }); | ||
|
|
||
| await page.waitForURL('/app'); | ||
| await expect(page.getByTestId('layout-app')).toBeVisible(); | ||
|
|
||
| await page.context().storageState({ path: USER_FILE }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { expect, test } from 'e2e/utils'; | ||
| import { ADMIN_FILE, USER_FILE } from 'e2e/utils/constants'; | ||
| import { randomString } from 'remeda'; | ||
|
|
||
| test.describe('User management as user', () => { | ||
| test.use({ storageState: USER_FILE }); | ||
|
|
||
| test('Should not have access', async ({ page }) => { | ||
| await page.to('/manager/users'); | ||
|
|
||
| await expect( | ||
| page.getByText("You don't have access to this page") | ||
| ).toBeVisible(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('User management as manager', () => { | ||
| test.use({ storageState: ADMIN_FILE }); | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.to('/manager/users'); | ||
| }); | ||
|
|
||
| test('Create a user', async ({ page }) => { | ||
| await page.getByText('New User').click(); | ||
|
|
||
| const randomId = randomString(8); | ||
| const uniqueEmail = `new-user-${randomId}@user.com`; | ||
|
|
||
| // Fill the form | ||
| await page.waitForURL('/manager/users/new'); | ||
| await page.getByLabel('Name').fill('New user'); | ||
| await page.getByLabel('Email').fill(uniqueEmail); | ||
| await page.getByText('Create').click(); | ||
|
|
||
| await page.waitForURL('/manager/users'); | ||
| await page.getByPlaceholder('Search...').fill('new-user'); | ||
| await expect(page.getByText(uniqueEmail)).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Edit a user', async ({ page }) => { | ||
| await page.getByText('admin@admin.com').click({ | ||
| force: true, | ||
| }); | ||
|
|
||
| await page.getByRole('link', { name: 'Edit user' }).click(); | ||
|
|
||
| const randomId = randomString(8); | ||
| const newAdminName = `Admin ${randomId}`; | ||
| await page.getByLabel('Name').fill(newAdminName); | ||
| await page.getByText('Save').click(); | ||
|
|
||
| await expect(page.getByText(newAdminName).first()).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Delete a user', async ({ page }) => { | ||
| await page | ||
| .getByText('user', { | ||
| exact: true, | ||
| }) | ||
| .first() | ||
| .click({ force: true }); | ||
|
|
||
| await page.getByRole('button', { name: 'Delete' }).click(); | ||
|
|
||
| await expect( | ||
| page.getByText('You are about to permanently delete this user.') | ||
| ).toBeVisible(); | ||
|
|
||
| await page.getByRole('button', { name: 'Delete' }).click(); | ||
|
|
||
| await expect(page.getByText('User deleted')).toBeVisible(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| const AUTH_FILE_BASE = 'e2e/.auth'; | ||
|
|
||
| export const USER_FILE = `${AUTH_FILE_BASE}/user.json`; | ||
| export const USER_EMAIL = 'user@user.com'; | ||
|
|
||
| export const ADMIN_FILE = `${AUTH_FILE_BASE}/admin.json`; | ||
| export const ADMIN_EMAIL = 'admin@admin.com'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { test as base } from '@playwright/test'; | ||
| import { ExtendedPage, pageWithUtils } from 'e2e/utils/page'; | ||
|
|
||
| const test = base.extend<ExtendedPage>({ | ||
| page: pageWithUtils, | ||
| }); | ||
|
|
||
| export * from '@playwright/test'; | ||
| export { test }; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { expect, Page } from '@playwright/test'; | ||
| import { CustomFixture } from 'e2e/utils/types'; | ||
|
|
||
| import { DEFAULT_LANGUAGE_KEY } from '@/lib/i18n/constants'; | ||
|
|
||
| import { | ||
| AUTH_EMAIL_OTP_MOCKED, | ||
| AUTH_SIGNUP_ENABLED, | ||
| } from '@/features/auth/config'; | ||
| import locales from '@/locales'; | ||
| import { FileRouteTypes } from '@/routeTree.gen'; | ||
|
|
||
| interface PageUtils { | ||
| /** | ||
| * Utility used to authenticate a user on the app | ||
| */ | ||
| login: (input: { email: string; code?: string }) => Promise<void>; | ||
|
|
||
| /** | ||
| * Override of the `page.goto` method with typed routes from the app | ||
| */ | ||
| to: ( | ||
| url: FileRouteTypes['to'], | ||
| options?: Parameters<Page['goto']>[1] | ||
| ) => ReturnType<Page['goto']>; | ||
| } | ||
|
|
||
| export type ExtendedPage = { page: PageUtils }; | ||
|
|
||
| export const pageWithUtils: CustomFixture<Page & PageUtils> = async ( | ||
| { page }, | ||
| apply | ||
| ) => { | ||
| page.login = async function login(input: { email: string; code?: string }) { | ||
| const routeLogin = '/login' satisfies FileRouteTypes['to']; | ||
| const routeLoginVerify = '/login/verify' satisfies FileRouteTypes['to']; | ||
| await page.waitForURL(`**${routeLogin}**`); | ||
|
|
||
| await expect( | ||
| page.getByText( | ||
| locales[DEFAULT_LANGUAGE_KEY].auth.pageLoginWithSignUp.title | ||
| ) | ||
| ).toBeVisible(); | ||
|
|
||
| await page | ||
| .getByPlaceholder(locales[DEFAULT_LANGUAGE_KEY].auth.common.email.label) | ||
| .fill(input.email); | ||
|
|
||
| await page | ||
| .getByRole('button', { | ||
| name: locales[DEFAULT_LANGUAGE_KEY].auth[ | ||
| AUTH_SIGNUP_ENABLED ? 'pageLoginWithSignUp' : 'pageLogin' | ||
| ].loginWithEmail, | ||
| }) | ||
| .click(); | ||
|
|
||
| await page.waitForURL(`**${routeLoginVerify}**`); | ||
| await page | ||
| .getByText(locales[DEFAULT_LANGUAGE_KEY].auth.common.otp.label) | ||
| .fill(input.code ?? AUTH_EMAIL_OTP_MOCKED); | ||
| }; | ||
|
|
||
| page.to = page.goto; | ||
|
|
||
| await apply(page); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { | ||
| PlaywrightTestArgs, | ||
| PlaywrightTestOptions, | ||
| TestFixture, | ||
| } from '@playwright/test'; | ||
| import { ExtendedPage } from 'e2e/utils/page'; | ||
|
|
||
| export type CustomFixture<TReturn> = TestFixture< | ||
| TReturn, | ||
| PlaywrightTestArgs & PlaywrightTestOptions & ExtendedPage | ||
| >; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that db:init can fail here if db is not ready in the docker after dk:init 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was more of a quick workaround to get a "Clean db state" between e2e test runs when running them in local !
We should discuss what's the best path forward to have consistent e2e test runs