Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/visualBuilder/components/__test__/fieldToolbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,89 @@ describe("FieldToolbarComponent", () => {
});
});

describe("Boolean field toolbar", () => {
const booleanSchema = {
data_type: "boolean",
display_name: "Featured",
uid: "featured",
field_metadata: { description: "", default_value: false },
multiple: false,
mandatory: false,
unique: false,
non_localizable: false,
} as unknown as ISchemaFieldMap;

const EDIT_ID =
"visual-builder__focused-toolbar__multiple-field-toolbar__edit-button";

const booleanMetadata: CslpData = {
...mockMultipleFieldMetadata,
fieldPath: "featured",
fieldPathWithIndex: "featured",
multipleFieldMetadata: { index: -1, parentDetails: null },
instance: { fieldPathWithIndex: "featured" },
};

const renderField = async (
schema: ISchemaFieldMap,
fieldMetadata: CslpData
) => {
vi.mocked(FieldSchemaMap.getFieldSchema).mockImplementation(() =>
Promise.resolve(schema)
);
const utils = render(
<FieldToolbarComponent
eventDetails={{ ...mockEventDetails, fieldMetadata }}
hideOverlay={vi.fn()}
/>
);
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
});
return utils;
};

test("boolean field shows the edit button", async () => {
const { container } = await renderField(
booleanSchema,
booleanMetadata
);

expect(
await findByTestId(container, EDIT_ID, {}, { timeout: 1000 })
).toBeInTheDocument();
});

test("edit button is disabled when the boolean field is disabled", async () => {
vi.mocked(isFieldDisabled).mockReturnValue({
isDisabled: true,
reason: "",
} as ReturnType<typeof isFieldDisabled>);
const { container } = await renderField(
booleanSchema,
booleanMetadata
);

expect(
await findByTestId(container, EDIT_ID, {}, { timeout: 1000 })
).toBeDisabled();
});

test("boolean field has no replace button", async () => {
const { container } = await renderField(
booleanSchema,
booleanMetadata
);

await findByTestId(container, EDIT_ID, {}, { timeout: 1000 });
expect(
container.querySelector(
'[data-testid="visual-builder-replace-boolean"]'
)
).not.toBeInTheDocument();
});
});

describe("Taxonomy field toolbar", () => {
const taxonomySchema = {
data_type: "taxonomy",
Expand Down
1 change: 1 addition & 0 deletions src/visualBuilder/components/icons/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export const fieldIcons: Partial<Record<FieldDataType, React.FC>> = {
select: EditIcon,
taxonomy: EditIcon,
tags: EditIcon,
boolean: EditIcon,
};
1 change: 1 addition & 0 deletions src/visualBuilder/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const ALLOWED_MODAL_EDITABLE_FIELD: FieldDataType[] = [
FieldDataType.SELECT,
FieldDataType.TAXONOMY,
FieldDataType.TAGS,
FieldDataType.BOOLEAN,
];

export const ALLOWED_REPLACE_FIELDS: FieldDataType[] = [
Expand Down
Loading