-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GSOC-E2E: Add collections lifecycle test #4248
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
Geethegreat
wants to merge
6
commits into
processing:develop
Choose a base branch
from
Geethegreat:collections-flow
base: develop
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.
+269
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e984630
Add collections lifecycle test
Geethegreat 9113f0b
split collections test into per-action tests, add plural sketch-count…
Geethegreat 51054e9
use getByRole/getByText selectors, replace transient toast assertions
Geethegreat 71e4857
unify collections.spec.ts selectors to prefer getByRole
Geethegreat 19ce9ae
use getByRole where accessible name allows it
Geethegreat aa1b199
Merge branch 'develop' into collections-flow
clairep94 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,269 @@ | ||
| import type { Page } from '@playwright/test'; | ||
| import { test, expect } from '../fixtures'; | ||
| import { dismissCookieBanner } from '../helpers/cookie-banner'; | ||
| import { createTestUser, TestUser, loginAs } from '../helpers/auth'; | ||
|
|
||
| test.describe.serial('collection lifecycle', () => { | ||
| let testUser: TestUser; | ||
| let page: Page; | ||
| let sketchName1: string; | ||
| let sketchName2: string; | ||
| let collectionName: string; | ||
|
|
||
| test.beforeAll(async ({ browser, request }) => { | ||
| testUser = await createTestUser(request); | ||
|
|
||
| // A single page shared across this describe.serial block (instead of the | ||
| // per-test `page` fixture) so each test below can build on the previous | ||
| // one's state (same sketch/collection, still logged in). | ||
| page = await browser.newPage(); | ||
| await page.addInitScript(() => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| (window as any).__REDUX_DEVTOOLS_EXTENSION__ = () => {}; | ||
| }); | ||
|
|
||
| await page.goto('/login'); | ||
| await dismissCookieBanner(page); | ||
| await loginAs(page, testUser); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await page.close(); | ||
| }); | ||
|
|
||
| test('can create a collection', async () => { | ||
| // Save the initial sketch | ||
| const editor = page.locator('.editor-holder'); | ||
| await editor.click(); | ||
|
|
||
| await page.keyboard.press('Control+S'); | ||
| await expect(page.getByText('Sketch saved.')).toBeVisible({ | ||
| timeout: 10_000 | ||
| }); | ||
|
|
||
| // Get the sketch name. ProjectName.jsx gives this button a static | ||
| // "Edit sketch name" aria-label (unlike the collection name editor, | ||
| // which uses the dynamic default), so we search by that and read the | ||
| // sketch name from its text content instead. | ||
| const name = await page | ||
| .getByRole('button', { name: 'Edit sketch name' }) | ||
| .textContent(); | ||
| expect(name).toBeTruthy(); | ||
| sketchName1 = name ?? ''; | ||
|
|
||
| // Open the collections page | ||
| await page.getByRole('menuitem', { name: testUser.username }).click(); | ||
| await page.getByRole('menuitem', { name: 'My Collections' }).click(); | ||
|
|
||
| await expect(page.getByText('No Collections.')).toBeVisible({ | ||
| timeout: 5_000 | ||
| }); | ||
|
|
||
| // Create a new collection | ||
| await page | ||
| .getByRole('button', { name: 'Create collection', exact: true }) | ||
| .click(); | ||
|
|
||
| collectionName = await page | ||
| .getByRole('textbox', { name: 'name' }) | ||
| .inputValue(); | ||
| // The form's submit button has the same accessible name as the toolbar | ||
| // button that opened it (still present behind the overlay), so the role | ||
| // query is scoped to the form itself to disambiguate. | ||
| await page | ||
| .locator('form') | ||
| .getByRole('button', { name: 'Create collection', exact: true }) | ||
| .click(); | ||
|
|
||
| // Confirm we're on the new collection page | ||
| await expect( | ||
| page.getByRole('button', { name: collectionName }) | ||
| ).toBeVisible({ timeout: 10_000 }); | ||
| await expect(page.getByText('No sketches in collection')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('can add sketches to a collection', async () => { | ||
| await page.getByRole('button', { name: 'Add Sketch', exact: true }).click(); | ||
|
|
||
| await expect(page.getByText(sketchName1)).toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| await page | ||
| .getByRole('button', { name: 'Add to collection', exact: true }) | ||
| .first() | ||
| .click(); | ||
|
|
||
| await page | ||
| .getByRole('button', { name: 'Close Add Sketch overlay' }) | ||
| .click(); | ||
|
|
||
| // Confirm the sketch is in the collection | ||
| const sketchesTable = page.getByRole('table'); | ||
| await expect( | ||
| sketchesTable.getByRole('link', { name: sketchName1 }) | ||
| ).toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| await sketchesTable.getByRole('link', { name: sketchName1 }).click(); | ||
|
|
||
| // Create a new sketch to add to the collection | ||
| await expect(page.locator('.editor-holder')).toBeVisible({ | ||
| timeout: 5_000 | ||
| }); | ||
|
|
||
| await page.getByRole('menuitem', { name: 'File' }).click(); | ||
| await page.getByRole('menuitem', { name: 'New' }).click(); | ||
|
|
||
| const editor = page.locator('.editor-holder'); | ||
| await editor.click(); | ||
|
|
||
| await page.keyboard.press('Control+S'); | ||
| await expect(page.getByText('Sketch saved.')).toBeVisible({ | ||
| timeout: 10_000 | ||
| }); | ||
|
|
||
| const name = await page | ||
| .getByRole('button', { name: 'Edit sketch name' }) | ||
| .textContent(); | ||
| expect(name).toBeTruthy(); | ||
| sketchName2 = name ?? ''; | ||
|
|
||
| // Add the new sketch to the collection | ||
| await page.getByRole('menuitem', { name: 'File' }).click(); | ||
| await page | ||
| .getByRole('menuitem', { name: 'Add to Collection', exact: true }) | ||
| .click(); | ||
|
|
||
| await expect(page.getByText(collectionName)).toBeVisible({ | ||
| timeout: 5_000 | ||
| }); | ||
|
|
||
| await page | ||
| .getByRole('button', { name: 'Add to collection', exact: true }) | ||
| .first() | ||
| .click(); | ||
|
|
||
| // The item's toggle flips to "Remove from collection" once the add lands. | ||
| // Asserting on that rather than the toast, which only shows for 1500ms. | ||
| await expect( | ||
| page.getByRole('button', { name: 'Remove from collection', exact: true }) | ||
| ).toBeVisible({ timeout: 10_000 }); | ||
|
|
||
| // Close the overlay | ||
| await page | ||
| .getByRole('button', { name: 'Close Add to collection overlay' }) | ||
| .click(); | ||
|
|
||
| await page.getByRole('menuitem', { name: testUser.username }).click(); | ||
| await page.getByRole('menuitem', { name: 'My Collections' }).click(); | ||
|
|
||
| // Verify the collection has 2 sketches | ||
| await expect( | ||
| page.getByRole('row', { name: collectionName }).getByRole('cell').nth(2) | ||
| ).toHaveText('2'); | ||
| }); | ||
|
|
||
| test('can rename a collection', async () => { | ||
| // Open the dropdown | ||
| await page | ||
| .getByRole('button', { name: 'Toggle Open/Close collection options' }) | ||
| .first() | ||
| .click(); | ||
|
|
||
| // Click Rename | ||
| await page.getByRole('menuitem').filter({ hasText: 'Rename' }).click(); | ||
|
|
||
| // The collection name becomes an input — fill it. No aria-label on this | ||
| // one, so it's scoped to the table to disambiguate from the page's | ||
| // "Search collections..." textbox. | ||
| const renameInput = page.getByRole('table').getByRole('textbox'); | ||
| await renameInput.click(); | ||
| await renameInput.fill('renamed-collection'); | ||
| await renameInput.press('Enter'); | ||
|
|
||
| collectionName = 'renamed-collection'; | ||
|
|
||
| // Verify the new name appears | ||
| await expect(page.getByRole('link', { name: collectionName })).toBeVisible({ | ||
| timeout: 5_000 | ||
| }); | ||
|
|
||
| await page.getByRole('link', { name: collectionName }).click(); | ||
|
|
||
| // Both sketches should still be in the collection after the rename | ||
| const sketchesTable = page.getByRole('table'); | ||
| await expect( | ||
| sketchesTable.getByRole('link', { name: sketchName1 }) | ||
| ).toBeVisible({ timeout: 5_000 }); | ||
| await expect( | ||
| sketchesTable.getByRole('link', { name: sketchName2 }) | ||
| ).toBeVisible({ timeout: 5_000 }); | ||
| await expect(page.getByText('2 sketches')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('can remove a sketch from a collection', async () => { | ||
| await page.getByRole('link', { name: sketchName1 }).click(); | ||
|
|
||
| // Confirm we're back in the editor and the sketch is loaded | ||
| await expect(page.locator('.editor-holder')).toBeVisible({ | ||
| timeout: 5_000 | ||
| }); | ||
| await expect( | ||
| page.getByRole('button', { name: 'Edit sketch name' }) | ||
| ).toHaveText(sketchName1, { timeout: 5_000 }); | ||
|
|
||
| await page.getByRole('menuitem', { name: 'File' }).click(); | ||
| await page | ||
| .getByRole('menuitem', { name: 'Add to Collection', exact: true }) | ||
| .click(); | ||
|
|
||
| await expect(page.getByText(collectionName)).toBeVisible({ | ||
| timeout: 5_000 | ||
| }); | ||
|
|
||
| await page | ||
| .getByRole('button', { name: 'Remove from collection', exact: true }) | ||
| .first() | ||
| .click(); | ||
|
|
||
| // The toggle flips back to "Add to collection" once the removal lands. | ||
| // Asserting on that rather than the toast, which only shows for 1500ms. | ||
| await expect( | ||
| page.getByRole('button', { name: 'Add to collection', exact: true }) | ||
| ).toBeVisible({ timeout: 10_000 }); | ||
|
|
||
| // Close the overlay | ||
| await page | ||
| .getByRole('button', { name: 'Close Add to collection overlay' }) | ||
| .click(); | ||
|
|
||
| await page.getByRole('menuitem', { name: testUser.username }).click(); | ||
| await page.getByRole('menuitem', { name: 'My Collections' }).click(); | ||
|
|
||
| // sketch1 was removed but sketch2 is still in the collection | ||
| await expect( | ||
| page.getByRole('row', { name: collectionName }).getByRole('cell').nth(2) | ||
| ).toHaveText('1'); | ||
| }); | ||
|
|
||
| test('can delete a collection', async () => { | ||
| // Accept the confirmation dialog | ||
| page.on('dialog', (dialog) => dialog.accept()); | ||
|
|
||
| // Open the dropdown for the collection | ||
| await page | ||
| .getByRole('button', { name: 'Toggle Open/Close collection options' }) | ||
| .first() | ||
| .click(); | ||
|
|
||
| // Click delete | ||
| await page.getByRole('menuitem').filter({ hasText: 'Delete' }).click(); | ||
|
|
||
| // Verify collection no longer exists in the table | ||
| await expect( | ||
| page.getByRole('link', { name: collectionName }) | ||
| ).toHaveCount(0, { timeout: 5_000 }); | ||
|
|
||
| await expect(page.getByText('No collections.')).toBeVisible({ | ||
| timeout: 5_000 | ||
| }); | ||
| }); | ||
| }); |
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.
Let's unify how we do selectors on this test, you have a mixture of methods here:
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 personally prefer
page.getByRolefor readabilityI think some folks also prefer it as it tests accessibility
https://www.reddit.com/r/Playwright/comments/1m91faa/locator_or_getbyrole/