Skip to content

Commit

Permalink
util unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
binrysearch committed Sep 9, 2024
1 parent 62af205 commit d68ed0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/util/elementInViewport.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import _createElement from "./createElement";
import van from "../packages/dom/van";
import elementInViewport from "./elementInViewport";

const {div} = van.tags;

describe("elementInViewport", () => {
test("should return true when element is in viewport", () => {
// Arrange
Expand All @@ -13,7 +15,7 @@ describe("elementInViewport", () => {
right: 50,
} as DOMRect)
);
const elm = _createElement("div");
const elm = div();
elm.getBoundingClientRect = getBoundingClientRectSpy;

// Act
Expand All @@ -34,7 +36,7 @@ describe("elementInViewport", () => {
right: 50,
} as DOMRect)
);
const elm = _createElement("div");
const elm = div();
elm.getBoundingClientRect = getBoundingClientRectSpy;

// Act
Expand All @@ -55,7 +57,7 @@ describe("elementInViewport", () => {
right: window.innerWidth + 50,
} as DOMRect)
);
const elm = _createElement("div");
const elm = div();
elm.getBoundingClientRect = getBoundingClientRectSpy;

// Act
Expand All @@ -76,7 +78,7 @@ describe("elementInViewport", () => {
right: 50,
} as DOMRect)
);
const elm = _createElement("div");
const elm = div();
elm.getBoundingClientRect = getBoundingClientRectSpy;

// Act
Expand All @@ -97,7 +99,7 @@ describe("elementInViewport", () => {
right: 50,
} as DOMRect)
);
const elm = _createElement("div");
const elm = div();
elm.getBoundingClientRect = getBoundingClientRectSpy;

// Act
Expand Down
18 changes: 10 additions & 8 deletions src/util/positionRelativeTo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { setPositionRelativeTo } from "./positionRelativeTo";
import createElement from "./createElement";
import { getBoundingClientRectSpy } from "../../tests/jest/helper";
import van from "../packages/dom/van"

const {div} = van.tags;

describe("setPositionRelativeTo", () => {
it("should return if helperLayer or currentStep is null", () => {
Expand All @@ -18,7 +20,7 @@ describe("setPositionRelativeTo", () => {

it("should set the correct width, height, top, left", () => {
// Arrange
const stepElement = createElement("div");
const stepElement = div();
stepElement.getBoundingClientRect = getBoundingClientRectSpy(
200,
100,
Expand All @@ -28,7 +30,7 @@ describe("setPositionRelativeTo", () => {
100
);

const helperLayer = createElement("div");
const helperLayer = div();
helperLayer.getBoundingClientRect = getBoundingClientRectSpy(
500,
500,
Expand All @@ -50,12 +52,12 @@ describe("setPositionRelativeTo", () => {

it("should add fixedTooltip if element is fixed", () => {
// Arrange
const stepElementParent = createElement("div");
const stepElement = createElement("div");
const stepElementParent = div();
const stepElement = div();
stepElement.style.position = "fixed";
stepElementParent.appendChild(stepElement);

const helperLayer = createElement("div");
const helperLayer = div();

// Act
setPositionRelativeTo(stepElementParent, helperLayer, stepElement, 10);
Expand All @@ -66,10 +68,10 @@ describe("setPositionRelativeTo", () => {

it("should remove the fixedTooltip className if element is not fixed", () => {
// Arrange
const stepElement = createElement("div");
const stepElement = div();
stepElement.style.position = "absolute";

const helperLayer = createElement("div");
const helperLayer = div();
helperLayer.className = "introjs-fixedTooltip";

// Act
Expand Down

0 comments on commit d68ed0a

Please sign in to comment.