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
Fix linting errors
  • Loading branch information
LGNorris committed Apr 9, 2021
commit cfc3bc56fdbb246824b3bbbc5487996b2aa82439
66 changes: 33 additions & 33 deletions spec/suites/dom/DomUtilSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe('DomUtil', function () {
var childEl = document.createElement('div');
el.appendChild(parentEl);
parentEl.appendChild(childEl);
expect(L.DomUtil.getSizedParentNode(childEl)).to.not.eql(parentEl)
expect(L.DomUtil.getSizedParentNode(childEl)).to.not.eql(parentEl);
parentEl.style.width = '150px';
parentEl.style.height = '150px';
expect(L.DomUtil.getSizedParentNode(childEl)).to.eql(parentEl);
Expand All @@ -216,8 +216,8 @@ describe('DomUtil', function () {
var childEl = document.createElement('div');
el.appendChild(childEl);
var scale = {
x: 1,
y: 1,
x: 1,
y: 1,
boundingClientRect: {
left: 25,
right: 305,
Expand All @@ -226,63 +226,63 @@ describe('DomUtil', function () {
bottom: 305,
width: 280
}
}
};
childEl.style.width = '250px';
childEl.style.height = '250px';
childEl.style.padding = '15px';
childEl.style.margin = '25px';
expect(L.DomUtil.getScale(childEl)).to.eql(scale)
expect(L.DomUtil.getScale(childEl)).to.eql(scale);
childEl.style.padding = '400px';
expect(L.DomUtil.getScale(childEl)).to.not.eql(scale)
})
expect(L.DomUtil.getScale(childEl)).to.not.eql(scale);
});
});


describe('#disableTextSelection, #enableTextSelection', function () {
it('Disable / enable the selectstart DOM events for the user ', function () {
var selectionPrevented;
function checkPrevented(e) {
if(e.defaultPrevented) {
selectionPrevented = true
if (e.defaultPrevented) {
selectionPrevented = true;
} else {
selectionPrevented = false
selectionPrevented = false;
}
}
var child = document.createElement('div');
el.appendChild(child);

L.DomUtil.disableTextSelection()
window.addEventListener('selectstart', checkPrevented)
L.DomUtil.disableTextSelection();
window.addEventListener('selectstart', checkPrevented);
happen.once(child, {type: 'selectstart'});
expect(selectionPrevented).to.be.ok()
expect(selectionPrevented).to.be.ok();

L.DomUtil.enableTextSelection();
happen.once(child, {type: 'selectstart'});
expect(selectionPrevented).to.not.be.ok()
expect(selectionPrevented).to.not.be.ok();
});
});

describe('#disableImageDrag, #enablerImageDrag', function () {
it('Disable / enable dragstart DOM events for the user', function () {
var selectionPrevented;
function checkPrevented(e) {
if(e.defaultPrevented) {
selectionPrevented = true
if (e.defaultPrevented) {
selectionPrevented = true;
} else {
selectionPrevented = false
selectionPrevented = false;
}
}
var child = document.createElement('div');
el.appendChild(child);

L.DomUtil.disableImageDrag()
window.addEventListener('dragstart', checkPrevented)
L.DomUtil.disableImageDrag();
window.addEventListener('dragstart', checkPrevented);
happen.once(child, {type: 'dragstart'});
expect(selectionPrevented).to.be.ok()
expect(selectionPrevented).to.be.ok();

L.DomUtil.enableImageDrag();
happen.once(child, {type: 'dragstart'});
expect(selectionPrevented).to.not.be.ok()
expect(selectionPrevented).to.not.be.ok();
});
});

Expand All @@ -293,20 +293,20 @@ describe('DomUtil', function () {
child.tabIndex = 0;
child.style.outline = 'solid';

expect(child.style.outline).to.be.equal('solid')
L.DomUtil.preventOutline(child)
expect(child.style.outline).to.be.equal('none')
expect(child.style.outline).to.be.equal('solid');
L.DomUtil.preventOutline(child);
expect(child.style.outline).to.be.equal('none');

//Explicit #restoreOutline through direct call
expect(child.style.outline).to.be.equal('none')
L.DomUtil.restoreOutline(child)
expect(child.style.outline).to.be.equal('solid')
// Explicit #restoreOutline through direct call
expect(child.style.outline).to.be.equal('none');
L.DomUtil.restoreOutline(child);
expect(child.style.outline).to.be.equal('solid');

//Implicit #restoreOutline test through simulation
L.DomUtil.preventOutline(child)
expect(child.style.outline).to.be.equal('none')
happen.once(child, { type: 'keydown'})
expect(child.style.outline).to.be.equal('solid')
// Implicit #restoreOutline test through simulation
L.DomUtil.preventOutline(child);
expect(child.style.outline).to.be.equal('none');
happen.once(child, {type: 'keydown'});
expect(child.style.outline).to.be.equal('solid');
});
});
});