Skip to content

Commit

Permalink
fix: Snippet path in preview (calcom#14830)
Browse files Browse the repository at this point in the history
* fix: Snippet path in preview

* Add test
  • Loading branch information
hariombalhara authored May 2, 2024
1 parent 52813b0 commit 6c8fced
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/embeds/embed-core/playwright/tests/preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from "@playwright/test";
import { test } from "@calcom/web/playwright/lib/fixtures";

test.describe("Preview", () => {
test("Preview - embed-core should load", async ({ page }) => {
test("Preview - embed-core should load if correct embedLibUrl is provided", async ({ page }) => {
await page.goto(
"http://localhost:3000/embed/preview.html?embedLibUrl=http://localhost:3000/embed/embed.js&bookerUrl=http://localhost:3000&calLink=pro/30min"
);
Expand All @@ -26,4 +26,20 @@ test.describe("Preview", () => {
});
expect(libraryLoaded).toBe(true);
});

test("Preview - embed-core should load from embedLibUrl", async ({ page }) => {
// Intentionally pass a URL that will not load to be able to easily test that the embed was loaded from there
page.goto(
"http://localhost:3000/embed/preview.html?embedLibUrl=http://wronglocalhost:3000/embed/embed.js&bookerUrl=http://localhost:3000&calLink=pro/30min"
);

const failedRequestUrl = await new Promise<string>((resolve) =>
page.on("requestfailed", (request) => {
console.log("request failed");
resolve(request.url());
})
);

expect(failedRequestUrl).toBe("http://wronglocalhost:3000/embed/embed.js");
});
});
2 changes: 1 addition & 1 deletion packages/embeds/embed-core/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if (!bookerUrl || !embedLibUrl) {
}
p(cal, ar);
};
})(window, "//localhost:3000/embed/embed.js", "init");
})(window, embedLibUrl, "init");
const previewWindow = window;
previewWindow.Cal.fingerprint = process.env.EMBED_PUBLIC_EMBED_FINGER_PRINT as string;

Expand Down

0 comments on commit 6c8fced

Please sign in to comment.