Skip to content

Commit

Permalink
refactor: extract getMiddleOfElement util
Browse files Browse the repository at this point in the history
  • Loading branch information
ogunb committed Nov 19, 2023
1 parent 2eb528f commit 809ddb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/components/tooltip/bl-tooltip.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { assert, elementUpdated, expect, fixture, html, oneEvent } from "@open-wc/testing";
import { sendKeys, sendMouse } from "@web/test-runner-commands";
import { getMiddleOfElement } from "../../utilities/elements";
import type typeOfBlPopover from "../popover/bl-popover";
import BlTooltip from "./bl-tooltip";
import type typeOfBlTooltip from "./bl-tooltip";
import type typeOfBlPopover from "../popover/bl-popover";

describe("bl-tooltip", () => {
it("should be defined tooltip instance", () => {
Expand Down Expand Up @@ -111,7 +112,7 @@ describe("bl-tooltip", () => {
><button slot="tooltip-trigger">Test</button> Test Tooltip</bl-tooltip
>`
);
const tooltip = el.shadowRoot?.querySelector("bl-popover") as HTMLElement;
const tooltip = el.shadowRoot!.querySelector("bl-popover")!;
const trigger = document.querySelector("button") as HTMLElement;
const body = document.querySelector("body") as HTMLElement;

Expand Down Expand Up @@ -202,12 +203,3 @@ describe("bl-tooltip", () => {
expect(el.visible).to.be.false;
});
});

function getMiddleOfElement(element: Element) {
const { x, y, width, height } = element.getBoundingClientRect();

return {
x: Math.floor(x + window.pageXOffset + width / 2),
y: Math.floor(y + window.pageYOffset + height / 2),
};
}
8 changes: 8 additions & 0 deletions src/utilities/elements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function getMiddleOfElement(element: Element) {
const { x, y, width, height } = element.getBoundingClientRect();

return {
x: Math.floor(x + window.pageXOffset + width / 2),
y: Math.floor(y + window.pageYOffset + height / 2),
};
}

0 comments on commit 809ddb4

Please sign in to comment.