Files
formbricks/apps/web/playwright/survey.spec.ts
T
Dhruwang Jariwala dc1ee72594 chore: translation management revamp (scope 1) (#7733)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
2026-04-16 11:18:48 +00:00

1004 lines
45 KiB
TypeScript

import { expect } from "@playwright/test";
import { surveys } from "@/playwright/utils/mock";
import { test } from "./lib/fixtures";
import * as helper from "./utils/helper";
import { createSurvey, createSurveyWithLogic, uploadFileForFileUploadQuestion } from "./utils/helper";
test.use({
launchOptions: {
slowMo: 150,
},
});
test.describe("Survey Create & Submit Response without logic", async () => {
// 5 minutes
test.setTimeout(1000 * 60 * 5);
let url: string | null;
test("Create survey and submit response", async ({ page, users }) => {
const user = await users.create();
await user.login();
await page.waitForURL(/\/environments\/[^/]+\/surveys/);
await test.step("Create Survey", async () => {
await createSurvey(page, surveys.createAndSubmit);
// Save & Publish Survey
await page.getByRole("button", { name: "Settings", exact: true }).click();
await page.locator("#howToSendCardTrigger").click();
await expect(page.locator("#howToSendCardOption-link")).toBeVisible();
await page.locator("#howToSendCardOption-link").click();
// Wait for any auto-save to complete before publishing
await page.waitForTimeout(2000);
await page.getByRole("button", { name: "Publish" }).click();
// Get URL - increase timeout for slower local environments
await page.waitForURL(/\/environments\/[^/]+\/surveys\/[^/]+\/summary(\?.*)?$/, { timeout: 60000 });
await page.getByLabel("Copy survey link to clipboard").click();
url = await page.evaluate("navigator.clipboard.readText()");
});
await test.step("Submit Survey Response", async () => {
await page.goto(url!);
await page.waitForURL(/\/s\/[A-Za-z0-9]+$/);
// Welcome Card
await expect(
page.locator("#questionCard--1").getByText(surveys.createAndSubmit.welcomeCard.headline)
).toBeVisible();
await expect(
page.locator("#questionCard--1").getByText(surveys.createAndSubmit.welcomeCard.description)
).toBeVisible();
await page.locator("#questionCard--1").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("Open Text answer");
await page.locator("#questionCard-0").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
.locator("#questionCard-1 label")
.filter({ hasText: surveys.createAndSubmit.singleSelectQuestion.options[i] })
).toBeVisible();
}
await expect(page.getByText("Other")).toBeVisible();
await expect(page.locator("#questionCard-1").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-1").getByRole("button", { name: "Back" })).toBeVisible();
await page
.locator("#questionCard-1 label")
.filter({ hasText: surveys.createAndSubmit.singleSelectQuestion.options[0] })
.click();
await page.locator("#questionCard-1").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.singleSelectQuestion.options.length; i++) {
await expect(
page
.locator("#questionCard-2 label")
.filter({ hasText: surveys.createAndSubmit.multiSelectQuestion.options[i] })
).toBeVisible();
}
await expect(page.locator("#questionCard-2").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-2").getByRole("button", { name: "Back" })).toBeVisible();
for (let i = 0; i < surveys.createAndSubmit.multiSelectQuestion.options.length; i++) {
await page
.locator("#questionCard-2 label")
.filter({ hasText: surveys.createAndSubmit.multiSelectQuestion.options[i] })
.click();
}
await page.locator("#questionCard-2").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.locator("#questionCard-3").getByText(surveys.createAndSubmit.ratingQuestion.lowLabel)
).toBeVisible();
await expect(
page.locator("#questionCard-3").getByText(surveys.createAndSubmit.ratingQuestion.highLabel)
).toBeVisible();
// Rating component uses fieldset with labels, not a group with name "Choices"
expect(await page.locator("#questionCard-3").locator("fieldset label").count()).toBe(5);
await expect(page.locator("#questionCard-3").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-3").getByRole("button", { name: "Back" })).toBeVisible();
// Click on the label instead of the radio to avoid SVG intercepting pointer events
await page.locator("#questionCard-3").locator('label:has(input[value="3"])').click();
await page.locator("#questionCard-3").getByRole("button", { name: "Next" }).click();
// NPS Question
await expect(page.getByText(surveys.createAndSubmit.npsQuestion.question)).toBeVisible();
await expect(
page.locator("#questionCard-4").getByText(surveys.createAndSubmit.npsQuestion.lowLabel)
).toBeVisible();
await expect(
page.locator("#questionCard-4").getByText(surveys.createAndSubmit.npsQuestion.highLabel)
).toBeVisible();
await expect(page.locator("#questionCard-4").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-4").getByRole("button", { name: "Back" })).toBeVisible();
for (let i = 0; i < 11; i++) {
await expect(page.locator("#questionCard-4").getByText(`${i}`, { exact: true })).toBeVisible();
}
await page.locator("#questionCard-4").getByText("8", { exact: true }).click();
await page.locator("#questionCard-4").getByRole("button", { name: "Next" }).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.locator("#questionCard-5").getByRole("button", { name: "Next" }).click();
// Consent Question
await expect(page.getByText(surveys.createAndSubmit.consentQuestion.question)).toBeVisible();
await expect(page.getByText(surveys.createAndSubmit.consentQuestion.checkboxLabel)).toBeVisible();
await expect(page.locator("#questionCard-6").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-6").getByRole("button", { name: "Back" })).toBeVisible();
await page.getByLabel(surveys.createAndSubmit.consentQuestion.checkboxLabel).check();
await page.locator("#questionCard-6").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.locator("#questionCard-7").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-7").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.locator("#questionCard-7").getByRole("button", { name: "Next" }).click();
// File Upload Question
await expect(page.getByText(surveys.createAndSubmit.fileUploadQuestion.question)).toBeVisible();
await expect(page.locator("#questionCard-8").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-8").getByRole("button", { name: "Back" })).toBeVisible();
await expect(page.getByRole("button", { name: "Upload files by clicking or" })).toBeVisible();
await page.locator("input[type=file]").setInputFiles({
name: "file.doc",
mimeType: "application/msword",
buffer: Buffer.from("this is test"),
});
await page.getByText("Uploading...").waitFor({ state: "hidden" });
await page.locator("#questionCard-8").getByRole("button", { name: "Next" }).click();
// Matrix Question
await expect(page.getByText(surveys.createAndSubmit.matrix.question)).toBeVisible();
await expect(page.getByText(surveys.createAndSubmit.matrix.description)).toBeVisible();
await expect(
page.getByRole("rowheader", { name: surveys.createAndSubmit.matrix.rows[0] })
).toBeVisible();
await expect(
page.getByRole("rowheader", { name: surveys.createAndSubmit.matrix.rows[1] })
).toBeVisible();
await expect(
page.getByRole("rowheader", { name: surveys.createAndSubmit.matrix.rows[2] })
).toBeVisible();
await expect(
page.getByRole("columnheader", { name: surveys.createAndSubmit.matrix.columns[0], exact: true })
).toBeVisible();
await expect(
page.getByRole("columnheader", { name: surveys.createAndSubmit.matrix.columns[1], exact: true })
).toBeVisible();
await expect(
page.getByRole("columnheader", { name: surveys.createAndSubmit.matrix.columns[2], exact: true })
).toBeVisible();
await expect(
page.getByRole("columnheader", { name: surveys.createAndSubmit.matrix.columns[3], exact: true })
).toBeVisible();
await expect(page.locator("#questionCard-9").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-9").getByRole("button", { name: "Back" })).toBeVisible();
await page.getByRole("radio", { name: "Roses-0" }).click();
await page.getByRole("radio", { name: "Trees-0" }).click();
await page.getByRole("radio", { name: "Ocean-0" }).click();
await page.locator("#questionCard-9").getByRole("button", { name: "Next" }).click();
// Address Question
await expect(page.getByText(surveys.createAndSubmit.address.question)).toBeVisible();
await expect(page.getByLabel(surveys.createAndSubmit.address.placeholder.addressLine1)).toBeVisible();
await page.getByLabel(surveys.createAndSubmit.address.placeholder.addressLine1).fill("Address");
await expect(page.getByLabel(surveys.createAndSubmit.address.placeholder.city)).toBeVisible();
await page.getByLabel(surveys.createAndSubmit.address.placeholder.city).fill("city");
await expect(page.getByLabel(surveys.createAndSubmit.address.placeholder.zip)).toBeVisible();
await page.getByLabel(surveys.createAndSubmit.address.placeholder.zip).fill("12345");
await page.locator("#questionCard-10").getByRole("button", { name: "Next" }).click();
// Contact Info Question
await expect(page.getByText(surveys.createAndSubmit.contactInfo.question)).toBeVisible();
await expect(page.getByLabel(surveys.createAndSubmit.contactInfo.placeholder)).toBeVisible();
await page.getByLabel(surveys.createAndSubmit.contactInfo.placeholder).fill("John Doe");
await page.locator("#questionCard-11").getByRole("button", { name: "Next" }).click();
// Ranking Question
await expect(page.getByText(surveys.createAndSubmit.ranking.question)).toBeVisible();
for (let i = 0; i < surveys.createAndSubmit.ranking.choices.length; i++) {
await page.getByText(surveys.createAndSubmit.ranking.choices[i]).click();
}
await page.locator("#questionCard-12").getByRole("button", { name: "Finish" }).click();
// loading spinner -> wait for it to disappear
await page.getByTestId("loading-spinner").waitFor({ state: "hidden" });
});
});
});
test.describe("Multi Language Survey Create", async () => {
// 5 minutes
test.setTimeout(1000 * 60 * 5);
test("Create Survey", async ({ page, users }) => {
const user = await users.create();
await user.login();
await page.waitForURL(/\/environments\/[^/]+\/surveys/);
// Add workspace languages (English + German)
await page.getByRole("link", { name: "Configuration" }).click();
await page.getByRole("link", { name: "Survey Languages" }).click();
await page.getByRole("button", { name: "Edit languages" }).click();
await page.getByRole("button", { name: "Add language" }).click();
await page.getByRole("button", { name: "Select" }).click();
await page.getByPlaceholder("Search items").click();
await page.getByPlaceholder("Search items").fill("Eng");
await page.getByText("English", { exact: true }).click();
await page.getByRole("button", { name: "Save changes" }).click();
await page.getByRole("button", { name: "Edit languages" }).click();
await page.getByRole("button", { name: "Add language" }).click();
await page.getByRole("button", { name: "Select" }).click();
await page.getByRole("textbox", { name: "Search items" }).click();
await page.getByRole("textbox", { name: "Search items" }).fill("German");
await page.getByText("German", { exact: true }).nth(1).click();
await page.getByRole("button", { name: "Save changes" }).click();
await page.waitForTimeout(2000);
// Create survey and add all questions in English (default language)
await page.getByRole("link", { name: "Surveys" }).click();
await page.getByText("Start from scratch").click();
await page.getByRole("button", { name: "Create survey", exact: true }).click();
// Enable welcome card
await page.locator("#welcome-toggle").click();
// Add questions in default language
await page.getByText("Add Block").click();
await page.getByRole("button", { name: "Single-Select" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.singleSelectQuestion.question);
await page.getByPlaceholder("Option 1").fill(surveys.createAndSubmit.singleSelectQuestion.options[0]);
await page.getByPlaceholder("Option 2").fill(surveys.createAndSubmit.singleSelectQuestion.options[1]);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Multi-Select Ask respondents" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.multiSelectQuestion.question);
await page.getByPlaceholder("Option 1").fill(surveys.createAndSubmit.multiSelectQuestion.options[0]);
await page.getByPlaceholder("Option 2").fill(surveys.createAndSubmit.multiSelectQuestion.options[1]);
await page.getByPlaceholder("Option 3").fill(surveys.createAndSubmit.multiSelectQuestion.options[2]);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Picture Selection" }).click();
await helper.fillRichTextEditor(
page,
"Question*",
surveys.createAndSubmit.pictureSelectQuestion.question
);
// Handle file uploads
await uploadFileForFileUploadQuestion(page);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Rating" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.ratingQuestion.question);
await page.getByPlaceholder("Not good").fill(surveys.createAndSubmit.ratingQuestion.lowLabel);
await page.getByPlaceholder("Very satisfied").fill(surveys.createAndSubmit.ratingQuestion.highLabel);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Net Promoter Score (NPS)" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.npsQuestion.question);
await page.getByLabel("Lower label").fill(surveys.createAndSubmit.npsQuestion.lowLabel);
await page.getByLabel("Upper label").fill(surveys.createAndSubmit.npsQuestion.highLabel);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Date" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.dateQuestion.question);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "File Upload" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.fileUploadQuestion.question);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Matrix" }).scrollIntoViewIfNeeded();
await page.getByRole("button", { name: "Matrix" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.matrix.question);
await page.locator("#row-0").click();
await page.locator("#row-0").fill(surveys.createAndSubmit.matrix.rows[0]);
await page.locator("#row-1").click();
await page.locator("#row-1").fill(surveys.createAndSubmit.matrix.rows[1]);
await page.getByRole("button", { name: "Add row" }).click();
await page.locator("#row-2").click();
await page.locator("#row-2").fill(surveys.createAndSubmit.matrix.rows[2]);
await page.locator("#column-0").click();
await page.locator("#column-0").fill(surveys.createAndSubmit.matrix.columns[0]);
await page.locator("#column-1").click();
await page.locator("#column-1").fill(surveys.createAndSubmit.matrix.columns[1]);
await page.getByRole("button", { name: "Add column" }).click();
await page.locator("#column-2").click();
await page.locator("#column-2").fill(surveys.createAndSubmit.matrix.columns[2]);
await page.getByRole("button", { name: "Add column" }).click();
await page.locator("#column-3").click();
await page.locator("#column-3").fill(surveys.createAndSubmit.matrix.columns[3]);
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Address" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.address.question);
await page.getByRole("row", { name: "Address Line 2" }).getByRole("switch").nth(1).click();
await page.getByRole("row", { name: "City" }).getByRole("cell").nth(2).click();
await page.getByRole("row", { name: "State" }).getByRole("switch").nth(1).click();
await page.getByRole("row", { name: "Zip" }).getByRole("cell").nth(2).click();
await page.getByRole("row", { name: "Country" }).getByRole("switch").nth(1).click();
await page
.locator("div")
.filter({ hasText: /^Add BlockChoose the first question on your Block$/ })
.nth(1)
.click();
await page.getByRole("button", { name: "Ranking" }).click();
await helper.fillRichTextEditor(page, "Question*", surveys.createAndSubmit.ranking.question);
await page.getByPlaceholder("Option 1").click();
await page.getByPlaceholder("Option 1").fill(surveys.createAndSubmit.ranking.choices[0]);
await page.getByPlaceholder("Option 2").click();
await page.getByPlaceholder("Option 2").fill(surveys.createAndSubmit.ranking.choices[1]);
await page.getByRole("button", { name: "Add option" }).click();
await page.getByPlaceholder("Option 3").click();
await page.getByPlaceholder("Option 3").fill(surveys.createAndSubmit.ranking.choices[2]);
await page.getByRole("button", { name: "Add option" }).click();
await page.getByPlaceholder("Option 4").click();
await page.getByPlaceholder("Option 4").fill(surveys.createAndSubmit.ranking.choices[3]);
await page.getByRole("button", { name: "Add option" }).click();
await page.getByPlaceholder("Option 5").click();
await page.getByPlaceholder("Option 5").fill(surveys.createAndSubmit.ranking.choices[4]);
// Navigate to Language tab to enable translations and add German
await page.getByText("Language").click();
await page.locator("#activate-translations-toggle").click();
// Select English as default language
await page.locator("button", { hasText: "Select Language" }).click();
await page.getByText("English (en)", { exact: true }).click();
await page.getByRole("button", { name: "Confirm" }).click();
// Enable German by toggling its switch in the language table
await page
.getByRole("row", { name: /German/ })
.getByRole("switch")
.click();
// Open translation modal for German by clicking the German row
await page.getByRole("cell", { name: "German" }).click();
await expect(page.getByRole("dialog")).toBeVisible();
// Fill translations in the Manage Translations modal
// Welcome card translations (rich text for headline/subheader, plain for buttonLabel)
await helper.fillModalRichTranslation(
page,
"welcomeCard.headline",
surveys.germanCreate.welcomeCard.headline
);
await helper.fillModalRichTranslation(
page,
"welcomeCard.subheader",
surveys.germanCreate.welcomeCard.description
);
await helper.fillModalTranslation(
page,
"welcomeCard.buttonLabel",
surveys.germanCreate.welcomeCard.buttonLabel
);
// Block 0 - Open text question
await helper.fillModalTranslation(page, "blocks.0.buttonLabel", surveys.germanCreate.next);
await helper.fillModalRichTranslation(
page,
"blocks.0.elements.0.headline",
surveys.germanCreate.openTextQuestion.question
);
await helper.fillModalTranslation(
page,
"blocks.0.elements.0.placeholder",
surveys.germanCreate.openTextQuestion.placeholder
);
// Block 1 - Single-select question
await helper.fillModalRichTranslation(
page,
"blocks.1.elements.0.headline",
surveys.germanCreate.singleSelectQuestion.question
);
await helper.fillModalTranslation(
page,
"blocks.1.elements.0.choices.0.label",
surveys.germanCreate.singleSelectQuestion.options[0]
);
await helper.fillModalTranslation(
page,
"blocks.1.elements.0.choices.1.label",
surveys.germanCreate.singleSelectQuestion.options[1]
);
// Block 2 - Multi-select question
await helper.fillModalRichTranslation(
page,
"blocks.2.elements.0.headline",
surveys.germanCreate.multiSelectQuestion.question
);
await helper.fillModalTranslation(
page,
"blocks.2.elements.0.choices.0.label",
surveys.germanCreate.multiSelectQuestion.options[0]
);
await helper.fillModalTranslation(
page,
"blocks.2.elements.0.choices.1.label",
surveys.germanCreate.multiSelectQuestion.options[1]
);
await helper.fillModalTranslation(
page,
"blocks.2.elements.0.choices.2.label",
surveys.germanCreate.multiSelectQuestion.options[2]
);
// Block 3 - Picture selection question
await helper.fillModalRichTranslation(
page,
"blocks.3.elements.0.headline",
surveys.germanCreate.pictureSelectQuestion.question
);
// Block 4 - Rating question
await helper.fillModalRichTranslation(
page,
"blocks.4.elements.0.headline",
surveys.germanCreate.ratingQuestion.question
);
await helper.fillModalTranslation(
page,
"blocks.4.elements.0.lowerLabel",
surveys.germanCreate.ratingQuestion.lowLabel
);
await helper.fillModalTranslation(
page,
"blocks.4.elements.0.upperLabel",
surveys.germanCreate.ratingQuestion.highLabel
);
// Block 5 - NPS question
await helper.fillModalRichTranslation(
page,
"blocks.5.elements.0.headline",
surveys.germanCreate.npsQuestion.question
);
await helper.fillModalTranslation(
page,
"blocks.5.elements.0.lowerLabel",
surveys.germanCreate.npsQuestion.lowLabel
);
await helper.fillModalTranslation(
page,
"blocks.5.elements.0.upperLabel",
surveys.germanCreate.npsQuestion.highLabel
);
// Block 6 - Date question
await helper.fillModalRichTranslation(
page,
"blocks.6.elements.0.headline",
surveys.germanCreate.dateQuestion.question
);
// Block 7 - File upload question
await helper.fillModalRichTranslation(
page,
"blocks.7.elements.0.headline",
surveys.germanCreate.fileUploadQuestion.question
);
// Block 8 - Matrix question
await helper.fillModalRichTranslation(
page,
"blocks.8.elements.0.headline",
surveys.germanCreate.matrix.question
);
await helper.fillModalTranslation(
page,
"blocks.8.elements.0.rows.0.label",
surveys.germanCreate.matrix.rows[0]
);
await helper.fillModalTranslation(
page,
"blocks.8.elements.0.rows.1.label",
surveys.germanCreate.matrix.rows[1]
);
await helper.fillModalTranslation(
page,
"blocks.8.elements.0.rows.2.label",
surveys.germanCreate.matrix.rows[2]
);
await helper.fillModalTranslation(
page,
"blocks.8.elements.0.columns.0.label",
surveys.germanCreate.matrix.columns[0]
);
await helper.fillModalTranslation(
page,
"blocks.8.elements.0.columns.1.label",
surveys.germanCreate.matrix.columns[1]
);
await helper.fillModalTranslation(
page,
"blocks.8.elements.0.columns.2.label",
surveys.germanCreate.matrix.columns[2]
);
await helper.fillModalTranslation(
page,
"blocks.8.elements.0.columns.3.label",
surveys.germanCreate.matrix.columns[3]
);
// Block 9 - Address question
await helper.fillModalRichTranslation(
page,
"blocks.9.elements.0.headline",
surveys.germanCreate.addressQuestion.question
);
await helper.fillModalTranslation(
page,
"blocks.9.elements.0.addressLine1.placeholder",
surveys.germanCreate.addressQuestion.placeholder.addressLine1
);
await helper.fillModalTranslation(
page,
"blocks.9.elements.0.addressLine2.placeholder",
surveys.germanCreate.addressQuestion.placeholder.addressLine2
);
await helper.fillModalTranslation(
page,
"blocks.9.elements.0.city.placeholder",
surveys.germanCreate.addressQuestion.placeholder.city
);
await helper.fillModalTranslation(
page,
"blocks.9.elements.0.state.placeholder",
surveys.germanCreate.addressQuestion.placeholder.state
);
await helper.fillModalTranslation(
page,
"blocks.9.elements.0.zip.placeholder",
surveys.germanCreate.addressQuestion.placeholder.zip
);
await helper.fillModalTranslation(
page,
"blocks.9.elements.0.country.placeholder",
surveys.germanCreate.addressQuestion.placeholder.country
);
// Block 10 - Ranking question
await helper.fillModalRichTranslation(
page,
"blocks.10.elements.0.headline",
surveys.germanCreate.ranking.question
);
await helper.fillModalTranslation(
page,
"blocks.10.elements.0.choices.0.label",
surveys.germanCreate.ranking.choices[0]
);
await helper.fillModalTranslation(
page,
"blocks.10.elements.0.choices.1.label",
surveys.germanCreate.ranking.choices[1]
);
await helper.fillModalTranslation(
page,
"blocks.10.elements.0.choices.2.label",
surveys.germanCreate.ranking.choices[2]
);
await helper.fillModalTranslation(
page,
"blocks.10.elements.0.choices.3.label",
surveys.germanCreate.ranking.choices[3]
);
await helper.fillModalTranslation(
page,
"blocks.10.elements.0.choices.4.label",
surveys.germanCreate.ranking.choices[4]
);
// Ending card translations
await helper.fillModalRichTranslation(
page,
"endings.0.headline",
surveys.germanCreate.endingCard.headline
);
await helper.fillModalRichTranslation(
page,
"endings.0.subheader",
surveys.germanCreate.endingCard.description
);
await helper.fillModalTranslation(
page,
"endings.0.buttonLabel",
surveys.germanCreate.endingCard.buttonLabel
);
// Save translations
await page.getByRole("button", { name: "Save" }).click();
// Configure as link survey and publish
await page.getByRole("button", { name: "Settings", exact: true }).click();
await page.locator("#howToSendCardTrigger").click();
await expect(page.locator("#howToSendCardOption-link")).toBeVisible();
await page.locator("#howToSendCardOption-link").click();
// Wait for any auto-save to complete before publishing
await page.waitForTimeout(2000);
await page.getByRole("button", { name: "Publish" }).click();
await page.waitForTimeout(2000);
await page.waitForURL(/\/environments\/[^/]+\/surveys\/[^/]+\/summary(\?.*)?$/, { timeout: 60000 });
await page.getByLabel("Select Language").click();
await page.getByText("German").click();
await page.getByLabel("Copy survey link to clipboard").click();
const germanSurveyUrl = await page.evaluate("navigator.clipboard.readText()");
expect(germanSurveyUrl).toContain("lang=de");
});
});
test.describe("Testing Survey with advanced logic", async () => {
// 8 minutes
test.setTimeout(1000 * 60 * 8);
let url: string | null;
test("Create survey and submit response", async ({ page, users }) => {
const user = await users.create();
await user.login();
await page.waitForURL(/\/environments\/[^/]+\/surveys/);
await test.step("Create Survey", async () => {
await createSurveyWithLogic(page, surveys.createWithLogicAndSubmit);
// Save & Publish Survey
await page.getByRole("button", { name: "Settings", exact: true }).click();
await page.locator("#howToSendCardTrigger").click();
await expect(page.locator("#howToSendCardOption-link")).toBeVisible();
await page.locator("#howToSendCardOption-link").click();
await page.getByRole("button", { name: "Publish" }).click();
// Get URL
await page.waitForURL(/\/environments\/[^/]+\/surveys\/[^/]+\/summary(\?.*)?$/);
await page.getByLabel("Copy survey link to clipboard").click();
url = await page.evaluate("navigator.clipboard.readText()");
});
await test.step("Submit Survey Response", async () => {
await page.goto(url!);
await page.waitForURL(/\/s\/[A-Za-z0-9]+$/);
// Welcome Card
await expect(
page.locator("#questionCard--1").getByText(surveys.createWithLogicAndSubmit.welcomeCard.headline)
).toBeVisible();
await expect(
page.locator("#questionCard--1").getByText(surveys.createWithLogicAndSubmit.welcomeCard.description)
).toBeVisible();
await page.locator("#questionCard--1").getByRole("button", { name: "Next" }).click();
// Open Text Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.openTextQuestion.question)).toBeVisible();
await expect(
page.getByText(surveys.createWithLogicAndSubmit.openTextQuestion.description)
).toBeVisible();
await expect(
page.getByPlaceholder(surveys.createWithLogicAndSubmit.openTextQuestion.placeholder)
).toBeVisible();
await page
.getByPlaceholder(surveys.createWithLogicAndSubmit.openTextQuestion.placeholder)
.fill("Open Text answer");
await page.locator("#questionCard-0").getByRole("button", { name: "Next" }).click();
// Single Select Question
await expect(
page.getByText(surveys.createWithLogicAndSubmit.singleSelectQuestion.question)
).toBeVisible();
await expect(
page.getByText(surveys.createWithLogicAndSubmit.singleSelectQuestion.description)
).toBeVisible();
for (let i = 0; i < surveys.createWithLogicAndSubmit.singleSelectQuestion.options.length; i++) {
await expect(
page
.locator("#questionCard-1 label")
.filter({ hasText: surveys.createWithLogicAndSubmit.singleSelectQuestion.options[i] })
).toBeVisible();
}
await expect(page.getByText("Other")).toBeVisible();
await expect(page.locator("#questionCard-1").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-1").getByRole("button", { name: "Back" })).toBeVisible();
await page
.locator("#questionCard-1 label")
.filter({ hasText: surveys.createWithLogicAndSubmit.singleSelectQuestion.options[0] })
.click();
await page.locator("#questionCard-1").getByRole("button", { name: "Next" }).click();
// Multi Select Question
await expect(
page.getByText(surveys.createWithLogicAndSubmit.multiSelectQuestion.question)
).toBeVisible();
await expect(
page.getByText(surveys.createWithLogicAndSubmit.multiSelectQuestion.description)
).toBeVisible();
for (let i = 0; i < surveys.createWithLogicAndSubmit.singleSelectQuestion.options.length; i++) {
await expect(
page
.locator("#questionCard-2 label")
.filter({ hasText: surveys.createWithLogicAndSubmit.multiSelectQuestion.options[i] })
).toBeVisible();
}
await expect(page.locator("#questionCard-2").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-2").getByRole("button", { name: "Back" })).toBeVisible();
for (let i = 0; i < surveys.createWithLogicAndSubmit.multiSelectQuestion.options.length; i++) {
await page
.locator("#questionCard-2 label")
.filter({ hasText: surveys.createWithLogicAndSubmit.multiSelectQuestion.options[i] })
.click();
}
await page.locator("#questionCard-2").getByRole("button", { name: "Next" }).click();
// Picture Select Question
await expect(
page.getByText(surveys.createWithLogicAndSubmit.pictureSelectQuestion.question)
).toBeVisible();
await expect(
page.getByText(surveys.createWithLogicAndSubmit.pictureSelectQuestion.description)
).toBeVisible();
await expect(page.locator("#questionCard-3").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-3").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.locator("#questionCard-3").getByRole("button", { name: "Next" }).click();
// Rating Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.ratingQuestion.question)).toBeVisible();
await expect(page.getByText(surveys.createWithLogicAndSubmit.ratingQuestion.description)).toBeVisible();
await expect(
page.locator("#questionCard-4").getByText(surveys.createWithLogicAndSubmit.ratingQuestion.lowLabel)
).toBeVisible();
await expect(
page.locator("#questionCard-4").getByText(surveys.createWithLogicAndSubmit.ratingQuestion.highLabel)
).toBeVisible();
await expect(page.locator("#questionCard-4").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-4").getByRole("button", { name: "Back" })).toBeVisible();
// Click on the label instead of the radio to avoid SVG intercepting pointer events
await page.locator("#questionCard-4").locator('label:has(input[value="4"])').click();
await page.locator("#questionCard-4").getByRole("button", { name: "Next" }).click();
// NPS Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.npsQuestion.question)).toBeVisible();
await expect(
page.locator("#questionCard-5").getByText(surveys.createWithLogicAndSubmit.npsQuestion.lowLabel)
).toBeVisible();
await expect(
page.locator("#questionCard-5").getByText(surveys.createWithLogicAndSubmit.npsQuestion.highLabel)
).toBeVisible();
await expect(page.locator("#questionCard-5").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-5").getByRole("button", { name: "Back" })).toBeVisible();
for (let i = 0; i < 11; i++) {
await expect(page.locator("#questionCard-5").getByText(`${i}`, { exact: true })).toBeVisible();
}
await page.locator("#questionCard-5").getByText("5", { exact: true }).click();
await page.locator("#questionCard-5").getByRole("button", { name: "Next" }).click();
// Ranking Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.ranking.question)).toBeVisible();
await page.locator("#questionCard-6").getByRole("button", { name: "Next" }).click();
// Matrix Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.matrix.question)).toBeVisible();
await expect(page.getByText(surveys.createWithLogicAndSubmit.matrix.description)).toBeVisible();
await expect(
page.getByRole("rowheader", { name: surveys.createWithLogicAndSubmit.matrix.rows[0] })
).toBeVisible();
await expect(
page.getByRole("rowheader", { name: surveys.createWithLogicAndSubmit.matrix.rows[1] })
).toBeVisible();
await expect(
page.getByRole("rowheader", { name: surveys.createWithLogicAndSubmit.matrix.rows[2] })
).toBeVisible();
await expect(
page.getByRole("columnheader", {
name: surveys.createWithLogicAndSubmit.matrix.columns[0],
exact: true,
})
).toBeVisible();
await expect(
page.getByRole("columnheader", {
name: surveys.createWithLogicAndSubmit.matrix.columns[1],
exact: true,
})
).toBeVisible();
await expect(
page.getByRole("columnheader", {
name: surveys.createWithLogicAndSubmit.matrix.columns[2],
exact: true,
})
).toBeVisible();
await expect(
page.getByRole("columnheader", {
name: surveys.createWithLogicAndSubmit.matrix.columns[3],
exact: true,
})
).toBeVisible();
await expect(page.locator("#questionCard-7").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-7").getByRole("button", { name: "Back" })).toBeVisible();
await page.getByRole("radio", { name: "Roses-0" }).click();
await page.getByRole("radio", { name: "Trees-0" }).click();
await page.getByRole("radio", { name: "Ocean-0" }).click();
await page.locator("#questionCard-7").getByRole("button", { name: "Next" }).click();
// CTA Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.ctaQuestion.question)).toBeVisible();
await expect(
page.getByRole("button", { name: surveys.createWithLogicAndSubmit.ctaQuestion.buttonLabel })
).toBeVisible();
await page
.getByRole("button", { name: surveys.createWithLogicAndSubmit.ctaQuestion.buttonLabel })
.click();
await page.locator("#questionCard-8").getByRole("button", { name: "Next" }).click();
// Consent Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.consentQuestion.question)).toBeVisible();
await expect(
page.getByText(surveys.createWithLogicAndSubmit.consentQuestion.checkboxLabel)
).toBeVisible();
await expect(page.locator("#questionCard-9").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-9").getByRole("button", { name: "Back" })).toBeVisible();
await page.getByLabel(surveys.createWithLogicAndSubmit.consentQuestion.checkboxLabel).check();
await page.locator("#questionCard-9").getByRole("button", { name: "Next" }).click();
// File Upload Question
await expect(
page.getByText(surveys.createWithLogicAndSubmit.fileUploadQuestion.question)
).toBeVisible();
await expect(page.locator("#questionCard-10").getByRole("button", { name: "Next" })).toBeVisible();
await expect(page.locator("#questionCard-10").getByRole("button", { name: "Back" })).toBeVisible();
await expect(page.getByRole("button", { name: "Upload files by clicking or" })).toBeVisible();
await page.locator("input[type=file]").setInputFiles({
name: "file.doc",
mimeType: "application/msword",
buffer: Buffer.from("this is test"),
});
await page.getByText("Uploading...").waitFor({ state: "hidden" });
await page.locator("#questionCard-10").getByRole("button", { name: "Next" }).click();
// Date Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.date.question)).toBeVisible();
// Click the "Today" button in the date picker - matches format like "Today, Tuesday, December 16th,"
await page.getByRole("button", { name: /^Today,/ }).click();
// Only click "Scroll to bottom" if visible (it may already be scrolled if today is at month end)
const scrollToBottomButton = page.getByRole("button", { name: "Scroll to bottom" });
if (await scrollToBottomButton.isVisible()) {
await scrollToBottomButton.click();
}
await page.locator("#questionCard-11").getByRole("button", { name: "Next", exact: true }).click();
// Cal Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.cal.question)).toBeVisible();
await page.locator("#questionCard-12").getByRole("button", { name: "Next" }).click();
// Address Question
await expect(page.getByText(surveys.createWithLogicAndSubmit.address.question)).toBeVisible();
await expect(
page.getByLabel(surveys.createWithLogicAndSubmit.address.placeholder.addressLine1)
).toBeVisible();
await page
.getByLabel(surveys.createWithLogicAndSubmit.address.placeholder.addressLine1)
.fill("Address");
await expect(page.getByLabel(surveys.createWithLogicAndSubmit.address.placeholder.city)).toBeVisible();
await page.getByLabel(surveys.createWithLogicAndSubmit.address.placeholder.city).fill("city");
await expect(page.getByLabel(surveys.createWithLogicAndSubmit.address.placeholder.zip)).toBeVisible();
await page.getByLabel(surveys.createWithLogicAndSubmit.address.placeholder.zip).fill("12345");
await page.locator("#questionCard-13").getByRole("button", { name: "Finish" }).click();
// loading spinner -> wait for it to disappear
await page.getByTestId("loading-spinner").waitFor({ state: "hidden" });
// Thank You Card
await expect(page.getByText(surveys.createWithLogicAndSubmit.endingCard.headline)).toBeVisible();
await expect(page.getByText(surveys.createWithLogicAndSubmit.endingCard.description)).toBeVisible();
});
await test.step("Verify Survey Response", async () => {
await page.goBack();
await page.waitForURL(/\/environments\/[^/]+\/surveys\/[^/]+\/summary(\?.*)?$/);
const currentUrl = page.url();
const updatedUrl = currentUrl.replace("summary?share=true", "responses");
await page.goto(updatedUrl);
const responseTable = page.locator("table#response-table");
await expect(responseTable).toBeVisible();
await expect(responseTable.getByRole("columnheader", { name: /^score$/i })).toBeVisible({
timeout: 15000,
});
await page.waitForLoadState("networkidle");
await page.waitForTimeout(5000);
// Look for any cell containing "32" or a score-related value
const scoreCell = page.getByRole("cell").filter({ hasText: /^32/ });
await expect(scoreCell).toBeVisible({
timeout: 15000,
});
// Look for the secret message in the table
const secretCell = page.getByRole("cell").filter({ hasText: /This is a secret message for e2e tests/ });
await expect(secretCell).toBeVisible({
timeout: 15000,
});
});
});
});