-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: e2e test for actions #1831
Conversation
Thank you for following the naming conventions for pull request titles! 🙏 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
apps/web/playwright/action.spec.ts
Create Issue const createNoCodeAction = async (
page: Page,
email: string,
password: string,
name: string,
description: string,
actionType: string,
actionValue: string
) => {
await login(page, email, password);
await page.getByRole("link", { name: "Actions & Attributes" }).click();
await page.getByRole("button", { name: "Add Action" }).click();
await expect(page.getByLabel("What did your user do?")).toBeVisible();
await page.getByLabel("What did your user do?").fill(name);
await expect(page.getByLabel("Description")).toBeVisible();
await page.getByLabel("Description").fill(description);
await expect(page.locator(`#${actionType}`)).toBeVisible();
await page.locator(`#${actionType}`).click();
await expect(page.locator(`[name='noCodeConfig.${actionType}.value']`)).toBeVisible();
await page.locator(`[name='noCodeConfig.${actionType}.value']`).fill(actionValue);
await page.getByRole("button", { name: "Track Action", exact: true }).click();
};
Create Issue const WHAT_DID_YOUR_USER_DO = "What did your user do?";
const DESCRIPTION = "Description";
const TRACK_ACTION = "Track Action";
// ... rest of your code
|
apps/web/playwright/action.spec.ts
Outdated
await page.getByLabel("What did your user do?").fill(name); | ||
|
||
await expect(page.getByLabel("Description")).toBeVisible(); | ||
await page.getByLabel("Description").fill(description); | ||
|
||
// User toggles the CSS Selector action type | ||
|
||
await expect(page.locator("#CssSelector")).toBeVisible(); | ||
await page.locator("#CssSelector").click(); | ||
|
||
// User fills the CSS Selector to track | ||
await expect(page.locator("[name='noCodeConfig.cssSelector.value']")).toBeVisible(); | ||
await page.locator("[name='noCodeConfig.cssSelector.value']").fill(selector); | ||
await page.getByRole("button", { name: "Track Action", exact: true }).click(); | ||
}; | ||
|
||
const createNoCodeActionByPageURL = async ( | ||
page: Page, | ||
email: string, | ||
password: string, | ||
name: string, | ||
description: string, | ||
matcher: { | ||
label: string; | ||
value: string; | ||
}, | ||
testURL: string | ||
) => { | ||
// await signUpAndLogin(page, name, email, password); | ||
await login(page, email, password); | ||
// await skipOnboarding(page); | ||
|
||
await page.getByRole("link", { name: "Actions & Attributes" }).click(); | ||
|
||
// Add Action button | ||
await page.getByRole("button", { name: "Add Action" }).click(); | ||
|
||
// User fills the action name and description | ||
await expect(page.getByLabel("What did your user do?")).toBeVisible(); | ||
await page.getByLabel("What did your user do?").fill(name); | ||
|
||
await expect(page.getByLabel("Description")).toBeVisible(); | ||
await page.getByLabel("Description").fill(description); | ||
|
||
// User toggles the Page URL action type | ||
|
||
await expect(page.locator("#PageURL")).toBeVisible(); | ||
await page.locator("#PageURL").click(); | ||
|
||
// User opens the dropdown and selects the URL match type | ||
await expect(page.locator("[name='noCodeConfig.[pageUrl].rule']")).toBeVisible(); | ||
await page.locator("[name='noCodeConfig.[pageUrl].rule']").selectOption({ label: matcher.label }); | ||
|
||
// User fills the Page URL to track | ||
await page.locator("[name='noCodeConfig.[pageUrl].value']").fill(matcher.value); | ||
|
||
// User fills the Test URL to track | ||
await page.locator("[name='noCodeConfig.[pageUrl].testUrl']").fill(testURL); | ||
|
||
// User clicks the Test Match button | ||
await page.getByRole("button", { name: "Test Match", exact: true }).click(); | ||
|
||
// User clicks the Track Action button | ||
await page.getByRole("button", { name: "Track Action", exact: true }).click(); | ||
}; | ||
|
||
const createNoCodeActionByInnerText = async ( | ||
page: Page, | ||
email: string, | ||
password: string, | ||
name: string, | ||
description: string, | ||
innerText: string | ||
) => { | ||
// await signUpAndLogin(page, name, email, password); | ||
await login(page, email, password); | ||
// await skipOnboarding(page); | ||
|
||
await page.getByRole("link", { name: "Actions & Attributes" }).click(); | ||
|
||
// Add Action button | ||
await page.getByRole("button", { name: "Add Action" }).click(); | ||
|
||
// User fills the action name and description | ||
await expect(page.getByLabel("What did your user do?")).toBeVisible(); | ||
await page.getByLabel("What did your user do?").fill(name); | ||
|
||
await expect(page.getByLabel("Description")).toBeVisible(); | ||
await page.getByLabel("Description").fill(description); | ||
|
||
// User toggles the Inner Text action type | ||
|
||
await expect(page.locator("#InnerText")).toBeVisible(); | ||
await page.locator("#InnerText").click(); | ||
|
||
// User fills the Inner Text to track | ||
await expect(page.locator("[name='noCodeConfig.innerHtml.value']")).toBeVisible(); | ||
await page.locator("[name='noCodeConfig.innerHtml.value']").fill(innerText); | ||
await page.getByRole("button", { name: "Track Action", exact: true }).click(); | ||
}; |
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.
Refactor the test functions to reduce code duplication and improve readability. The functions createNoCodeActionByCSSSelector
, createNoCodeActionByPageURL
, and createNoCodeActionByInnerText
have been refactored into a single function createNoCodeAction
that accepts the necessary parameters to handle the variations.
const createNoCodeActionByCSSSelector = async ( | |
page: Page, | |
email: string, | |
password: string, | |
name: string, | |
description: string, | |
selector: string | |
) => { | |
// await signUpAndLogin(page, name, email, password); | |
await login(page, email, password); | |
// await skipOnboarding(page); | |
await page.getByRole("link", { name: "Actions & Attributes" }).click(); | |
// Add Action button | |
await page.getByRole("button", { name: "Add Action" }).click(); | |
// User fills the action name and description | |
await expect(page.getByLabel("What did your user do?")).toBeVisible(); | |
await page.getByLabel("What did your user do?").fill(name); | |
await expect(page.getByLabel("Description")).toBeVisible(); | |
await page.getByLabel("Description").fill(description); | |
// User toggles the CSS Selector action type | |
await expect(page.locator("#CssSelector")).toBeVisible(); | |
await page.locator("#CssSelector").click(); | |
// User fills the CSS Selector to track | |
await expect(page.locator("[name='noCodeConfig.cssSelector.value']")).toBeVisible(); | |
await page.locator("[name='noCodeConfig.cssSelector.value']").fill(selector); | |
await page.getByRole("button", { name: "Track Action", exact: true }).click(); | |
}; | |
const createNoCodeActionByPageURL = async ( | |
page: Page, | |
email: string, | |
password: string, | |
name: string, | |
description: string, | |
matcher: { | |
label: string; | |
value: string; | |
}, | |
testURL: string | |
) => { | |
// await signUpAndLogin(page, name, email, password); | |
await login(page, email, password); | |
// await skipOnboarding(page); | |
await page.getByRole("link", { name: "Actions & Attributes" }).click(); | |
// Add Action button | |
await page.getByRole("button", { name: "Add Action" }).click(); | |
// User fills the action name and description | |
await expect(page.getByLabel("What did your user do?")).toBeVisible(); | |
await page.getByLabel("What did your user do?").fill(name); | |
await expect(page.getByLabel("Description")).toBeVisible(); | |
await page.getByLabel("Description").fill(description); | |
// User toggles the Page URL action type | |
await expect(page.locator("#PageURL")).toBeVisible(); | |
await page.locator("#PageURL").click(); | |
// User opens the dropdown and selects the URL match type | |
await expect(page.locator("[name='noCodeConfig.[pageUrl].rule']")).toBeVisible(); | |
await page.locator("[name='noCodeConfig.[pageUrl].rule']").selectOption({ label: matcher.label }); | |
// User fills the Page URL to track | |
await page.locator("[name='noCodeConfig.[pageUrl].value']").fill(matcher.value); | |
// User fills the Test URL to track | |
await page.locator("[name='noCodeConfig.[pageUrl].testUrl']").fill(testURL); | |
// User clicks the Test Match button | |
await page.getByRole("button", { name: "Test Match", exact: true }).click(); | |
// User clicks the Track Action button | |
await page.getByRole("button", { name: "Track Action", exact: true }).click(); | |
}; | |
const createNoCodeActionByInnerText = async ( | |
page: Page, | |
email: string, | |
password: string, | |
name: string, | |
description: string, | |
innerText: string | |
) => { | |
// await signUpAndLogin(page, name, email, password); | |
await login(page, email, password); | |
// await skipOnboarding(page); | |
await page.getByRole("link", { name: "Actions & Attributes" }).click(); | |
// Add Action button | |
await page.getByRole("button", { name: "Add Action" }).click(); | |
// User fills the action name and description | |
await expect(page.getByLabel("What did your user do?")).toBeVisible(); | |
await page.getByLabel("What did your user do?").fill(name); | |
await expect(page.getByLabel("Description")).toBeVisible(); | |
await page.getByLabel("Description").fill(description); | |
// User toggles the Inner Text action type | |
await expect(page.locator("#InnerText")).toBeVisible(); | |
await page.locator("#InnerText").click(); | |
// User fills the Inner Text to track | |
await expect(page.locator("[name='noCodeConfig.innerHtml.value']")).toBeVisible(); | |
await page.locator("[name='noCodeConfig.innerHtml.value']").fill(innerText); | |
await page.getByRole("button", { name: "Track Action", exact: true }).click(); | |
}; | |
const createNoCodeAction = async ( | |
page: Page, | |
email: string, | |
password: string, | |
name: string, | |
description: string, | |
actionType: string, | |
actionValue: string | |
) => { | |
await login(page, email, password); | |
await page.getByRole("link", { name: "Actions & Attributes" }).click(); | |
await page.getByRole("button", { name: "Add Action" }).click(); | |
await expect(page.getByLabel("What did your user do?")).toBeVisible(); | |
await page.getByLabel("What did your user do?").fill(name); | |
await expect(page.getByLabel("Description")).toBeVisible(); | |
await page.getByLabel("Description").fill(description); | |
await expect(page.locator(`#${actionType}`)).toBeVisible(); | |
await page.locator(`#${actionType}`).click(); | |
await expect(page.locator(`[name='noCodeConfig.${actionType}.value']`)).toBeVisible(); | |
await page.locator(`[name='noCodeConfig.${actionType}.value']`).fill(actionValue); | |
await page.getByRole("button", { name: "Track Action", exact: true }).click(); | |
}; |
@@ -0,0 +1,320 @@ | |||
import { actions, users } from "@/playwright/utils/mock"; |
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.
Defining the repeated strings as constants at the top of the file to improve readability and maintainability.
import { actions, users } from "@/playwright/utils/mock"; | |
const WHAT_DID_YOUR_USER_DO = 'What did your user do?'; | |
const DESCRIPTION = 'Description'; | |
const TRACK_ACTION = 'Track Action'; | |
const ADD_ACTION = 'Add Action'; | |
const SAVE_CHANGES = 'Save changes'; | |
const SETTINGS = 'Settings'; | |
const TEST_MATCH = 'Test Match'; | |
const CODE = 'Code'; | |
const ACTIONS_AND_ATTRIBUTES = 'Actions & Attributes'; | |
const DELETE = 'Delete'; |
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.
@pandeymangg thanks a lot for adding the tests 😊🚀
We are great on track to test the most important frontend parts of the Formbricks app 💪
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.
@pandeymangg Thanks a lot for creating the additional tests 😊💪Looks great!
Now that we fixed the e2e pipeline, we can merge this :-) 🚀
What does this PR do?
Fixes # (issue)
Type of change
How should this be tested?
Checklist
Required
pnpm build
console.logs
git pull origin main
Appreciated