Skip to content

Commit

Permalink
MAT-8111 fixed argument button is enabled when there is no data type
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-prateekkeerthi committed Jan 10, 2025
1 parent 7ce86ed commit aa0a8f7
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ArgumentsProps {
functionArguments?: FunctionArgument[];
canEdit: boolean;
addArgumentToFunctionsArguments: Function;
isFluentFunction: boolean;
deleteArgumentFromFunctionArguments: Function;
dirty: boolean;
}
Expand All @@ -43,6 +44,7 @@ export default function ArgumentSection(props: ArgumentsProps) {
addArgumentToFunctionsArguments,
deleteArgumentFromFunctionArguments,
functionArguments,
isFluentFunction,
canEdit,
dirty,
} = props;
Expand Down Expand Up @@ -84,6 +86,9 @@ export default function ArgumentSection(props: ArgumentsProps) {
<div tw="flex flex-wrap">
<div tw="w-1/2">
<TextField
required={
isFluentFunction || formik.values.dataType ? "required" : ""
}
label="Name"
id="argument-name-field"
name="argumentName"
Expand All @@ -101,6 +106,7 @@ export default function ArgumentSection(props: ArgumentsProps) {
</div>
<div tw="flex-grow pl-5">
<Select
required={formik.values.argumentName ? "required" : ""}
label="Available DataTypes"
id="arg-type-selector"
inputProps={{
Expand Down Expand Up @@ -169,7 +175,13 @@ export default function ArgumentSection(props: ArgumentsProps) {
</Button>
<Button
data-testid={`function-argument-add-btn`}
disabled={!canEdit || !formik.isValid || !formik.dirty}
disabled={
!canEdit ||
!formik.isValid ||
!formik.dirty ||
!formik.values.argumentName ||
!formik.values.dataType
}
onClick={handleSubmit}
>
Add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,17 @@ describe("CQL Function Builder Tests", () => {
expect(clearButton).toBeInTheDocument();
expect(clearButton).toBeEnabled();

const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeInTheDocument();
expect(addButton).toBeEnabled();
const dataTypeDropdown = await screen.findByTestId(
"arg-type-selector-input"
);
fireEvent.change(dataTypeDropdown, {
target: { value: "Boolean" },
});

await waitFor(() => {
const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeEnabled();
});

fireEvent.click(clearButton);

Expand Down Expand Up @@ -267,12 +275,18 @@ describe("CQL Function Builder Tests", () => {
});
expect(argumentNameInput.value).toBe("Test");

const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeInTheDocument();
expect(addButton).toBeEnabled();

fireEvent.click(addButton);
const dataTypeDropdown = await screen.findByTestId(
"arg-type-selector-input"
);
fireEvent.change(dataTypeDropdown, {
target: { value: "Boolean" },
});

await waitFor(() => {
const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeEnabled();
fireEvent.click(addButton);
});
const functionArgumentTable = screen.getByTestId("function-argument-tbl");
expect(functionArgumentTable).toBeInTheDocument();
await waitFor(() => {
Expand Down Expand Up @@ -314,11 +328,18 @@ describe("CQL Function Builder Tests", () => {
});
expect(argumentNameInput.value).toBe("Test");

const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeInTheDocument();
expect(addButton).toBeEnabled();
const dataTypeDropdown = await screen.findByTestId(
"arg-type-selector-input"
);
fireEvent.change(dataTypeDropdown, {
target: { value: "Boolean" },
});

fireEvent.click(addButton);
await waitFor(() => {
const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeEnabled();
fireEvent.click(addButton);
});

const functionArgumentTable = screen.getByTestId("function-argument-tbl");
expect(functionArgumentTable).toBeInTheDocument();
Expand Down Expand Up @@ -710,12 +731,11 @@ describe("CQL Function Builder Tests", () => {
target: { value: "Boolean" },
});

const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeInTheDocument();
expect(addButton).toBeEnabled();
// get available dataTypes 0

fireEvent.click(addButton);
await waitFor(() => {
const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeEnabled();
fireEvent.click(addButton);
});

const functionArgumentTable = screen.getByTestId("function-argument-tbl");
expect(functionArgumentTable).toBeInTheDocument();
Expand Down Expand Up @@ -832,11 +852,11 @@ describe("CQL Function Builder Tests", () => {
target: { value: "Boolean" },
});

const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeInTheDocument();
expect(addButton).toBeEnabled();

fireEvent.click(addButton);
await waitFor(() => {
const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeEnabled();
fireEvent.click(addButton);
});

const functionArgumentTable = screen.getByTestId("function-argument-tbl");
expect(functionArgumentTable).toBeInTheDocument();
Expand Down Expand Up @@ -940,13 +960,11 @@ describe("CQL Function Builder Tests", () => {
fireEvent.change(dataTypeDropdown, {
target: { value: "Boolean" },
});

const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeInTheDocument();
expect(addButton).toBeEnabled();

fireEvent.click(addButton);

await waitFor(() => {
const addButton = screen.getByTestId("function-argument-add-btn");
expect(addButton).toBeEnabled();
fireEvent.click(addButton);
});
const functionArgumentTable = screen.getByTestId("function-argument-tbl");
expect(functionArgumentTable).toBeInTheDocument();
const tableRow = functionArgumentTable.querySelector("tbody").children[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export default function FunctionBuilder({
}
dirty={dirty}
functionArguments={formik.values.functionsArguments}
isFluentFunction={formik.values.fluentFunction}
/>
</ExpandingSection>

Expand Down
34 changes: 30 additions & 4 deletions src/validations/FunctionArgumentSchemaValidator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
import * as Yup from "yup";

export const FunctionArgumentSchemaValidator = Yup.object().shape({
argumentName: Yup.string().matches(
/^(?!\s+$)[a-zA-Z0-9_ ]+$/,
"No spaces or special characters besides underscore are allowed"
argumentName: Yup.string()
.matches(
/^(?!\s+$)[a-zA-Z0-9_ ]+$/,
"No spaces or special characters besides underscore are allowed"
)
.test("argumentName", "Argument Name is required", function (value) {
const { dataType } = this.parent;
if (
dataType &&
dataType.trim() !== "" &&
(!value || value.trim() === "")
) {
return false;
}
return true;
}),
dataType: Yup.string().test(
"dataType",
"Data Type is required",
function (value) {
const { argumentName } = this.parent;
if (
argumentName &&
argumentName.trim() !== "" &&
(!value || value.trim() === "")
) {
return false;
}
return true;
}
),
dataType: Yup.string(),
other: Yup.string().when("dataType", {
is: (value: any) => value === "Other",
then: (schema) =>
Expand Down

0 comments on commit aa0a8f7

Please sign in to comment.