From f93c5b3c553d1247c2d31ccf90cf1d48323cbc09 Mon Sep 17 00:00:00 2001 From: Shubham Palriwala Date: Mon, 8 Apr 2024 15:07:09 +0530 Subject: [PATCH] fix: e2e tests, make welcomeCard.headline optional, remove console logs (#2374) --- .github/actions/cache-build-web/action.yml | 1 + apps/web/playwright/js.spec.ts | 6 ++---- apps/web/playwright/onboarding.spec.ts | 2 +- apps/web/playwright/survey.spec.ts | 15 ++++++++------ apps/web/playwright/utils/helper.ts | 2 +- apps/web/playwright/utils/mock.ts | 5 +++++ packages/js-core/index.html | 2 +- packages/js-core/src/index.ts | 1 - packages/lib/i18n/reverseTranslation.ts | 2 +- packages/types/surveys.ts | 24 +++++++++++++--------- playwright.config.ts | 2 +- 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/.github/actions/cache-build-web/action.yml b/.github/actions/cache-build-web/action.yml index ce5445ab08..34cfa42f80 100644 --- a/.github/actions/cache-build-web/action.yml +++ b/.github/actions/cache-build-web/action.yml @@ -46,6 +46,7 @@ runs: run: | SECRET=$(openssl rand -hex 32) echo "ENCRYPTION_KEY=$SECRET" >> $GITHUB_ENV + echo "ENTERPRISE_LICENSE_KEY=$SECRET" >> $GITHUB_ENV shell: bash - run: | diff --git a/apps/web/playwright/js.spec.ts b/apps/web/playwright/js.spec.ts index 8e647f75b2..384610bd36 100644 --- a/apps/web/playwright/js.spec.ts +++ b/apps/web/playwright/js.spec.ts @@ -46,13 +46,11 @@ test.describe("JS Package Test", async () => { expect(page.getByRole("link", { name: "Surveys" })).toBeVisible(); await page.getByRole("link", { name: "Surveys" }).click(); await expect(page.getByRole("heading", { name: "Surveys" })).toBeVisible(); - - await page.screenshot(); }); test("JS Display Survey on Page", async ({ page }) => { let currentDir = process.cwd(); - let htmlFilePath = currentDir + "/packages/js/index.html"; + let htmlFilePath = currentDir + "/packages/js-core/index.html"; let htmlFile = replaceEnvironmentIdInHtml(htmlFilePath, environmentId); await page.goto(htmlFile); @@ -76,7 +74,7 @@ test.describe("JS Package Test", async () => { test("JS submits Response to Survey", async ({ page }) => { let currentDir = process.cwd(); - let htmlFilePath = currentDir + "/packages/js/index.html"; + let htmlFilePath = currentDir + "/packages/js-core/index.html"; let htmlFile = "file:///" + htmlFilePath; diff --git a/apps/web/playwright/onboarding.spec.ts b/apps/web/playwright/onboarding.spec.ts index 2d8fad6353..63db58bdc4 100644 --- a/apps/web/playwright/onboarding.spec.ts +++ b/apps/web/playwright/onboarding.spec.ts @@ -30,7 +30,7 @@ test.describe("Onboarding Flow Test", async () => { await page.getByRole("button", { name: "Skip" }).click(); await page.getByRole("button", { name: "Skip" }).click(); - await page.getByRole("button", { name: "I am not sure how to do this" }).click(); + await page.getByRole("button", { name: "Skip" }).click(); await page.locator("input").click(); await page.locator("input").fill("test@gmail.com"); await page.getByRole("button", { name: "Invite" }).click(); diff --git a/apps/web/playwright/survey.spec.ts b/apps/web/playwright/survey.spec.ts index acc9848d53..db584ee0df 100644 --- a/apps/web/playwright/survey.spec.ts +++ b/apps/web/playwright/survey.spec.ts @@ -23,10 +23,8 @@ test.describe("Survey Create & Submit Response", async () => { // Get URL await page.waitForURL(/\/environments\/[^/]+\/surveys\/[^/]+\/summary$/); - url = await page - .locator("div") - .filter({ hasText: /^http:\/\/localhost:3000\/s\/[A-Za-z0-9]+$/ }) - .innerText(); + await page.getByLabel("Copy survey link to clipboard").click(); + url = await page.evaluate("navigator.clipboard.readText()"); }); test("Create Survey with Custom Actions", async ({ page }) => { @@ -195,7 +193,7 @@ test.describe("Survey Create & Submit Response", async () => { test.describe("Multi Language Survey Create", async () => { test.describe.configure({ mode: "serial" }); - const { name, email, password } = users.survey[2]; + const { name, email, password } = users.survey[3]; test("Create Survey", async ({ page }) => { await signUpAndLogin(page, name, email, password); await finishOnboarding(page); @@ -217,7 +215,7 @@ test.describe("Multi Language Survey Create", async () => { await page.getByRole("textbox", { name: "Search items" }).fill("German"); await page.getByText("German").nth(1).click(); await page.getByRole("button", { name: "Save Changes" }).click(); - await new Promise((resolve) => setTimeout(resolve, 2000)); + await page.waitForTimeout(2000); await page.getByRole("link", { name: "Surveys" }).click(); await page.getByRole("button", { name: "Start from scratch Create a" }).click(); await page.locator("#multi-lang-toggle").click(); @@ -273,6 +271,8 @@ test.describe("Multi Language Survey Create", async () => { .filter({ hasText: /^Add QuestionAdd a new question to your survey$/ }) .nth(1) .click(); + + await page.getByRole("button", { name: "Matrix" }).scrollIntoViewIfNeeded(); await page.getByRole("button", { name: "Matrix" }).click(); // Enable translation in german @@ -422,5 +422,8 @@ test.describe("Multi Language Survey Create", async () => { await page.waitForURL(/\/environments\/[^/]+\/surveys\/[^/]+\/summary$/); 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"); }); }); diff --git a/apps/web/playwright/utils/helper.ts b/apps/web/playwright/utils/helper.ts index 7cd8f99282..fe8d13f96d 100644 --- a/apps/web/playwright/utils/helper.ts +++ b/apps/web/playwright/utils/helper.ts @@ -64,7 +64,7 @@ export const finishOnboarding = async (page: Page, deleteExampleSurvey: boolean await expect(page.getByText("My Product")).toBeVisible(); let currentDir = process.cwd(); - let htmlFilePath = currentDir + "/packages/js/index.html"; + let htmlFilePath = currentDir + "/packages/js-core/index.html"; const environmentId = /\/environments\/([^/]+)\/surveys/.exec(page.url())?.[1] ?? diff --git a/apps/web/playwright/utils/mock.ts b/apps/web/playwright/utils/mock.ts index ff41c2b952..e779e51226 100644 --- a/apps/web/playwright/utils/mock.ts +++ b/apps/web/playwright/utils/mock.ts @@ -34,6 +34,11 @@ export const users = { email: "survey3@formbricks.com", password: "Gj2DGji27D&M8u53V", }, + { + name: "Survey User 4", + email: "survey4@formbricks.com", + password: "UU3efj8vJa&M8u5M1", + }, ], js: [ { diff --git a/packages/js-core/index.html b/packages/js-core/index.html index 56507f16a2..c62bafc504 100644 --- a/packages/js-core/index.html +++ b/packages/js-core/index.html @@ -7,7 +7,7 @@ e.parentNode.insertBefore(t, e), setTimeout(function () { formbricks.init({ - environmentId: "clu9xfvdn0009vhyg9b6858gc", + environmentId: "cluqpv56n00lbxl3f8xvytyog", apiHost: "http://localhost:3000", }); }, 500); diff --git a/packages/js-core/src/index.ts b/packages/js-core/src/index.ts index f50d43d4e8..abf9f25ac8 100644 --- a/packages/js-core/src/index.ts +++ b/packages/js-core/src/index.ts @@ -25,7 +25,6 @@ logger.debug("Create command queue"); const queue = new CommandQueue(); const init = async (initConfig: TJsConfigInput) => { - console.log("init in formbricks-js-core"); ErrorHandler.init(initConfig.errorHandler); queue.add(false, initialize, initConfig); await queue.wait(); diff --git a/packages/lib/i18n/reverseTranslation.ts b/packages/lib/i18n/reverseTranslation.ts index d2d2872546..397a2861f1 100644 --- a/packages/lib/i18n/reverseTranslation.ts +++ b/packages/lib/i18n/reverseTranslation.ts @@ -37,7 +37,7 @@ export const reverseTranslateSurvey = (survey: TSurvey, languageCode: string = " // check if the headline is an empty object, if so, add a "default" key // TODO: This is a temporary fix, should be handled propperly - if (Object.keys(reversedSurvey.welcomeCard.headline).length === 0) { + if (reversedSurvey.welcomeCard.headline && Object.keys(reversedSurvey.welcomeCard.headline).length === 0) { reversedSurvey.welcomeCard.headline = { default: "" }; } diff --git a/packages/types/surveys.ts b/packages/types/surveys.ts index 99af33aa19..38ce1c99c2 100644 --- a/packages/types/surveys.ts +++ b/packages/types/surveys.ts @@ -38,16 +38,20 @@ export enum TSurveyQuestionType { Matrix = "matrix", } -export const ZSurveyWelcomeCard = z.object({ - enabled: z.boolean(), - headline: ZI18nString, - html: ZI18nString.optional(), - fileUrl: z.string().optional(), - buttonLabel: ZI18nString.optional(), - timeToFinish: z.boolean().default(true), - showResponseCount: z.boolean().default(false), - videoUrl: z.string().optional(), -}); +export const ZSurveyWelcomeCard = z + .object({ + enabled: z.boolean(), + headline: ZI18nString.optional(), + html: ZI18nString.optional(), + fileUrl: z.string().optional(), + buttonLabel: ZI18nString.optional(), + timeToFinish: z.boolean().default(true), + showResponseCount: z.boolean().default(false), + videoUrl: z.string().optional(), + }) + .refine((schema) => !(schema.enabled && !schema.headline), { + message: "Welcome card must have a headline", + }); export const ZSurveyHiddenFields = z.object({ enabled: z.boolean(), diff --git a/playwright.config.ts b/playwright.config.ts index 4d0dfa761b..ed7cada0f3 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -16,7 +16,7 @@ export default defineConfig({ /* Retry on CI only */ retries: 0, /* Timeout for each test */ - timeout: 90000, + timeout: 120000, /* Opt out of parallel tests on CI. */ workers: 1, /* Reporter to use. See https://playwright.dev/docs/test-reporters */