Skip to content

Commit

Permalink
test: Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
NriotHrreion committed Sep 8, 2024
1 parent e5b719f commit 4681cbc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/test/linkedNodes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe("linked-nodes-tests", () => {

it("create-linked-nodes-from-array", () => {
expect(nodes.toArray()).toStrictEqual([1, 2, 3, "Hello", true]);
expect(nodes.length).toBe(5);
});

it("is-linked-nodes-empty", () => {
Expand Down
10 changes: 10 additions & 0 deletions src/ui/hoverWidget/hoverWidget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ describe("hover-widget-provider-tests", () => {
expect(hoverWidget.text).toBe("test 1");
expect(hoverWidget.id).toBeDefined();
expect(document.getElementById("hover-widget-provider").childNodes.length).toBe(1);

hoverWidget.text = "changed text";

expect(hoverWidget.text).toBe("changed text");
expect(document.getElementById("hover-widget-content").textContent).toBe("changed text");
});

it("create-text-hover-widget-with-title", () => {
Expand All @@ -62,6 +67,11 @@ describe("hover-widget-provider-tests", () => {
expect(hoverWidgetWithTitle.title).toBe("Test Title");
expect(hoverWidgetWithTitle.id).toBeDefined();
expect(document.getElementById("hover-widget-provider").childNodes.length).toBe(2);

hoverWidgetWithTitle.title = "changed title";

expect(hoverWidgetWithTitle.title).toBe("changed title");
expect(document.getElementById("hover-widget-title").textContent).toBe("changed title");
});

it("clear-hover-widgets", () => {
Expand Down
24 changes: 21 additions & 3 deletions src/ui/modal/modal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,43 @@ describe("modal-component-tests", () => {
it("modal-properties", () => {
expect(modal.element.classList.contains("modal-dialog")).toBeTruthy();
expect(modal.element.id).toBe("test");
expect(modal.element.open).toBeFalsy();
expect(modal.element.classList.contains("opened")).toBeFalsy();
});

it("modal-content", () => {
expect(modal.element.querySelector("h1").textContent).toBe("Test Modal");
expect(modal.element.querySelector("footer").childNodes.length).toBe(1);

expect(modal.element.querySelector("footer").childNodes.length).toBe(2);
expect(document.getElementById("modal.test.test-btn").textContent).toBe("Test Footer Button");
});

it("modal-show", () => {
expect(modal.element.open).toBeFalsy();
expect(modal.element.classList.contains("opened")).toBeFalsy();
let counter = 0;

modal.onShow(() => {
counter++;
});

modal.show();

expect(modal.element.open).toBeTruthy();
expect(modal.element.classList.contains("opened")).toBeTruthy();
expect(counter).toBe(1);
});

it("modal-close", () => {
let counter = 0;

modal.onClose(() => {
counter++;
});

modal.close();

expect(modal.element.open).toBeFalsy();
expect(modal.element.classList.contains("opened")).toBeFalsy();
expect(counter).toBe(1);
});

it("modal-dispose", () => {
Expand All @@ -60,6 +75,9 @@ describe("modal-provider-tests", () => {

const modal = modalProvider.getCurrentModal();
expect(modal.element.open).toBeTruthy();

modalProvider.open("test"); // open modal twice times
expect(modal.element.open).toBeTruthy();
});

it("close-all-modals", () => {
Expand Down
8 changes: 7 additions & 1 deletion src/ui/modal/testModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { Modal } from "./modal";
export class TestModal extends Modal {

public constructor(target: ComponentLike) {
super(target, { id: "test", title: "Test Modal" });
if(process.env.NODE_ENV !== "test") {
throw new Error("TestModal can only be used in test environment.");
}

super(target, { id: "test", title: "Test Modal", width: 300, height: 200 });

this._addFooterButton("test-btn", { text: "Test Footer Button" }, () => {});
}
}

0 comments on commit 4681cbc

Please sign in to comment.