Skip to content

Commit

Permalink
MAT-7792: Fix test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Dec 10, 2024
1 parent 747f2f1 commit 80e5b1c
Showing 1 changed file with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,147 @@ describe("CQL Function Builder Tests", () => {
)) as HTMLInputElement;
expect(definitionName.value).toBe("IP");
});

it("should call handleApplyFunction with a function that we've created through the UI when other is selected.", async () => {
const handleApplyFn = jest.fn();
render(
<FunctionBuilder
canEdit={true}
handleApplyFunction={handleApplyFn}
cqlBuilderLookupsTypes={cqlBuilderLookup}
/>
);
// name, insert, except args
const functionNameInput = (await screen.findByTestId(
"function-name-text-input"
)) as HTMLInputElement;
const argumentsSection = screen.getByTestId(
"terminology-section-Arguments-sub-heading"
);
expect(functionNameInput).toBeInTheDocument();
expect(functionNameInput.value).toBe("");
fireEvent.change(functionNameInput, {
target: { value: "IP" },
});
expect(functionNameInput.value).toBe("IP");

const definitionCommentTextBox = await screen.findByRole("textbox", {
name: "Comment",
});
expect(definitionCommentTextBox).toBeInTheDocument();
const definitionCommentInput = (await screen.findByTestId(
"function-comment-text"
)) as HTMLInputElement;
expect(definitionCommentInput.value).toBe("");
fireEvent.change(definitionCommentInput, {
target: { value: "comment" },
});
expect(definitionCommentInput.value).toBe("comment");

expect(
screen.getByTestId("terminology-section-Expression Editor-sub-heading")
).toBeInTheDocument();
const typeInput = screen.getByTestId(
"type-selector-input"
) as HTMLInputElement;
expect(typeInput).toBeInTheDocument();
expect(typeInput.value).toBe("");

fireEvent.change(typeInput, {
target: { value: "Timing" },
});
expect(typeInput.value).toBe("Timing");

const nameAutoComplete = screen.getByTestId("name-selector");
expect(nameAutoComplete).toBeInTheDocument();
const nameComboBox = within(nameAutoComplete).getByRole("combobox");
//name dropdown is populated with values based on type
await waitFor(() => expect(nameComboBox).toBeEnabled());

const nameDropDown = await screen.findByTestId("name-selector");
fireEvent.keyDown(nameDropDown, { key: "ArrowDown" });

const nameOptions = await screen.findAllByRole("option");
expect(nameOptions).toHaveLength(70);
const insertBtn = screen.getByTestId("expression-insert-btn");

expect(insertBtn).toBeInTheDocument();
expect(insertBtn).toBeDisabled();

fireEvent.click(nameOptions[0]);
expect(insertBtn).toBeEnabled();

fireEvent.click(insertBtn);
const definitionName = (await screen.findByTestId(
"function-name-text-input"
)) as HTMLInputElement;
expect(definitionName.value).toBe("IP");
// args
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 dataTypeDropdown = await screen.findByTestId(
"arg-type-selector-input"
);
fireEvent.change(dataTypeDropdown, {
target: { value: "Other" },
});

// we now need to populate other textfield
const otherNameInput = (await screen.findByTestId(
"other-type-input"
)) as HTMLInputElement;
expect(otherNameInput).toBeInTheDocument();
expect(otherNameInput.value).toBe("");
fireEvent.change(otherNameInput, {
target: { value: "Other" },
});
expect(otherNameInput.value).toBe("Other");

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");
// submit
const submitButton = screen.getByTestId("function-apply-btn");
expect(submitButton).toBeEnabled();
fireEvent.click(submitButton);

await waitFor(() => {
expect(handleApplyFn).toHaveBeenCalledWith(
expect.objectContaining({
comment: "comment",
expressionValue: "after",
fluentFunction: true,
functionName: "IP",
functionsArguments: [
expect.objectContaining({
argumentName: "Test",
dataType: "Other",
}),
],
})
);
});
});
it("should call handleApplyFunction with a function that we've created through the UI", async () => {
const handleApplyFn = jest.fn();
render(
Expand Down

0 comments on commit 80e5b1c

Please sign in to comment.