-
-
Notifications
You must be signed in to change notification settings - Fork 173
Add e2e my-posts page tests for delete interactions #1209
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
Changes from 1 commit
6cd0e80
f85a64d
66e7450
b5817df
30d566f
e33431b
7cae3fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,27 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Page } from "@playwright/test"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import test, { expect } from "@playwright/test"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { articleExcerpt, loggedInAsUserOne } from "./utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function openPublishedTab(page: Page) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await page.goto("http://localhost:3000/my-posts"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await page.getByRole("link", { name: "Published" }).click(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await expect(page).toHaveURL(/\/my-posts\?tab=published$/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function openDeleteModal(page: Page) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await page.getByRole("button", { name: "Options" }).click(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const optionsDiv = page.locator( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "div[aria-labelledby='headlessui-menu-button-:r5:']", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await expect(optionsDiv).toBeVisible(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deleteButton = optionsDiv.locator("text=Delete"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await deleteButton.click(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const confirmationDiv = page.getByText( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Are you sure you want to delete this article?", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await expect(confirmationDiv).toBeVisible(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function openDeleteModal(page: Page) { | |
| await page.getByRole("button", { name: "Options" }).click(); | |
| const optionsDiv = page.locator( | |
| "div[aria-labelledby='headlessui-menu-button-:r5:']", | |
| ); | |
| await expect(optionsDiv).toBeVisible(); | |
| const deleteButton = optionsDiv.locator("text=Delete"); | |
| await deleteButton.click(); | |
| const confirmationDiv = page.getByText( | |
| "Are you sure you want to delete this article?", | |
| ); | |
| await expect(confirmationDiv).toBeVisible(); | |
| } | |
| const SELECTORS = { | |
| OPTIONS_MENU: '[role="menu"]', | |
| DELETE_CONFIRMATION: 'div[role="dialog"]' | |
| }; | |
| const TEXT = { | |
| DELETE_CONFIRMATION: 'Are you sure you want to delete this article?' | |
| }; | |
| async function openDeleteModal(page: Page) { | |
| await page.getByRole("button", { name: "Options" }).click(); | |
| const optionsDiv = page.locator(SELECTORS.OPTIONS_MENU); | |
| await expect(optionsDiv).toBeVisible(); | |
| const deleteButton = optionsDiv.locator("text=Delete"); | |
| await deleteButton.click(); | |
| const confirmationDiv = page.locator(SELECTORS.DELETE_CONFIRMATION); | |
| await expect(confirmationDiv).toBeVisible({ timeout: 5000 }); | |
| await expect(confirmationDiv).toHaveText(TEXT.DELETE_CONFIRMATION); | |
| } |
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.
this might create flakiness if there is a delay in clicking the button and the url being updated with the published tab query.
we can add something like
await page.waitForURL('url pattern');then assert the url
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.
Thank you for this, @pkspyder007; this is added, too.