dom-core-test.js revision 1c8e83505eae7560612e069a40097601f35c7dc0
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return element from string': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return first match when dupe id exists': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when no match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when input is undefined': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should avoid mistaking name for id': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(inputs[0], Y.DOM.byId('test-name-id1'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(inputs[1], Y.DOM.byId('test-name-id2'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should avoid mistaking form id for named input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.innerHTML = '<span id="test-by-id-root">foo</span><span>bar</span>';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should restrict search to the given node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given node (off document)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.innerHTML = '<span id="test-by-id-root">foo</span><span>bar</span>';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given document (frame)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search the given document (frame)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return all elements with the given id': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual(nodes, Y.DOM.allById('test-dupe-id'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return all elements with the given id (root element)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual(nodes, Y.DOM.allById('test-dupe-id', node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when no match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([], Y.DOM.allById('fake-id'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when no element childNodes': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty array when input is undefined': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should return elements only': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp ArrayAssert.itemsAreEqual(nodes, Y.DOM.children(node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the first match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the first match (root element)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('input')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when no match': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when tag is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search given document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.getElementsByTagName('div')[0],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should search given document (frame)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the text content of the given node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the text content of the given text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty string when no text found' : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty string when input is null' : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return empty string when input is undefined' : function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should set content with the given text': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should set html content as text': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should preserve spaces': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should replace existing content': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should set text for text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(content, Y.DOM.getText(node, content));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'nextSibling', null, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next element that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the next node that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('span')[0].nextSibling,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'previousSibling', null, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous element that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the previous node that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root.getElementsByTagName('div')[0].previousSibling,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.DOM.elementByAxis(node, 'previousSibling', fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the parent element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(root, Y.DOM.elementByAxis(node, 'parentNode'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the ancestor element that passes the test fn': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when not found': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
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 'should return null when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isNull(Y.DOM.elementByAxis(null, 'previousSibling'));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return null when input is undefined': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the parent node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the same node': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should return the matching ancestor': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(document.body, Y.DOM.ancestor(node, fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestor (test self match)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.areEqual(node, Y.DOM.ancestor(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestor (test self not matched)': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp var root = document.getElementById('test-element-by-axis'),
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp Assert.areEqual(document.body, Y.DOM.ancestor(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return an array of one (documentElement)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should include the starting node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.documentElement, document.body, node],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should omit the starting node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.documentElement, document.body],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestors': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.body], Y.DOM.ancestors(node, fn));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestors (test self match)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([node], Y.DOM.ancestors(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return the matching ancestors (test self not matched)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var root = document.getElementById('test-element-by-axis'),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ArrayAssert.itemsAreEqual([document.body], Y.DOM.ancestors(node, fn, true));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'html element should contain body element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.contains(document.documentElement, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'body element should not contain html element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM.contains(document.body, document.documentElement));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true when element is element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.contains(document.body, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM.contains(document.documentElement, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for null input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for undefined input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'html element should contain body element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.documentElement, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'body element should not contain html element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, document.documentElement));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true when element is element': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.body, document.body));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be true for contained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isTrue(Y.DOM._bruteContains(document.documentElement, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should be false for uncontained text node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, node));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for null input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Assert.isFalse(Y.DOM._bruteContains(document.body, null));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for undefined input': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for off document node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return true for in document node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for removed node': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should work with duplicate IDs in document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should work with duplicate IDs off document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should work with form that has input name="id" and id="id"': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false when input is null': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return false for cloned node off document': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return true for cloned node in document (same id)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should return true for cloned node in document (new id)': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should create empty div': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should trim leading space': function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp 'should create empty div (self-closed input)': function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should create div with text': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp 'should create div with innerHTML': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp Assert.areEqual('<em>bar</em>', el.innerHTML.toLowerCase());
6f294bea19c397d53e471007448460655f4b8c6bTripp 'should create input type submit': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp var el = Y.DOM.create('<input name="foo" value="bar" type="submit">');
6f294bea19c397d53e471007448460655f4b8c6bTripp 'should create input type radio': function() {
6f294bea19c397d53e471007448460655f4b8c6bTripp var el = Y.DOM.create('<input name="test-input" type="radio">');
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp 'should create form': function() {
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>'),
cols = [],
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>',
frag;
var nodes = [
node;