2010-09-07 22:02:45 +08:00
|
|
|
describe('DomUtil', function() {
|
|
|
|
var el;
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2010-09-07 22:02:45 +08:00
|
|
|
beforeEach(function() {
|
|
|
|
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
|
|
|
|
2010-09-07 22:02:45 +08:00
|
|
|
afterEach(function() {
|
|
|
|
document.body.removeChild(el);
|
|
|
|
});
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2010-09-07 22:02:45 +08:00
|
|
|
describe('#get', function() {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('gets element by id if the given argument is string', function() {
|
2010-09-07 22:02:45 +08:00
|
|
|
el.id = 'testId';
|
|
|
|
expect(L.DomUtil.get(el.id)).toBe(el);
|
|
|
|
});
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns the element if it is given as an argument', function() {
|
2010-09-07 22:02:45 +08:00
|
|
|
expect(L.DomUtil.get(el)).toBe(el);
|
|
|
|
});
|
|
|
|
});
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2011-07-15 20:03:35 +08:00
|
|
|
describe('#addClass, #removeClass, #hasClass', function() {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('has defined class for test element', function() {
|
2011-07-15 20:03:35 +08:00
|
|
|
el.className = 'bar foo baz ';
|
|
|
|
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy();
|
|
|
|
expect(L.DomUtil.hasClass(el, 'bar')).toBeTruthy();
|
|
|
|
expect(L.DomUtil.hasClass(el, 'baz')).toBeTruthy();
|
|
|
|
expect(L.DomUtil.hasClass(el, 'boo')).toBeFalsy();
|
|
|
|
});
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2013-02-20 04:41:48 +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
|
|
|
|
2011-07-15 20:03:35 +08:00
|
|
|
expect(el.className).toEqual('foo');
|
|
|
|
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy();
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2011-07-15 20:03:35 +08:00
|
|
|
L.DomUtil.addClass(el, 'bar');
|
|
|
|
expect(el.className).toEqual('foo bar');
|
|
|
|
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy();
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2011-07-15 20:03:35 +08:00
|
|
|
L.DomUtil.removeClass(el, 'foo');
|
|
|
|
expect(el.className).toEqual('bar');
|
|
|
|
expect(L.DomUtil.hasClass(el, 'foo')).toBeFalsy();
|
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');
|
|
|
|
expect(el.className).toEqual('foo barz');
|
2013-02-20 00:18:15 +08:00
|
|
|
});
|
2011-07-15 20:03:35 +08:00
|
|
|
});
|
2013-02-05 23:01:01 +08:00
|
|
|
|
|
|
|
describe('#documentIsLtr', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns true if doc direction is ltr', function () {
|
2013-02-05 23:01:01 +08:00
|
|
|
expect(L.DomUtil.documentIsLtr()).toBe(true);
|
|
|
|
expect(L.DomUtil.documentIsLtr()).toBe(true); // cached
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getViewportOffset', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('calculates the viewport offset of an element', function () {
|
2013-02-20 00:21:01 +08:00
|
|
|
var div = document.createElement('div');
|
|
|
|
div.style.position = 'absolute';
|
|
|
|
div.style.top = '100px';
|
|
|
|
div.style.left = '200px';
|
|
|
|
div.style.border = '10px solid black';
|
|
|
|
div.style.padding = '50px';
|
|
|
|
div.style.visibility = 'hidden';
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2013-02-20 00:21:01 +08:00
|
|
|
var div2 = document.createElement('div');
|
|
|
|
div.style.marginTop = '100px';
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2013-02-20 00:21:01 +08:00
|
|
|
div.appendChild(div2);
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2013-02-20 00:21:01 +08:00
|
|
|
document.body.appendChild(div);
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2013-02-20 00:21:01 +08:00
|
|
|
expect(L.DomUtil.getViewportOffset(div2)).toEqual(new L.Point(260, 260));
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2013-02-20 00:21:01 +08:00
|
|
|
document.body.removeChild(div);
|
|
|
|
});
|
2013-02-05 23:01:01 +08:00
|
|
|
});
|
|
|
|
|
2010-09-14 00:02:49 +08:00
|
|
|
describe('#setPosition', noSpecs);
|
2013-02-05 23:01:01 +08:00
|
|
|
|
2010-09-14 19:57:45 +08:00
|
|
|
describe('#getStyle', noSpecs);
|
2013-02-05 23:01:01 +08:00
|
|
|
});
|