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

40 lines
1.1 KiB
JavaScript

import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { hbs } from "ember-cli-htmlbars";
import domUtils from "discourse-common/utils/dom-utils";
discourseModule("utils:dom-utils", function (hooks) {
setupRenderingTest(hooks);
componentTest("offset", {
template: hbs`{{d-button translatedLabel="baz"}}`,
async test(assert) {
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,
});
},
});
componentTest("position", {
template: hbs`{{d-button translatedLabel="baz"}}`,
async test(assert) {
const element = document.querySelector(".btn");
const position = domUtils.position(element);
assert.deepEqual(position, {
top: element.offsetTop,
left: element.offsetLeft,
});
},
});
});