Skip to content
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

Playwright test - users spec for /pro/users #13434

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/playwright/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export const ENDPOINTS = {
preview: "/pro/purchase/preview*",
stripePaymentMethod : "https://api.stripe.com/v1/payment_methods",
};

export const getRandomEmail = () =>
`playwright-test-${Math.random().toString(36).substring(2,12)}@canonical.com`;
65 changes: 65 additions & 0 deletions tests/playwright/tests/pro/users.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { test, expect } from "@playwright/test";
import { acceptCookiePolicy, login } from "../../helpers/commands";
import { getRandomEmail } from "../../helpers/utils";

test.describe("/pro/users", () => {
const email = getRandomEmail();

test("It should add and delete a user correctly", async ({ page }) => {
await page.goto("/pro/users");
await login(page);
await acceptCookiePolicy(page);

await page.getByRole("button", { name: /Add new user/ }).click();
await page.getByLabel("Name").fill("Angela");
await page.getByLabel("email address").fill(email);
await page
.getByLabel("Role", { exact: true })
.selectOption({ label: "Technical" });

await page.route("/pro/accounts/*", async (route) => {
const request = route.request();
const postData = await request.postDataJSON();

if (request.method() === "POST") {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ email: postData.email, role: postData.role }),
});
} else if (request.method() === "DELETE") {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ email: postData.email }),
});
}
});

await page
.getByRole("button", { name: "Add new user", exact: true })
.click();

await page.waitForTimeout(3000);

await expect(page.getByText(/User added successfully/)).toBeVisible();

await page.getByPlaceholder("Search for users").fill(email);

await expect(page.getByText(email)).toBeVisible();

await page.getByLabel(`Edit user ${email}`).click();

await page.locator("button[aria-label='delete']").click();

await page.getByRole("button", { name: "Yes, remove user" }).click();

await page.waitForTimeout(3000);

await expect(page.getByText(/User deleted/)).toBeVisible();

await page.getByPlaceholder("Search for users").fill(email);

await expect(page.getByText(email)).not.toBeVisible();
});
});
Loading