dom-core-test.js revision 1c8e83505eae7560612e069a40097601f35c7dc0
8215dd9a19d775d6391d4f44be2ca8268952e048TrippYUI.add('dom-core-test', function(Y) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var Assert = Y.Assert;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert = Y.ArrayAssert;
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp Y.Test.Runner.add(new Y.Test.Case({
6f294bea19c397d53e471007448460655f4b8c6bTripp name: 'Y.DOM.byId',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return element from string': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.areEqual(document.getElementById('test-id'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.byId('test-id'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return first match when dupe id exists': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-id'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp dupe = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp dupe.id = 'test-id';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.insertBefore(dupe, node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.areEqual(dupe, Y.DOM.byId('test-id'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(dupe);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when no match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.isNull(Y.DOM.byId('fake-id'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.isNull(Y.DOM.byId(null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when input is undefined': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.isNull(Y.DOM.byId());
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should avoid mistaking name for id': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var inputs = document.getElementsByTagName('form')[0]
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp .getElementsByTagName('input');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(inputs[0], Y.DOM.byId('test-name-id1'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(inputs[1], Y.DOM.byId('test-name-id2'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should avoid mistaking form id for named input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var form = document.getElementsByTagName('form')[0];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(form, Y.DOM.byId('test-names'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.innerHTML = '<span id="test-by-id-root">foo</span><span>bar</span>';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.areEqual(node.childNodes[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.byId('test-by-id-root', node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should restrict search to the given node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.id = 'test-by-id-root';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.isNull(Y.DOM.byId('test-by-id-root', node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given node (off document)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.innerHTML = '<span id="test-by-id-root">foo</span><span>bar</span>';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.areEqual(node.childNodes[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.byId('test-by-id-root', node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given document (frame)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.areEqual(document.getElementById('test-id'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.byId('demo', document));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given document (frame)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var frame = document.getElementById('test-frame'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp doc = frame.contentWindow.document;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Assert.areEqual(doc.getElementById('demo'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.byId('demo', doc));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.allById',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return all elements with the given id': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var nodes = document.getElementById('test-dupe-ids')
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp .getElementsByTagName('span');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual(nodes, Y.DOM.allById('test-dupe-id'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return all elements with the given id (root element)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-dupe-root'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp nodes = node.getElementsByTagName('span');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual(nodes, Y.DOM.allById('test-dupe-id', node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when no match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([], Y.DOM.allById('fake-id'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.children',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when no element childNodes': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([], Y.DOM.children(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([], Y.DOM.children(null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when input is undefined': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp ArrayAssert.itemsAreEqual([], Y.DOM.children());
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should return elements only': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-children'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp nodes = node.getElementsByTagName('span');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp ArrayAssert.itemsAreEqual(nodes, Y.DOM.children(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.firstByTag',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the first match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.firstByTag('div'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the first match (root element)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-names');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('input')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.firstByTag('input', root));
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when no match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.firstByTag('fake-tag'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when tag is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.firstByTag(null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search given document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.firstByTag('div', document));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search given document (frame)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var frame = document.getElementById('test-frame'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp doc = frame.contentWindow.document,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = doc .getElementById('demo');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(node, Y.DOM.firstByTag('div', doc));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.getText',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the text content of the given node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-get-text'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp nodes = node.childNodes,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp text = '',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp i = 0,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp child;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp while((child = nodes[i++])) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp text += child.innerHTML || child.nodeValue;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual(text, Y.DOM.getText(node));
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the text content of the given text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var text = 'foo bar',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = document.createTextNode(text);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(text, Y.DOM.getText(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty string when no text found' : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('', Y.DOM.getText(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty string when input is null' : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('', Y.DOM.getText(null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty string when input is undefined' : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('', Y.DOM.getText());
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.setText',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should set content with the given text': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp var node = document.createElement('div'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp content = 'testing text content';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.setText(node, content);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should set html content as text': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp content = '<div>testing text content</div>';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.setText(node, content);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should preserve spaces': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp content = ' testing text content ';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.setText(node, content);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should replace existing content': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp content = 'testing text content';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.innerHTML = '<em>foo</em>';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.setText(node, content);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should set text for text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createTextNode(''),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp content = 'testing text content';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.setText(node, content);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.elementByAxis',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('div')[0];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('span')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'nextSibling'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('div')[0];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(node.nextSibling,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'nextSibling', null, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next element that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName === 'EM';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('em')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'nextSibling', fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next node that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.nodeValue === 'baz';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('span')[0].nextSibling,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'nextSibling', fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('span')[0];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'previousSibling'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('span')[0];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(node.previousSibling,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'previousSibling', null, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous element that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('EM')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName === 'DIV';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'previousSibling', fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous node that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('em')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.nodeValue === 'foo';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('div')[0].previousSibling,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'previousSibling', fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the parent element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('span')[0];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root, Y.DOM.elementByAxis(node, 'parentNode'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the ancestor element that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('EM')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName === 'BODY';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.body,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'parentNode', fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when not found': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.firstChild,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.nodeValue === 'foo';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling', fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling', null, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis(node, 'previousSibling', fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis(null, 'previousSibling'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis(document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when input is undefined': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis());
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.ancestor',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the parent node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.documentElement,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.ancestor(document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the same node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.body,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.ancestor(document.body, null, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should return the matching ancestor': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('EM')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName === 'BODY';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.body, Y.DOM.ancestor(node, fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestor (test self match)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('EM')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName === 'EM';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(node, Y.DOM.ancestor(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestor (test self not matched)': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp var root = document.getElementById('test-element-by-axis'),
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp node = root.getElementsByTagName('EM')[0],
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp fn = function(node) {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp return node.tagName === 'BODY';
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp };
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual(document.body, Y.DOM.ancestor(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.ancestors',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return an array of one (documentElement)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.documentElement],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.ancestors(document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should include the starting node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.documentElement, document.body, node],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.ancestors(node, null, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should omit the starting node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.documentElement, document.body],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.ancestors(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestors': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName !== 'HTML';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.body], Y.DOM.ancestors(node, fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestors (test self match)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('EM')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName === 'EM';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([node], Y.DOM.ancestors(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestors (test self not matched)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = root.getElementsByTagName('EM')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fn = function(node) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return node.tagName === 'BODY';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.body], Y.DOM.ancestors(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.contains',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'html element should contain body element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.contains(document.documentElement, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'body element should not contain html element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(document.body, document.documentElement));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.contains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true when element is element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.contains(document.body, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createTextNode('foo');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.contains(document.documentElement, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createTextNode('foo');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for null input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(document.body, null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(null, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(null, null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for undefined input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains());
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM._bruteContains',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'html element should contain body element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.documentElement, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'body element should not contain html element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, document.documentElement));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true when element is element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.body, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createTextNode('foo');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.documentElement, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createTextNode('foo');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for null input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(null, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(null, null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for undefined input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains());
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.inDoc',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for off document node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.inDoc(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return true for in document node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.inDoc(document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for removed node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.inDoc(node), 'removed');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should work with duplicate IDs in document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var nodes = document.getElementById('test-dupe-ids')
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp .getElementsByTagName('span');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.inDoc(nodes[2]));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should work with duplicate IDs off document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.createElement('div');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.id = 'test-dupe-id';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.inDoc(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should work with form that has input name="id" and id="id"': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-names');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.inDoc(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.inDoc(null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for cloned node off document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-id');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = node.cloneNode(true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.inDoc(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return true for cloned node in document (same id)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-id');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = node.cloneNode(true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.inDoc(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return true for cloned node in document (new id)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = document.getElementById('test-id');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = node.cloneNode(true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.id = 'test-id-new';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.appendChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.inDoc(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp document.body.removeChild(node);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Test.Runner.add(new Y.Test.Case({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name: 'Y.DOM.create',
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should create empty div': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var el = Y.DOM.create(('<div/>'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('DIV', el.tagName);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('', el.innerHTML);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should trim leading space': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var el = Y.DOM.create((' <div/>'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('DIV', el.tagName);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('', el.innerHTML);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should create empty div (self-closed input)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var el = Y.DOM.create(('<div/>'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('DIV', el.tagName);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('', el.innerHTML);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should create div with text': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp var el = Y.DOM.create(('<div>foo</div>'));
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual('DIV', el.tagName);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual('foo', el.innerHTML);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp },
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp 'should create div with innerHTML': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp var el = Y.DOM.create(('<div><em>bar</em></div>'));
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual('DIV', el.tagName);
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('<em>bar</em>', el.innerHTML.toLowerCase());
6f294bea19c397d53e471007448460655f4b8c6bTripp },
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp 'should create input type submit': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp var el = Y.DOM.create('<input name="foo" value="bar" type="submit">');
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('INPUT', el.tagName);
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('submit', el.type);
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('foo', el.name);
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('bar', el.value);
6f294bea19c397d53e471007448460655f4b8c6bTripp },
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp 'should create input type radio': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp var el = Y.DOM.create('<input name="test-input" type="radio">');
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('INPUT', el.tagName);
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('radio', el.type);
6f294bea19c397d53e471007448460655f4b8c6bTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp },
6f294bea19c397d53e471007448460655f4b8c6bTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should create form': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp var el = Y.DOM.create('<form/>');
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('FORM', el.tagName);
6f294bea19c397d53e471007448460655f4b8c6bTripp },
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp 'should create a form with content': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp var el = Y.DOM.create('<form><fieldset><legend>foo</legend>' +
6f294bea19c397d53e471007448460655f4b8c6bTripp '<label>foo:</label><input name="foo"><input type="submit"></form>'),
6f294bea19c397d53e471007448460655f4b8c6bTripp fieldset = el.firstChild,
6f294bea19c397d53e471007448460655f4b8c6bTripp legend = fieldset.firstChild;
6f294bea19c397d53e471007448460655f4b8c6bTripp label = legend.nextSibling,
6f294bea19c397d53e471007448460655f4b8c6bTripp input = label.nextSibling;
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp submit = input.nextSibling;
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('FORM', el.tagName);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual('FIELDSET', fieldset.tagName);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual('LEGEND', legend.tagName);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual('LABEL', label.tagName);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('INPUT', input.tagName);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual('foo', input.name);
Assert.areEqual('INPUT', submit.tagName);
Assert.areEqual('submit', submit.type);
},
'should create legend': function() {
var el = Y.DOM.create('<legend/>');
Assert.areEqual('LEGEND', el.tagName);
},
'should create fieldset': function() {
var el = Y.DOM.create('<fieldset/>');
Assert.areEqual('FIELDSET', el.tagName);
},
'should create label': function() {
var el = Y.DOM.create('<label/>');
Assert.areEqual('LABEL', el.tagName);
},
'should create a list item': function() {
var el = Y.DOM.create('<li>fresh</li>');
Assert.areEqual('LI', el.tagName);
Assert.areEqual('fresh', el.innerHTML);
},
'should create a one item list': function() {
el = Y.DOM.create('<ul><li>fresh</li></ul>');
Assert.areEqual(1, el.childNodes.length);
},
'should create a table': function() {
var el = Y.DOM.create('<table/>');
Assert.areEqual('TABLE', el.tagName);
},
'should create a table with content': function() {
var el = Y.DOM.create('<table><tr><td>foo</td><td>bar</td></tr></table>'),
tbody = el.firstChild,
tr = el.firstChild.firstChild,
td = tr.firstChild;
Assert.areEqual('TABLE', el.tagName);
Assert.areEqual('TBODY', tbody.tagName);
Assert.areEqual('TR', tr.tagName);
Assert.areEqual('TD', td.tagName);
Assert.areEqual('TD', td.nextSibling.tagName, 'td 2');
},
'should create a table head': function() {
var el = Y.DOM.create('<thead></thead>');
Assert.areEqual('THEAD', el.tagName);
},
'should create a table head from uppercase': function() {
var el = Y.DOM.create('<THEAD></THEAD>');
Assert.areEqual('THEAD', el.tagName);
},
'should create a table head with nested table': function() {
var el = Y.DOM.create('<thead><tr><td><table><tbody><tr>' +
'<td>fresh</td></tr></tbody></table></td></tr></thead>');
Assert.areEqual('THEAD', el.tagName);
Assert.areEqual(1, el.getElementsByTagName('table').length);
},
'should create a table heading cell': function() {
var el = Y.DOM.create('<th>fresh</th>');
Assert.areEqual('TH', el.tagName);
Assert.areEqual('fresh', el.innerHTML);
},
'should create a caption': function() {
var el = Y.DOM.create('<caption>fresh</caption>');
Assert.areEqual('CAPTION', el.tagName);
Assert.areEqual('fresh', el.innerHTML);
},
'should create a colgroup': function() {
var el = Y.DOM.create('<colgroup/>');
Assert.areEqual('COLGROUP', el.tagName);
},
'should create a col element': function() {
var el = Y.DOM.create('<col>');
Assert.areEqual('COL', el.tagName);
},
'should create a colgroup with col elements': function() {
var el = Y.DOM.create('<colgroup><col><col></colgroup>'),
nodes = el.childNodes,
i = 0,
cols = [],
child;
// IE inserts a linefeed between cols
while((child = nodes[i++])) {
if (child.nodeName === 'COL') {
cols.push(child);
}
}
Assert.areEqual('COLGROUP', el.tagName);
Assert.areEqual('COL', cols[0].tagName);
Assert.areEqual('COL', cols[1].tagName);
},
'should create a table row': function() {
var el = Y.DOM.create('<tr/>');
Assert.areEqual('TR', el.tagName);
},
'should create a table row with content': function() {
var el = Y.DOM.create('<tr><td>foo</td><td>bar</td></tr>');
Assert.areEqual('TR', el.tagName);
Assert.areEqual('TD', el.firstChild.tagName);
Assert.areEqual('TD', el.firstChild.nextSibling.tagName, 'td 2');
},
'should create a table cell': function() {
var el = Y.DOM.create('<td/>');
Assert.areEqual('TD', el.tagName);
},
'should create a table cell with content': function() {
var el = Y.DOM.create('<td>fresh</td>');
Assert.areEqual('TD', el.tagName);
Assert.areEqual('fresh', el.innerHTML);
},
'should create a button element': function() {
var el = Y.DOM.create('<button>fresh</button>');
Assert.areEqual('BUTTON', el.tagName);
},
'should create an optgroup element': function() {
var el = Y.DOM.create('<optgroup></optgroup>');
Assert.areEqual('OPTGROUP', el.tagName);
},
'should create an optgroup with an option': function() {
var el = Y.DOM.create('<optgroup><option>foo</option></optgroup>');
Assert.areEqual('OPTGROUP', el.tagName);
Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
},
'should create an optgroup with options': function() {
var el = Y.DOM.create('<optgroup><option>foo</option><option>bar</option></optgroup>');
Assert.areEqual('OPTGROUP', el.tagName);
Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
Assert.areEqual('OPTION', el.firstChild.nextSibling.tagName, 'option 2');
},
'should create a select element': function() {
var el = Y.DOM.create('<select/>');
Assert.areEqual('SELECT', el.tagName);
},
'should create a select with an option': function() {
var el = Y.DOM.create('<select><option>foo</option></select>');
Assert.areEqual('SELECT', el.tagName);
Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
},
'should create a select with options': function() {
var el = Y.DOM.create('<select><option>foo</option><option>bar</option></select>');
Assert.areEqual('SELECT', el.tagName);
Assert.areEqual('OPTION', el.firstChild.tagName, 'option');
Assert.areEqual('OPTION', el.firstChild.nextSibling.tagName, 'option 2');
},
'should create a option element': function() {
var el = Y.DOM.create('<option/>');
Assert.areEqual('OPTION', el.tagName);
},
'should create a option with content': function() {
var el = Y.DOM.create('<option><foo</option>');
Assert.areEqual('OPTION', el.tagName);
},
'should create a selected option': function() {
var el = Y.DOM.create('<option selected><foo</option>');
Assert.areEqual('OPTION', el.tagName);
},
'should create an iframe (self-closed)': function() {
var el = Y.DOM.create('<iframe/>');
Assert.areEqual('IFRAME', el.tagName);
},
'should create an iframe': function() {
var el = Y.DOM.create('<iframe src="http://search.yahoo.com/" id="yui-iframetest"></iframe>');
Assert.areEqual('IFRAME', el.tagName);
},
'should create an iframe with attributes': function() {
var html = '<iframe border="0" frameBorder="0" marginWidth="0"' +
' marginHeight="0" leftMargin="0" topMargin="0"' +
' allowTransparency="true" width="100%" height="99%"></iframe>';
el = Y.DOM.create(html);
Assert.areEqual('IFRAME', el.tagName);
Assert.areEqual(0, el.frameBorder);
Assert.areEqual(document, el.ownerDocument);
},
'should create a script': function() {
var el = Y.DOM.create('<scr' + 'ipt/>');
Assert.areEqual('SCRIPT', el.tagName);
},
'should create a script with src': function() {
var el = Y.DOM.create('<scr' + 'ipt src="http://search.yahoo.com/"></scr' + 'ipt>');
Assert.areEqual('SCRIPT', el.tagName);
Assert.areEqual('http://search.yahoo.com/', el.src);
},
'should create a link element': function() {
var el = Y.DOM.create('<link/>');
Assert.areEqual('LINK', el.tagName);
},
'should create a link element with attrs': function() {
var el = Y.DOM.create('<link href="http://search.yahoo.com/" rel="stylesheet">');
Assert.areEqual('LINK', el.tagName);
Assert.areEqual('http://search.yahoo.com/', el.href);
Assert.areEqual(el.rel, 'stylesheet');
},
'should create a textNode': function() {
var el = Y.DOM.create('text');
Assert.areEqual(3, el.nodeType);
},
'should return a fragment when creating a collection': function() {
var html = '<div>foo</div><div id="tmp-bar">bar</div><div>baz</div>',
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(3, el.childNodes.length);
Assert.areEqual('tmp-bar', el.childNodes[1].id);
Assert.areEqual('foo', el.childNodes[0].innerHTML);
},
'should return a fragment containing options': function() {
var html = '<option>foo</option><option id="tmp-bar">bar</option><option>baz</option>',
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(3, el.childNodes.length);
Assert.areEqual('tmp-bar', el.childNodes[1].id);
},
'should return a fragment including text nodes': function() {
var html = 'foo <span>bar</span> baz',
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(3, el.childNodes[0].nodeType);
Assert.areEqual(1, el.childNodes[1].nodeType);
Assert.areEqual(3, el.childNodes[2].nodeType);
},
'should return a fragment with the correct selected option': function() {
var html = '<option>foo</option><option selected>bar</option><option>baz</option>';
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(3, el.childNodes.length);
Assert.isTrue(el.childNodes[1].selected);
},
'should return a fragment containing table cells': function() {
var html = '<td>foo</td><td id="tmp-bar">bar</td><td>baz</td>',
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(3, el.childNodes.length);
Assert.areEqual('tmp-bar', el.childNodes[1].id);
},
'should return a fragment containing col elements': function() {
var html = '<col><col>',
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(2, el.childNodes.length);
Assert.areEqual('COL', el.childNodes[0].tagName);
Assert.areEqual('COL', el.childNodes[1].tagName);
},
'should return a fragment containing table bodies': function() {
var html = '<tbody><tr><td>foo</td></tr></tbody><tbody id="tmp-bar"><tr><td>bar</td></tr></tbody><tbody><tr><td>bar</td></tr></tbody>',
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(3, el.childNodes.length);
Assert.areEqual('TBODY', el.childNodes[0].tagName);
Assert.areEqual('TBODY', el.childNodes[1].tagName);
Assert.areEqual('tmp-bar', el.childNodes[1].id);
},
'should return a fragment containing thead with nested table and tbody': function() {
var html = '<thead><tr><td><table><tbody><tr><td>fresh</td></tr>' +
'</tbody></table></td></tr></thead><tbody></tbody>',
el = Y.DOM.create(html);
Assert.areEqual(11, el.nodeType);
Assert.areEqual(2, el.childNodes.length);
Assert.areEqual('THEAD', el.firstChild.tagName);
Assert.areEqual(1, el.firstChild.getElementsByTagName('table').length);
Assert.areEqual('TBODY', el.childNodes[1].tagName);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.getAttribute',
'should return "className" value': function() {
var node = document.createElement('div');
node.className = 'foo';
Assert.areEqual('foo', Y.DOM.getAttribute(node, 'class'), 'class');
Assert.areEqual('foo', Y.DOM.getAttribute(node, 'className'), 'className');
},
'should return "for" value': function() {
var node = document.getElementById('for-id');
Assert.areEqual('id', Y.DOM.getAttribute(node, 'for'));
Assert.areEqual('id', Y.DOM.getAttribute(node, 'htmlFor'));
},
'should handle bad input': function() {
var node = document.createElement('div');
Y.DOM.getAttribute(null);
Y.DOM.getAttribute();
Assert.isTrue(true);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.setAttribute',
'should set className': function() {
var node = document.createElement('div');
Y.DOM.setAttribute(node, 'class', 'foo');
Assert.areEqual('foo', node.className);
Y.DOM.setAttribute(node, 'className', 'bar');
Assert.areEqual('bar', node.className);
},
'should set "for" attribute': function() {
var node = document.createElement('label');
Y.DOM.setAttribute(node, 'for', 'foo');
Assert.areEqual('foo', node.htmlFor);
Y.DOM.setAttribute(node, 'htmlFor', 'bar');
Assert.areEqual('bar', node.htmlFor);
},
'should handle bad input': function() {
var node = document.createElement('div');
Y.DOM.setAttribute(null, 'bar');
Y.DOM.setAttribute(node, null);
Y.DOM.setAttribute();
Assert.isTrue(true);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.getValue',
'input value should match html value': function() {
var node = document.getElementById('test-text-value'),
val = 'test value';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'input value should match no html value': function() {
var node = document.getElementById('test-text-no-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'input value should match empty html value': function() {
var node = document.getElementById('test-text-empty-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'textarea value should match html value': function() {
var node = document.getElementById('test-textarea-text-value'),
val = 'textarea test';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'textarea value should match no html value': function() {
var node = document.getElementById('test-textarea-no-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'should ignore textarea html value attribute': function() {
var node = document.getElementById('test-textarea-value');
Assert.areEqual('', Y.DOM.getValue(node));
},
'select value should match html value': function() {
var node = document.getElementById('test-select-value');
val = 'option value';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'select value should match no html value': function() {
var node = document.getElementById('test-select-no-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'select value should match empty html value with text': function() {
var node = document.getElementById('test-select-empty-value-text'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'select value should match empty html value': function() {
var node = document.getElementById('test-select-empty-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'option value should match html value': function() {
var node = document.getElementById('test-option-value');
val = 'option value';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'option value should match html content': function() {
var node = document.getElementById('test-option-value-text');
val = 'option text';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'option value should match no html value': function() {
var node = document.getElementById('test-option-no-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'option value should match empty html value with text': function() {
var node = document.getElementById('test-select-empty-value-text'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'option value should match empty html value': function() {
var node = document.getElementById('test-select-empty-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'button value should match html value': function() {
var node = document.getElementById('test-button-value');
val = 'button value';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'button value should match no html value': function() {
var node = document.getElementById('test-button-no-value'),
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'button value should ignore html content': function() {
var node = document.getElementById('test-button-text-value');
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
},
'button value should match empty value': function() {
var node = document.getElementById('test-button-empty-value');
val = '';
Assert.areEqual(val, Y.DOM.getValue(node));
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.setValue',
'input value should match updated value': function() {
var node = document.getElementById('test-text-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, 'test value');
},
'value updated from empty string should be new value': function() {
var node = document.getElementById('test-text-empty-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
},
'value updated from no value should be new value': function() {
var node = document.getElementById('test-text-no-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
node.removeAttribute('value')
},
'textarea from html value should match new value': function() {
var node = document.getElementById('test-textarea-text-value'),
val = 'new textarea test';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue('textarea test');
},
'textarea from no value should match new value': function() {
var node = document.getElementById('test-textarea-no-value'),
val = 'new textarea test';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue('');
},
'button value should match updated value': function() {
var node = document.getElementById('test-button-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, 'test value');
},
'button value updated from empty string should be new value': function() {
var node = document.getElementById('test-button-empty-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
},
'button value updated from no value should be new value': function() {
var node = document.getElementById('test-button-no-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
node.removeAttribute('value')
},
'option value should match updated value': function() {
var node = document.getElementById('test-option-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, 'test value');
},
'option value updated from text should be new value': function() {
var node = document.getElementById('test-option-value-text'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
},
'option value updated from empty string should be new value': function() {
var node = document.getElementById('test-option-empty-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
},
'option value updated from no value should be new value': function() {
var node = document.getElementById('test-option-no-value'),
val = 'new value';
Y.DOM.setValue(node, val);
Assert.areEqual(val, Y.DOM.getValue(node));
Y.DOM.setValue(node, '');
node.removeAttribute('value')
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM._nl2Frag',
'should return fragment from HTMLCollection': function() {
var node = document.createElement('div'),
frag;
node.innerHTML = '<div>foo</div><div>bar</div><div>baz</div>';
frag = Y.DOM._nl2frag(node.childNodes);
Y.Assert.areEqual(11, frag.nodeType);
Y.Assert.areEqual(3, frag.childNodes.length);
},
'should return fragment from Array of HTML Elements': function() {
var nodes = [
document.createElement('div'),
document.createElement('div'),
document.createElement('div')
],
frag = Y.DOM._nl2frag(nodes);
Y.Assert.areEqual(11, frag.nodeType);
Y.Assert.areEqual(3, frag.childNodes.length);
},
'should return null for bad input': function() {
Assert.isNull(Y.DOM._nl2frag({}));
Assert.isNull(Y.DOM._nl2frag());
Assert.isNull(Y.DOM._nl2frag(''));
Assert.isNull(Y.DOM._nl2frag(1));
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.isWindow',
'should return true for window object': function() {
Assert.isTrue(Y.DOM.isWindow(window));
},
'should return true for frame window object': function() {
var frame = document.getElementById('test-frame'),
doc = frame.contentWindow.document,
win = doc.defaultView || doc.parentWindow;
Assert.isTrue(Y.DOM.isWindow(win));
},
'should return false for document object': function() {
Assert.isFalse(Y.DOM.isWindow(document));
},
'should return false for non-window input': function() {
Assert.isFalse(Y.DOM.isWindow());
Assert.isFalse(Y.DOM.isWindow(null));
Assert.isFalse(Y.DOM.isWindow(1));
Assert.isFalse(Y.DOM.isWindow(document.body));
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM._removeChildNodes',
'should remove all childNodes': function() {
var node = document.createElement('div'),
html = '<em>foo</em><strong>bar</strong><span>baz</span>';
node.innerHTML = html;
Y.DOM._removeChildNodes(node);
Assert.areEqual(0, node.childNodes.length);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.addHTML',
'should append the given html to the node': function() {
var node = document.createElement('div');
Y.DOM.addHTML(node, '<em>new content</em>');
Assert.areEqual('EM', node.lastChild.nodeName);
},
'should prepend the given html to the node': function() {
var node = document.createElement('div');
node.innerHTML = '<strong>bar</strong>';
Y.DOM.addHTML(node, '<em>new content</em>', node.firstChild);
Assert.areEqual('EM', node.firstChild.nodeName);
},
'should insert the given html after the first child': function() {
var node = document.createElement('div');
node.innerHTML = '<em>foo</em><strong>bar</strong>';
Y.DOM.addHTML(node, '<span>new content</span>', node.childNodes[1]);
Assert.areEqual('SPAN', node.childNodes[1].nodeName);
},
'should append the given node': function() {
var node = document.createElement('div');
Y.DOM.addHTML(node, document.createElement('div'));
Assert.areEqual('DIV', node.firstChild.nodeName);
},
'should add html before the given node': function() {
var node = document.createElement('div');
node.innerHTML = '<em>foo</em><strong>bar</strong>';
Y.DOM.addHTML(node.childNodes[1], '<span>new content</span>', 'before');
Assert.areEqual('SPAN', node.childNodes[1].nodeName);
},
'should add html after the given node': function() {
var node = document.createElement('div');
node.innerHTML = '<em>foo</em><strong>bar</strong>';
Y.DOM.addHTML(node.childNodes[1], '<span>new content</span>', 'after');
Assert.areEqual('SPAN', node.childNodes[2].nodeName);
},
'should replace the existing content (empty string)': function() {
var node = document.createElement('div');
node.innerHTML = '<em>foo</em><strong>bar</strong>';
Y.DOM.addHTML(node, '', 'replace');
Assert.areEqual(0, node.childNodes.length);
},
'should replace the existing content (null)': function() {
var node = document.createElement('div');
node.innerHTML = '<em>foo</em><strong>bar</strong>';
Y.DOM.addHTML(node, null, 'replace');
Assert.areEqual(0, node.childNodes.length);
},
'should replace the existing content (undefined)': function() {
var node = document.createElement('div');
node.innerHTML = '<em>foo</em><strong>bar</strong>';
Y.DOM.addHTML(node, undefined, 'replace');
Assert.areEqual(0, node.childNodes.length);
},
'should replace the existing content (0)': function() {
var node = document.createElement('div');
node.innerHTML = '<em>foo</em><strong>bar</strong>';
Y.DOM.addHTML(node, 0, 'replace');
Assert.areEqual(1, node.childNodes.length);
Assert.areEqual(3, node.firstChild.nodeType);
},
'should append the given nodelist': function() {
var node = document.createElement('div'),
node2 = document.createElement('div'),
nodelist;
node.innerHTML = '<em>foo</em><strong>bar</strong>';
nodelist = node.getElementsByTagName('*');
Y.DOM.addHTML(node2, nodelist);
Assert.areEqual('EM', node2.childNodes[0].nodeName);
},
'should insert the given nodelist before the given node': function() {
var node = document.createElement('div'),
node2 = document.createElement('div'),
nodelist;
node.innerHTML = '<em>foo</em><strong>bar</strong>';
node2.innerHTML = '<span>baz</span><b>foobar</b>';
nodelist = node.getElementsByTagName('*');
Y.DOM.addHTML(node2, nodelist, node2.firstChild.nextSibling);
Assert.areEqual('EM', node2.childNodes[1].nodeName);
},
'should prepend the given nodelist': function() {
var node = document.createElement('div'),
node2 = document.createElement('div'),
nodelist;
node.innerHTML = '<em>foo</em><strong>bar</strong>';
node2.innerHTML = '<span>baz</span><b>foobar</b>';
nodelist = node.getElementsByTagName('*');
Y.DOM.addHTML(node2, nodelist, node2.firstChild);
Assert.areEqual('EM', node2.childNodes[0].nodeName);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM._getRegExp',
'should return RegExp obj': function() {
var re = Y.DOM._getRegExp('^foo$');
Assert.isTrue(typeof re.test === 'function');
},
'should return cached RegExp obj': function() {
var re = Y.DOM._getRegExp('^foo$'),
re2 = Y.DOM._getRegExp('^foo$');
Assert.areSame(re, re2);
},
'should return new RegExp obj': function() {
var re = Y.DOM._getRegExp('^foo$'),
re2 = Y.DOM._getRegExp('^foos$'),
re3 = Y.DOM._getRegExp('^foo$', 'g');
Assert.areNotSame(re, re2);
Assert.areNotSame(re, re3);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM._getDoc',
'should return document from body': function() {
var doc = Y.DOM._getDoc(document.body);
Assert.areSame(document, doc);
},
'should return document from new node': function() {
var doc = Y.DOM._getDoc(document.createElement('div'));
Assert.areSame(document, doc);
},
'should return document from window': function() {
var doc = Y.DOM._getDoc(window);
Assert.areSame(document, doc);
},
'should return document from document': function() {
var doc = Y.DOM._getDoc(window);
Assert.areSame(document, doc);
},
'should return iframe document from iframe window': function() {
var win = document.getElementById('test-frame').contentWindow,
doc = Y.DOM._getDoc(win);
Assert.areSame(win.document, doc);
},
'should return iframe document from iframe node': function() {
var win = document.getElementById('test-frame').contentWindow,
doc = Y.DOM._getDoc(win.document.getElementById('demo'));
Assert.areSame(win.document, doc);
},
'should return iframe document from iframe document': function() {
var win = document.getElementById('test-frame').contentWindow,
doc = Y.DOM._getDoc(win.document);
Assert.areSame(win.document, doc);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM._getWin',
'should return window from body': function() {
var win = Y.DOM._getWin(document.body);
Assert.areSame(window.window, win.window);
},
'should return window from new node': function() {
var win = Y.DOM._getWin(document.createElement('div'));
Assert.areSame(window.window, win.window);
},
'should return window from window': function() {
var win = Y.DOM._getWin(window);
Assert.areSame(window.window, window.window);
},
'should return window from document': function() {
var win = Y.DOM._getWin(window);
Assert.areSame(window.window, win.window);
},
'should return iframe window from iframe window': function() {
var node = document.getElementById('test-frame'),
win = Y.DOM._getWin(node.contentWindow);
Assert.areSame(node.contentWindow.window, win.window);
},
'should return iframe window from iframe node': function() {
var contentWin = document.getElementById('test-frame').contentWindow,
win = Y.DOM._getWin(contentWin.document.getElementById('demo'));
Assert.areSame(contentWin.window, win.window);
},
'should return iframe window from iframe document': function() {
var contentWin = document.getElementById('test-frame').contentWindow,
win = Y.DOM._getWin(contentWin.document);
Assert.areSame(contentWin.window, win.window);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM._batch',
'should append html on all nodes in HTMLCollection': function() {
var node = document.createElement('div'),
val = '<p>new text</p>';
node.innerHTML = '<span></span><span></span><span></span>';
Y.DOM._batch(node.childNodes, 'addHTML', val);
Assert.areEqual('P', node.childNodes[0].firstChild.tagName);
Assert.areEqual('P', node.childNodes[1].firstChild.tagName);
Assert.areEqual('P', node.childNodes[2].firstChild.tagName);
},
'should setText on all nodes in HTMLCollection': function() {
var node = document.createElement('div'),
val = 'new text';
node.innerHTML = '<span>foo</span><span>bar</span><span>baz</span>',
Y.DOM._batch(node.childNodes, 'setText', val);
Assert.areEqual(val, node.childNodes[0].innerHTML);
Assert.areEqual(val, node.childNodes[1].innerHTML);
Assert.areEqual(val, node.childNodes[2].innerHTML);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM._setSize',
'should set the node offsetWidth to the given value': function() {
var node = document.createElement('div');
document.body.appendChild(node);
Y.DOM._setSize(node, 'width', 100);
Assert.areEqual(100, node.offsetWidth);
document.body.removeChild(node);
},
'should set the node offsetHeight to the given value': function() {
var node = document.createElement('div');
document.body.appendChild(node);
Y.DOM._setSize(node, 'height', 100);
Assert.areEqual(100, node.offsetHeight);
document.body.removeChild(node);
},
'should set the node offsetWidth to zero if given a negative number': function() {
var node = document.createElement('div');
document.body.appendChild(node);
Y.DOM._setSize(node, 'width', -100);
Assert.areEqual(0, node.offsetWidth);
document.body.removeChild(node);
},
'should set the node offsetHeight to zero if given a negative number': function() {
var node = document.createElement('div');
document.body.appendChild(node);
Y.DOM._setSize(node, 'height', -100);
Assert.areEqual(0, node.offsetHeight);
document.body.removeChild(node);
},
'should set the offsetWidth via setWidth': function() {
var node = document.createElement('div');
document.body.appendChild(node);
Y.DOM.setWidth(node, 100);
Assert.areEqual(100, node.offsetWidth);
document.body.removeChild(node);
},
'should set the offsetHeight via setHeight': function() {
var node = document.createElement('div');
document.body.appendChild(node);
Y.DOM.setHeight(node, 100);
Assert.areEqual(100, node.offsetHeight);
document.body.removeChild(node);
},
'should set offsetWidth accounting for padding': function() {
var node = document.createElement('div');
document.body.appendChild(node);
node.style.padding = '10px';
Y.DOM.setWidth(node, 100);
Assert.areEqual(100, node.offsetWidth);
document.body.removeChild(node);
},
'should set offsetHeight accounting for padding': function() {
var node = document.createElement('div');
document.body.appendChild(node);
node.style.padding = '10px';
Y.DOM.setHeight(node, 100);
Assert.areEqual(100, node.offsetHeight);
document.body.removeChild(node);
},
'should set offsetWidth to padding when setting to zero': function() {
var node = document.createElement('div');
document.body.appendChild(node);
node.style.padding = '10px';
Y.DOM.setWidth(node, 0);
Assert.areEqual(20, node.offsetWidth);
document.body.removeChild(node);
},
'should set offsetHeight to padding when setting to zero': function() {
var node = document.createElement('div');
document.body.appendChild(node);
node.style.padding = '10px';
Y.DOM.setHeight(node, 0);
Assert.areEqual(20, node.offsetHeight);
document.body.removeChild(node);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.wrap',
'should wrap the node with the given html': function() {
var node = document.createElement('span');
Y.DOM.wrap(node, '<p></p>');
Assert.areEqual('P', node.parentNode.tagName);
},
'should wrap the node with the given complex html': function() {
var node = document.createElement('span');
Y.DOM.wrap(node, '<p><em><strong><span></span></strong></em></p>');
Assert.areEqual('SPAN', node.parentNode.tagName);
}
}));
Y.Test.Runner.add(new Y.Test.Case({
name: 'Y.DOM.unwrap',
'should remove the node\'s parent': function() {
var node = document.createElement('span').appendChild(document.createElement('em'));
Y.DOM.unwrap(node);
Assert.isTrue(!node.parentNode || node.parentNode.nodeType !== 1);
},
'should remove the node\'s parent and replace in DOM': function() {
var parent = document.createElement('span'),
node = parent.appendChild(document.createElement('strong')).
appendChild(document.createElement('em'));
document.body.insertBefore(parent, document.body.firstChild);
Y.DOM.unwrap(node);
Assert.areEqual('SPAN', node.parentNode.tagName);
document.body.removeChild(node.parentNode);
},
'should remove the node\'s parent and replace in DOM with siblings': function() {
var parent = document.createElement('div'),
node;
parent.innerHTML = '<p><span>foo</span><em>bar</em><strong>baz</strong></p>';
node = parent.getElementsByTagName('em')[0];
Y.DOM.unwrap(node);
Assert.areEqual('DIV', node.parentNode.tagName);
Assert.areEqual('SPAN', node.previousSibling.tagName);
Assert.areEqual('DIV', node.previousSibling.parentNode.tagName);
Assert.areEqual('STRONG', node.nextSibling.tagName);
Assert.areEqual('DIV', node.nextSibling.parentNode.tagName);
}
}));
}, '@VERSION@' ,{requires:['dom-base', 'dom-deprecated', 'test']});