Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-7791: add more tests for table #402

Merged
merged 2 commits into from
Dec 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,24 @@
header: "",
accessorKey: "arrows",
cell: (row: any) => {
return (
<div className="arrow-container">
<button
onClick={() => moveItem(row.row.index, row.row.index - 1)}
>
<ArrowDropUpOutlinedIcon />
</button>
<button
onClick={() => moveItem(row.row.index, row.row.index + 1)}
>
<ArrowDropDownOutlinedIcon />
</button>
</div>
);
if (functionArguments?.length > 1) {
return (

Check warning on line 162 in src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx

View check run for this annotation

Codecov / codecov/patch

src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx#L162

Added line #L162 was not covered by tests
<div className="arrow-container">
<button
onClick={() => moveItem(row.row.index, row.row.index - 1)}

Check warning on line 165 in src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx

View check run for this annotation

Codecov / codecov/patch

src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx#L165

Added line #L165 was not covered by tests
>
<ArrowDropUpOutlinedIcon />
</button>
<button
onClick={() => moveItem(row.row.index, row.row.index + 1)}

Check warning on line 170 in src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx

View check run for this annotation

Codecov / codecov/patch

src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx#L170

Added line #L170 was not covered by tests
>
<ArrowDropDownOutlinedIcon />
</button>
</div>
);
} else {
return <></>;
}
},
},
{
Expand All @@ -191,11 +195,10 @@
<ToolTippedIcon
tooltipMessage="Delete"
buttonProps={{
"data-testid": `delete-button-${row.id}`,
"aria-label": `delete-button-${row.id}`,
"data-testid": `delete-button-${row.row.id}`,
"aria-label": `delete-button-${row.row.id}`,
size: "small",
onClick: () => {
// const rowModal = table.getRow(row.id).original;
setSelectedArgument({
argumentName: row.row.original.name,
dataType: row.row.original.datatype,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,89 @@ describe("CQL Function Builder Tests", () => {
fireEvent.click(confirmClearButton);
expect(argumentNameInput.value).toBe("");
});

it("Should add argument to the table", async () => {
render(<FunctionBuilder canEdit={true} handleApplyFunction={jest.fn()} />);
const functionNameInput = (await screen.findByTestId(
"function-name-text-input"
)) as HTMLInputElement;
const argumentsSection = screen.getByTestId(
"terminology-section-Arguments-sub-heading"
);
const argumentSectionButton = await within(argumentsSection).findByRole(
"button"
);
fireEvent.click(argumentSectionButton);

const argumentNameInput = (await screen.findByTestId(
"argument-name-input"
)) as HTMLInputElement;
expect(argumentNameInput).toBeInTheDocument();
expect(argumentNameInput.value).toBe("");
fireEvent.change(argumentNameInput, {
target: { value: "Test" },
});
expect(argumentNameInput.value).toBe("Test");

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

fireEvent.click(addButton);

const functionArgumentTable = screen.getByTestId("function-argument-tbl");
expect(functionArgumentTable).toBeInTheDocument();
const tableRow = functionArgumentTable.querySelector("tbody").children[0];
expect(tableRow.children[1].textContent).toEqual("Test");
});

it("Should delete argument from the table", async () => {
render(<FunctionBuilder canEdit={true} handleApplyFunction={jest.fn()} />);
const functionNameInput = (await screen.findByTestId(
"function-name-text-input"
)) as HTMLInputElement;
const argumentsSection = screen.getByTestId(
"terminology-section-Arguments-sub-heading"
);
const argumentSectionButton = await within(argumentsSection).findByRole(
"button"
);
fireEvent.click(argumentSectionButton);

const argumentNameInput = (await screen.findByTestId(
"argument-name-input"
)) as HTMLInputElement;
expect(argumentNameInput).toBeInTheDocument();
expect(argumentNameInput.value).toBe("");
fireEvent.change(argumentNameInput, {
target: { value: "Test" },
});
expect(argumentNameInput.value).toBe("Test");

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

fireEvent.click(addButton);

const functionArgumentTable = screen.getByTestId("function-argument-tbl");
expect(functionArgumentTable).toBeInTheDocument();
const tableRow = functionArgumentTable.querySelector("tbody").children[0];
expect(tableRow.children[1].textContent).toEqual("Test");
const deleteArgumentButton = await within(tableRow).findByTestId(
"delete-button-0"
);
fireEvent.click(deleteArgumentButton);

const confirmDeleteButton = screen.getByTestId(
"delete-dialog-continue-button"
);
expect(confirmDeleteButton).toBeEnabled();
fireEvent.click(confirmDeleteButton);
const newTableRow =
functionArgumentTable.querySelector("tbody").children[0];
expect(newTableRow.children[0].textContent).toEqual(
"No Results were found"
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function FunctionBuilder({
const deleteArgumentFromFunctionArguments = (fn) => {
const newArgs = formik.values.functionsArguments.filter(
(argument) =>
argument?.argumentName !== fn.argumentName &&
argument?.argumentName !== fn.argumentName ||
argument?.dataType !== fn.dataType
);
formik.setFieldValue("functionsArguments", newArgs);
Expand Down
Loading