Skip to content

Commit

Permalink
Fix Routing Form tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hariombalhara committed May 12, 2023
1 parent 10fa353 commit e560f1e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion apps/web/public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1808,5 +1808,6 @@
"pop_up_element_click": "Pop up via element click",
"open_dialog_with_element_click": "Open your Cal dialog when someone clicks an element.",
"need_help_embedding": "Need help? See our guides for embedding Cal on Wix, Squarespace, or WordPress, check our common questions, or explore advanced embed options.",
"book_my_cal": "Book my Cal"
"book_my_cal": "Book my Cal",
"form_updated_successfully":"Form updated successfully."
}
3 changes: 3 additions & 0 deletions packages/app-store/routing-forms/components/FormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ export function FormActionsProvider({ appUrl, children }: { appUrl: string; chil
}
return { previousValue };
},
onSuccess: () => {
showToast(t("form_updated_successfully"), "success");
},
onSettled: (routingForm) => {
utils.viewer.appRoutingForms.forms.invalidate();
if (routingForm) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-store/routing-forms/components/SingleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function SingleForm({ form, appUrl, Page }: SingleFormComponentProps) {

const mutation = trpc.viewer.appRoutingForms.formMutation.useMutation({
onSuccess() {
showToast("Form updated successfully.", "success");
showToast(t("form_updated_successfully"), "success");
},
onError(e) {
if (e.message) {
Expand Down
22 changes: 13 additions & 9 deletions packages/app-store/routing-forms/playwright/tests/basic.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test.describe("Routing Forms", () => {
await expect(page.locator("text=Test Form Name")).toBeVisible();

await page.goto(`apps/routing-forms/route-builder/${formId}`);
await page.click('[data-testid="toggle-form"] [value="on"]');
await disableForm(page);
await gotoRoutingLink({ page, formId });
await expect(page.locator("text=ERROR 404")).toBeVisible();
});
Expand All @@ -39,17 +39,18 @@ test.describe("Routing Forms", () => {

const createdFields: Record<number, { label: string; typeIndex: number }> = {};

const { fieldTypesList: types } = await addAllTypesOfFieldsAndSaveForm(formId, page, {
const { fieldTypesList: types, fields } = await addAllTypesOfFieldsAndSaveForm(formId, page, {
description,
label,
});

expect(await page.inputValue(`[data-testid="description"]`)).toBe(description);
expect(await page.locator('[data-testid="field"]').count()).toBe(types.length);

types.forEach((item, index) => {
createdFields[index] = { label: `Test Label ${index + 1}`, typeIndex: index };
fields.forEach((item, index) => {
createdFields[index] = { label: item.label, typeIndex: index };
});

await expectCurrentFormToHaveFields(page, createdFields, types);

await page.click('[href*="/apps/routing-forms/route-builder/"]');
Expand All @@ -62,8 +63,6 @@ test.describe("Routing Forms", () => {
});

test.describe("F1<-F2 Relationship", () => {
// TODO: Fix this test, it is very flaky
// prettier-ignore
test("Create relationship by adding F1 as route.Editing F1 should update F2", async ({ page }) => {
const form1Id = await addForm(page, { name: "F1" });
const form2Id = await addForm(page, { name: "F2" });
Expand Down Expand Up @@ -367,6 +366,11 @@ test.describe("Routing Forms", () => {
});
});

async function disableForm(page: Page) {
await page.click('[data-testid="toggle-form"] [value="on"]');
await page.waitForSelector(".data-testid-toast-success");
}

async function expectCurrentFormToHaveFields(
page: Page,
fields: {
Expand All @@ -384,21 +388,21 @@ async function expectCurrentFormToHaveFields(

async function fillSeededForm(page: Page, routingFormId: string) {
await gotoRoutingLink({ page, formId: routingFormId });
await page.fill('[data-testid="form-field"]', "event-routing");
await page.fill('[data-testid="form-field-Test field"]', "event-routing");
page.click('button[type="submit"]');
await page.waitForURL((url) => {
return url.pathname.endsWith("/pro/30min");
});

await gotoRoutingLink({ page, formId: routingFormId });
await page.fill('[data-testid="form-field"]', "external-redirect");
await page.fill('[data-testid="form-field-Test field"]', "external-redirect");
page.click('button[type="submit"]');
await page.waitForURL((url) => {
return url.hostname.includes("google.com");
});

await gotoRoutingLink({ page, formId: routingFormId });
await page.fill('[data-testid="form-field"]', "custom-page");
await page.fill('[data-testid="form-field-Test field"]', "custom-page");
await page.click('button[type="submit"]');
await expect(page.locator("text=Custom Page Result")).toBeVisible();
}
Expand Down
4 changes: 3 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ if (IS_EMBED_REACT_TEST) {
const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: os.cpus().length,
// While debugging it should be focussed mode
// eslint-disable-next-line turbo/no-undeclared-env-vars
workers: process.env.PWDEBUG ? 1 : os.cpus().length,
timeout: DEFAULT_TEST_TIMEOUT,
maxFailures: headless ? 10 : undefined,
fullyParallel: true,
Expand Down

0 comments on commit e560f1e

Please sign in to comment.