Skip to content

Commit

Permalink
MAT-7792: Add further code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Dec 3, 2024
1 parent 254958e commit 489a495
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { within } from "@testing-library/dom";
import "@testing-library/jest-dom";
import FunctionBuilder from "./FunctionBuilder";
import { cqlBuilderLookup } from "../../__mocks__/MockCqlBuilderLookupsTypes";
import { getNewExpressionsAndLines } from "../../common/utils";

describe("CQL Function Builder Tests", () => {
it("Should display name and comment fields", async () => {
Expand Down Expand Up @@ -225,3 +226,38 @@ describe("CQL Function Builder Tests", () => {
expect(definitionName.value).toBe("IP");
});
});

describe("getNewExpressionsAndLines", () => {
it("should insert the formatted expression at the cursor position when cursorPosition is provided and autoInsert is false", () => {
const values = { name: "test", type: "Functions" };
const cursorPosition = { row: 1, column: 5 };
const expressionEditorValue = "Line 1\ntesttesttest2 content\nLine 3";
const autoInsert = false;
const result = getNewExpressionsAndLines(
values,
cursorPosition,
expressionEditorValue,
autoInsert
);

expect(result[0]).toBe("Line 1\ntestttestesttest2 content\nLine 3");
expect(result[1]).toEqual({ row: 1, column: 9 });
});

it("should append the formatted expression to a new line when cursorPosition is not provided or autoInsert is true", () => {
const values = { name: "test", type: "Functions" };
const cursorPosition = null;
const expressionEditorValue = "Line 1\nLine 2 content\nLine 3";
const autoInsert = true;

const result = getNewExpressionsAndLines(
values,
cursorPosition,
expressionEditorValue,
autoInsert
);

expect(result[0]).toBe("Line 1\nLine 2 content\nLine 3\ntest");
expect(result[1]).toEqual({ row: 3, column: 4 });
});
});

0 comments on commit 489a495

Please sign in to comment.