Leaflet/spec/suites/dom/DomUtilSpec.js

60 lines
1.7 KiB
JavaScript
Raw Normal View History

describe('DomUtil', function () {
2010-09-07 22:02:45 +08:00
var el;
2013-02-05 23:01:01 +08:00
beforeEach(function () {
2010-09-07 22:02:45 +08:00
el = document.createElement('div');
el.style.position = 'absolute';
el.style.top = el.style.left = '-10000px';
document.body.appendChild(el);
});
2013-02-05 23:01:01 +08:00
afterEach(function () {
2010-09-07 22:02:45 +08:00
document.body.removeChild(el);
});
2013-02-05 23:01:01 +08:00
describe('#get', function () {
it('gets element by id if the given argument is string', function () {
2010-09-07 22:02:45 +08:00
el.id = 'testId';
2013-03-02 05:49:20 +08:00
expect(L.DomUtil.get(el.id)).to.eql(el);
2010-09-07 22:02:45 +08:00
});
2013-02-05 23:01:01 +08:00
it('returns the element if it is given as an argument', function () {
2013-03-02 05:49:20 +08:00
expect(L.DomUtil.get(el)).to.eql(el);
2010-09-07 22:02:45 +08:00
});
});
2013-02-05 23:01:01 +08:00
describe('#addClass, #removeClass, #hasClass', function () {
it('has defined class for test element', function () {
2011-07-15 20:03:35 +08:00
el.className = 'bar foo baz ';
2013-03-02 05:49:20 +08:00
expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
expect(L.DomUtil.hasClass(el, 'bar')).to.be.ok();
expect(L.DomUtil.hasClass(el, 'baz')).to.be.ok();
expect(L.DomUtil.hasClass(el, 'boo')).to.not.be.ok();
2011-07-15 20:03:35 +08:00
});
2013-02-05 23:01:01 +08:00
it('adds or removes the class', function () {
2011-07-15 20:03:35 +08:00
el.className = '';
L.DomUtil.addClass(el, 'foo');
2013-02-05 23:01:01 +08:00
2013-03-02 05:49:20 +08:00
expect(el.className).to.eql('foo');
expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
2013-02-05 23:01:01 +08:00
2011-07-15 20:03:35 +08:00
L.DomUtil.addClass(el, 'bar');
2013-03-02 05:49:20 +08:00
expect(el.className).to.eql('foo bar');
expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
2013-02-05 23:01:01 +08:00
2011-07-15 20:03:35 +08:00
L.DomUtil.removeClass(el, 'foo');
2013-03-02 05:49:20 +08:00
expect(el.className).to.eql('bar');
expect(L.DomUtil.hasClass(el, 'foo')).to.not.be.ok();
2013-02-05 23:01:01 +08:00
2011-07-15 20:03:35 +08:00
el.className = 'foo bar barz';
L.DomUtil.removeClass(el, 'bar');
2013-03-02 05:49:20 +08:00
expect(el.className).to.eql('foo barz');
});
2011-07-15 20:03:35 +08:00
});
2013-02-05 23:01:01 +08:00
2013-03-02 05:49:20 +08:00
// describe('#setPosition', noSpecs);
2013-02-05 23:01:01 +08:00
2013-03-02 05:49:20 +08:00
// describe('#getStyle', noSpecs);
2013-02-05 23:01:01 +08:00
});