Skip to content

Commit

Permalink
chore(e2e): fix playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Tarca authored and matejtarca committed Oct 15, 2023
1 parent 0236728 commit b2ba9a6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
22 changes: 13 additions & 9 deletions e2e/applicationForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ test.describe("application form", () => {
await page
.getByLabel("Label")
.fill("What is your experience with hackathons?");
await page.getByLabel("Name").fill("experience");
await page.getByText("Select a field type").click();
await page.getByText("textarea").click();
await page.getByLabel("Required field").check();
await page.getByRole("button", { name: "Add new field" }).click();
await page.getByLabel("textarea").getByText("textarea").click();
await page.getByLabel("Required").check();
await page.getByRole("button", { name: "Create new field" }).click();

await expect(
page.getByText("1. What is your experience with hackathons? (textarea)")
Expand All @@ -84,19 +85,21 @@ test.describe("application form", () => {
await page
.getByLabel("Label")
.fill("I have been at the hackathon in the past.");
await page.getByLabel("Name").fill("hackathonsPast");
await page.getByText("Select a field type").click();
await page.getByText("checkbox").click();
await page.getByRole("button", { name: "Add new field" }).click();
await page.getByLabel("checkbox").getByText("checkbox").click();
await page.getByRole("button", { name: "Create new field" }).click();

await expect(
page.getByText("2. I have been at the hackathon in the past. (checkbox)")
).toBeVisible();

await page.getByRole("button", { name: "Create new field" }).click();
await page.getByLabel("Label").fill("What company do you work for?");
await page.getByLabel("Name").fill("company");
await page.getByText("Select a field type").click();
await page.getByText("text").click();
await page.getByRole("button", { name: "Add new field" }).click();
await page.getByLabel("text", { exact: true }).getByText("text").click();
await page.getByRole("button", { name: "Create new field" }).click();

await expect(
page.getByText("3. What company do you work for? (text)")
Expand All @@ -113,9 +116,10 @@ test.describe("application form", () => {
await page
.getByLabel("Label")
.fill("I have been at the hackathon in the past.");
await page.getByLabel("Name").fill("hackathonsPast");
await page.getByText("Select a field type").click();
await page.getByText("checkbox").click();
await page.getByRole("button", { name: "Add new field" }).click();
await page.getByLabel("checkbox").getByText("checkbox").click();
await page.getByRole("button", { name: "Create new field" }).click();

await expect(
page.getByText("3. I have been at the hackathon in the past. (checkbox)")
Expand Down
3 changes: 2 additions & 1 deletion src/scenes/ApplicationFormStep/components/FormRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const getDefaultValues = (
return Object.fromEntries(
formFields.map((formField) => {
const initialValue = shouldUseLocalInitialValues
? getLocalApplicationFieldData(formField.id)?.value ?? null
? getLocalApplicationFieldData(formField.id, formField.type)?.value ??
null
: formField.initialValue;
switch (formField.type) {
case FormFieldTypeEnum.text:
Expand Down
15 changes: 12 additions & 3 deletions src/services/helpers/localData/getLocalApplicationFieldData.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LocalApplicationFieldData } from "@/services/helpers/localData/types";
import { LocalApplicationFieldDataParsed } from "@/services/helpers/localData/types";
import getLocalApplicationData from "@/services/helpers/localData/getLocalApplicationData";
import { FormFieldType, FormFieldTypeEnum } from "@/services/types/formFields";

const getLocalApplicationFieldData = (
fieldId: number
): LocalApplicationFieldData | null => {
fieldId: number,
fieldType: FormFieldType
): LocalApplicationFieldDataParsed | null => {
const localApplicationData = getLocalApplicationData();
if (!localApplicationData) {
return null;
Expand All @@ -16,6 +18,13 @@ const getLocalApplicationFieldData = (
return null;
}

if (fieldType === FormFieldTypeEnum.checkbox) {
return {
...matchingField,
value: matchingField.value === "true",
};
}

return matchingField;
};

Expand Down
5 changes: 5 additions & 0 deletions src/services/helpers/localData/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ export type LocalApplicationFieldData = {
};

export type LocalApplicationData = LocalApplicationFieldData[];

export type LocalApplicationFieldDataParsed = {
fieldId: number;
value: string | boolean;
};

0 comments on commit b2ba9a6

Please sign in to comment.