Skip to content

Commit

Permalink
fix: e2e tests, make welcomeCard.headline optional, remove console lo…
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamPalriwala authored Apr 8, 2024
1 parent 08ce026 commit f93c5b3
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 26 deletions.
1 change: 1 addition & 0 deletions .github/actions/cache-build-web/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
6 changes: 2 additions & 4 deletions apps/web/playwright/js.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion apps/web/playwright/onboarding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
await page.getByRole("button", { name: "Invite" }).click();
Expand Down
15 changes: 9 additions & 6 deletions apps/web/playwright/survey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
});
});
2 changes: 1 addition & 1 deletion apps/web/playwright/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] ??
Expand Down
5 changes: 5 additions & 0 deletions apps/web/playwright/utils/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export const users = {
email: "[email protected]",
password: "Gj2DGji27D&M8u53V",
},
{
name: "Survey User 4",
email: "[email protected]",
password: "UU3efj8vJa&M8u5M1",
},
],
js: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/js-core/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
e.parentNode.insertBefore(t, e),
setTimeout(function () {
formbricks.init({
environmentId: "clu9xfvdn0009vhyg9b6858gc",
environmentId: "cluqpv56n00lbxl3f8xvytyog",
apiHost: "http://localhost:3000",
});
}, 500);
Expand Down
1 change: 0 additions & 1 deletion packages/js-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/i18n/reverseTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" };
}

Expand Down
24 changes: 14 additions & 10 deletions packages/types/surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit f93c5b3

Please sign in to comment.