mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-29 19:41:32 -05:00
70b7f6614e
Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
181 lines
9.1 KiB
TypeScript
181 lines
9.1 KiB
TypeScript
import { surveys, users } from "@/playwright/utils/mock";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
import { createSurvey } from "./utils/helper";
|
|
|
|
test.describe("Survey Create & Submit Response", async () => {
|
|
test.describe.configure({ mode: "serial" });
|
|
let url: string | null;
|
|
const { name, email, password } = users.survey[0];
|
|
|
|
test("Create Survey", async ({ page }) => {
|
|
await createSurvey(page, name, email, password, surveys.createAndSubmit);
|
|
// Save & Publish Survey
|
|
await page.getByRole("button", { name: "Continue to Settings" }).click();
|
|
await page.getByRole("button", { name: "Publish" }).click();
|
|
|
|
// Get URL
|
|
await page.waitForURL(/\/environments\/[^/]+\/surveys\/[^/]+\/summary$/);
|
|
url = await page
|
|
.locator("div")
|
|
.filter({ hasText: /^http:\/\/localhost:3000\/s\/[A-Za-z0-9]+$/ })
|
|
.innerText();
|
|
});
|
|
|
|
test("Create Survey with Custom Actions", async ({ page }) => {
|
|
const { name, email, password } = users.survey[1];
|
|
|
|
await createSurvey(page, name, email, password, surveys.createAndSubmit);
|
|
// Save & Publish Survey
|
|
await page.getByRole("button", { name: "Continue to Settings" }).click();
|
|
|
|
await expect(page.locator("#howToSendCardTrigger")).toBeVisible();
|
|
await page.locator("#howToSendCardTrigger").click();
|
|
|
|
await expect(page.locator("#howToSendCardOption-web")).toBeVisible();
|
|
await page.locator("#howToSendCardOption-web").click();
|
|
|
|
await expect(page.getByText("Survey Trigger")).toBeVisible();
|
|
await page.getByText("Survey Trigger").click();
|
|
|
|
await page.getByRole("button", { name: "Custom Actions" }).click();
|
|
|
|
await expect(page.locator("#codeAction")).toBeVisible();
|
|
await page.locator("#codeAction").click();
|
|
|
|
await expect(page.locator("#codeActionIdentifierInput")).toBeVisible();
|
|
await page.locator("#codeActionIdentifierInput").fill("my-custom-code-action");
|
|
|
|
await expect(page.locator("#noCodeAction")).toBeVisible();
|
|
await page.locator("#noCodeAction").click();
|
|
|
|
await expect(page.locator("#cssSelectorToggle")).toBeVisible();
|
|
await expect(page.locator("#pageURLToggle")).toBeVisible();
|
|
await expect(page.locator("#innerHTMLToggle")).toBeVisible();
|
|
|
|
await page.locator("#cssSelectorToggle").click();
|
|
await expect(page.locator("#cssSelectorInput")).toBeVisible();
|
|
await page.locator("#cssSelectorInput").fill(".my-custom-class");
|
|
|
|
await page.locator("#pageURLToggle").click();
|
|
await expect(page.locator("#pageURLInput")).toBeVisible();
|
|
await page.locator("#pageURLInput").fill("custom-url");
|
|
|
|
await page.locator("#innerHTMLToggle").click();
|
|
await expect(page.locator("#innerHTMLInput")).toBeVisible();
|
|
await page.locator("#innerHTMLInput").fill("Download");
|
|
|
|
await page.getByRole("button", { name: "Publish" }).click();
|
|
});
|
|
|
|
test("Submit Survey Response", async ({ page }) => {
|
|
await page.goto(url!);
|
|
await page.waitForURL(/\/s\/[A-Za-z0-9]+$/);
|
|
|
|
// Welcome Card
|
|
await expect(page.getByText(surveys.createAndSubmit.welcomeCard.headline)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.welcomeCard.description)).toBeVisible();
|
|
await page.getByRole("button", { name: "Next" }).click();
|
|
|
|
// Open Text Question
|
|
await expect(page.getByText(surveys.createAndSubmit.openTextQuestion.question)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.openTextQuestion.description)).toBeVisible();
|
|
await expect(page.getByPlaceholder(surveys.createAndSubmit.openTextQuestion.placeholder)).toBeVisible();
|
|
await page
|
|
.getByPlaceholder(surveys.createAndSubmit.openTextQuestion.placeholder)
|
|
.fill("This is my Open Text answer");
|
|
await page.getByRole("button", { name: "Next" }).click();
|
|
|
|
// Single Select Question
|
|
await expect(page.getByText(surveys.createAndSubmit.singleSelectQuestion.question)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.singleSelectQuestion.description)).toBeVisible();
|
|
for (let i = 0; i < surveys.createAndSubmit.singleSelectQuestion.options.length; i++) {
|
|
await expect(page.getByText(surveys.createAndSubmit.singleSelectQuestion.options[i])).toBeVisible();
|
|
}
|
|
await expect(page.getByText("Other")).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Next" })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
|
|
await page.getByText(surveys.createAndSubmit.singleSelectQuestion.options[0]).click();
|
|
await page.getByRole("button", { name: "Next" }).click();
|
|
|
|
// Multi Select Question
|
|
await expect(page.getByText(surveys.createAndSubmit.multiSelectQuestion.question)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.multiSelectQuestion.description)).toBeVisible();
|
|
for (let i = 0; i < surveys.createAndSubmit.multiSelectQuestion.options.length; i++) {
|
|
await expect(page.getByText(surveys.createAndSubmit.multiSelectQuestion.options[i])).toBeVisible();
|
|
}
|
|
await expect(page.getByRole("button", { name: "Next" })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
|
|
await page.getByText(surveys.createAndSubmit.multiSelectQuestion.options[0]).click();
|
|
await page.getByText(surveys.createAndSubmit.multiSelectQuestion.options[1]).click();
|
|
await page.getByRole("button", { name: "Next" }).click();
|
|
|
|
// Rating Question
|
|
await expect(page.getByText(surveys.createAndSubmit.ratingQuestion.question)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.ratingQuestion.description)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.ratingQuestion.lowLabel)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.ratingQuestion.highLabel)).toBeVisible();
|
|
expect(await page.getByRole("group", { name: "Choices" }).locator("label").count()).toBe(5);
|
|
await expect(page.getByRole("button", { name: "Next" })).not.toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
|
|
await page.getByLabel("").nth(3).click();
|
|
|
|
// NPS Question
|
|
await expect(page.getByText(surveys.createAndSubmit.npsQuestion.question)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.npsQuestion.lowLabel)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.npsQuestion.highLabel)).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Next" })).not.toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
|
|
|
|
for (let i = 0; i < 11; i++) {
|
|
await expect(page.getByText(`${i}`, { exact: true })).toBeVisible();
|
|
}
|
|
await page.getByText("8").click();
|
|
|
|
// CTA Question
|
|
await expect(page.getByText(surveys.createAndSubmit.ctaQuestion.question)).toBeVisible();
|
|
await expect(
|
|
page.getByRole("button", { name: surveys.createAndSubmit.ctaQuestion.buttonLabel })
|
|
).toBeVisible();
|
|
await page.getByRole("button", { name: surveys.createAndSubmit.ctaQuestion.buttonLabel }).click();
|
|
|
|
// Consent Question
|
|
await expect(page.getByText(surveys.createAndSubmit.consentQuestion.question)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.consentQuestion.checkboxLabel)).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Next" })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
|
|
await page.getByText(surveys.createAndSubmit.consentQuestion.checkboxLabel).check();
|
|
await page.getByRole("button", { name: "Next" }).click();
|
|
|
|
// Picture Select Question
|
|
await expect(page.getByText(surveys.createAndSubmit.pictureSelectQuestion.question)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.pictureSelectQuestion.description)).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Next" })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
|
|
await expect(page.getByRole("img", { name: "puppy-1-small.jpg" })).toBeVisible();
|
|
await expect(page.getByRole("img", { name: "puppy-2-small.jpg" })).toBeVisible();
|
|
await page.getByRole("img", { name: "puppy-1-small.jpg" }).click();
|
|
await page.getByRole("button", { name: "Next" }).click();
|
|
|
|
// File Upload Question
|
|
await expect(page.getByText(surveys.createAndSubmit.fileUploadQuestion.question)).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Finish" })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
|
|
await expect(
|
|
page.locator("label").filter({ hasText: "Click or drag to upload files." }).locator("div").nth(0)
|
|
).toBeVisible();
|
|
await page.locator("input[type=file]").setInputFiles({
|
|
name: "file.txt",
|
|
mimeType: "text/plain",
|
|
buffer: Buffer.from("this is test"),
|
|
});
|
|
await page.getByText("Uploading...").waitFor({ state: "hidden" });
|
|
|
|
await page.getByRole("button", { name: "Finish" }).click();
|
|
|
|
// Thank You Card
|
|
await expect(page.getByText(surveys.createAndSubmit.thankYouCard.headline)).toBeVisible();
|
|
await expect(page.getByText(surveys.createAndSubmit.thankYouCard.description)).toBeVisible();
|
|
});
|
|
});
|