Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DomUtil function tests #7547

Merged
merged 11 commits into from
Apr 15, 2022
Prev Previous commit
Next Next commit
Added setPosition and getPosition tests
  • Loading branch information
LGNorris committed Apr 8, 2021
commit e4ca6e233c11432ed712438a8d54915dac5dfa9f
51 changes: 46 additions & 5 deletions spec/suites/dom/DomUtilSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ describe('DomUtil', function () {
var el;

beforeEach(function () {
el = document.createElement('div');
var el = document.createElement('div');
var input = document.createElement('input');
input.value = 'xxx';
el.style.position = 'absolute';
el.style.top = el.style.left = '-10000px';
document.body.appendChild(el);
document.body.appendChild(input);
});

afterEach(function () {
Expand Down Expand Up @@ -52,7 +55,7 @@ describe('DomUtil', function () {
expect(el.className).to.eql('foo barz');
});
});
describe('#getStyle', function () {
describe('#getStyle', function () {
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
it('gets the value for a certain style attribute on an element,', function () {
el.id = 'testId';
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
el.style.color = 'black';
Expand Down Expand Up @@ -142,7 +145,7 @@ describe('DomUtil', function () {
expect(el.style.opacity).to.equal('0');
});
});

describe('#testProp', function () {
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
it('Check array of style names return first valid style name for element', function () {
expect(L.DomUtil.testProp(['transform'])).to.not.be.ok();
Expand All @@ -168,10 +171,48 @@ describe('DomUtil', function () {
});
});

describe('#setPosition', function () {
describe('#setPosition, #getPosition', function () {
it("Sets position of el to coordinates specified by position.", function () {
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
var position = L.point(100, 100);
expect(L.DomUtil.getStyle(el, 'left')).to.be.equal('-10000px');
expect(L.DomUtil.getStyle(el, 'top')).to.be.equal('-10000px');

var x = 100;
var y = 100;
var position = L.point(x, y);
L.DomUtil.setPosition(el, position);
expect(L.DomUtil.getStyle(el, 'left')).to.be.equal(x + 'px');
expect(L.DomUtil.getStyle(el, 'top')).to.be.equal(y + 'px');

var newX = 333;
var newY = 666;
var newPosition = L.point(newX, newY);
L.DomUtil.setPosition(el, newPosition);
expect(L.DomUtil.getStyle(el, 'left')).to.be.equal(newX + 'px');
expect(L.DomUtil.getStyle(el, 'top')).to.be.equal(newY + 'px');
});

it("Returns position of an element positioned with setPosition.", function () {
var coordinates = {x: 333, y: 666};
var position = L.point(coordinates);
expect(L.DomUtil.getPosition(el)).to.not.eql(coordinates);
L.DomUtil.setPosition(el, position);
expect(L.DomUtil.getPosition(el)).to.be.an('object');
expect(L.DomUtil.getPosition(el)).to.eql(coordinates);
});
});

describe('#disableTextSelection', function () {
it('Disable the selectstart DOM events for the user ', function () {
// var listener = sinon.spy();
// console.log('selectstart' in window)
// L.DomUtil.disableTextSelection()
// console.log('onselectstart' in window)
// // L.DomEvent.on(window, 'selectstart', listener)
// // happen.once(window, {
// // type: "selectstart"
// // })
// // expect(listener.called).to.be.ok()
// L.DomUtil.disableTextSelection()
});
});

Expand Down