Skip to content

Commit

Permalink
MAT-7791: add more tests for table (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
chubert-sb authored Dec 6, 2024
1 parent ac5c792 commit 419886b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 18 deletions.
37 changes: 20 additions & 17 deletions src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,24 @@ const Arguments = ({
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 (
<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>
);
} else {
return <></>;
}
},
},
{
Expand All @@ -191,11 +195,10 @@ const Arguments = ({
<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

0 comments on commit 419886b

Please sign in to comment.