This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/utils/dom-utils-test.js
Jarek Radosz 263cd02a27
DEV: Get rid of all discourseModule uses (#19576)
QUnit's `module` and `setupTest` is the way
2022-12-22 13:13:28 +01:00

34 lines
1.0 KiB
JavaScript

import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { hbs } from "ember-cli-htmlbars";
import domUtils from "discourse-common/utils/dom-utils";
import { module, test } from "qunit";
import { render } from "@ember/test-helpers";
module("Unit | Utils | dom-utils", function (hooks) {
setupRenderingTest(hooks);
test("offset", async function (assert) {
await render(hbs`<DButton @translatedLabel="baz" />`);
const element = document.querySelector(".btn");
const offset = domUtils.offset(element);
const rect = element.getBoundingClientRect();
assert.deepEqual(offset, {
top: rect.top + window.scrollY,
left: rect.left + window.scrollX,
});
});
test("position", async function (assert) {
await render(hbs`<DButton @translatedLabel="baz" />`);
const element = document.querySelector(".btn");
const position = domUtils.position(element);
assert.deepEqual(position, {
top: element.offsetTop,
left: element.offsetLeft,
});
});
});