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 a few more tests for the DomUtil functions
  • Loading branch information
LGNorris committed Apr 3, 2021
commit fb2f77f3fb98e66f461a989df83ec4b590b82644
49 changes: 49 additions & 0 deletions spec/suites/dom/DomUtilSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,55 @@ describe('DomUtil', function () {
});
});

describe('#toFront, #toBack', function () {
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(function () {
L.DomUtil.create('div', 'childContainer', el);
L.DomUtil.create('h1', 'childh1', el);
L.DomUtil.create('p', 'childp', el);
});
it('Moves el to last child position parent element', function () {
el.id = 'testId';
expect(el.children.length).to.equal(3);
expect(Array.from(el.children).indexOf(document.querySelector('.childContainer') === 0));
L.DomUtil.toFront(el.children[0]);
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
expect(Array.from(el.children).indexOf(document.querySelector('.childContainer') === 2));
});
it('Moves el to first child position parent element', function () {
el.id = 'testId';
expect(el.children.length).to.equal(3);
expect(Array.from(el.children).indexOf(document.querySelector('.childp') === 2));
L.DomUtil.toFront(el.children[0]);
expect(Array.from(el.children).indexOf(document.querySelector('.childp') === 0));
});
});

describe('#setClass, #getClass', function () {
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
it('Sets the elements class', function () {
el.id = 'testId';
expect(el.classList.contains('newClass')).to.not.be.ok();
L.DomUtil.setClass(el, 'newClass');
expect(el.classList.contains('newClass')).to.be.ok();
});
it('Gets the elements class', function () {
el.id = 'testId';
expect(L.DomUtil.getClass(el)).to.not.equal('newClass');
L.DomUtil.setClass(el, 'newClass');
expect(L.DomUtil.getClass(el)).to.equal('newClass');
});
});

describe('#setOpacity', function () {
it('Sets opacity of element', function () {
el.id = 'testId';
L.DomUtil.setOpacity(el, 1);
expect(el.style.opacity).to.equal('1');
L.DomUtil.setOpacity(el, 0.5);
expect(el.style.opacity).to.equal('0.5');
L.DomUtil.setOpacity(el, '0');
expect(el.style.opacity).to.equal('0');
});
});

// describe('#setPosition', noSpecs);

// describe('#getStyle', noSpecs);
Expand Down