Permalink
Browse files

add support for dl

add test for ul, ol dl
  • Loading branch information...
1 parent 9a4f29f commit 63b0c4805f69c3f9e9e8071da1d1c6c83ad692fd @eskimoblood eskimoblood committed May 14, 2012
Showing with 51 additions and 6 deletions.
  1. +17 −2 fixie.js
  2. +34 −4 test/fetch-test.js
View
@@ -126,6 +126,10 @@ function () {
case 'ul':
element.innerHTML = fixie_fetchList();
break;
+
+ case 'dl':
+ element.innerHTML = fixie_fetchDefinitionList();
+ break;
case 'hr':
break;
@@ -155,7 +159,7 @@ function () {
}
function constrain(min, max){
- return Math.floor(Math.random() * (max - min + 1) + min);
+ return Math.round(Math.random() * (max - min) + min);
}
function fixie_fetch(min, max, func, join) {
@@ -171,7 +175,7 @@ function () {
function fetch_suroundWithTag(min, max, func, tagName) {
var startTag = '<' + tagName + '>';
var endTag = '</' + tagName + '>';
- return startTag + fixie_fetch(4, 8, func, endTag + startTag) + endTag;
+ return startTag + fixie_fetch(min, max, func, endTag + startTag) + endTag;
}
function fixie_fetchPhrase() {
@@ -193,6 +197,17 @@ function () {
function fixie_fetchList() {
return fetch_suroundWithTag(4, 8, fixie_fetchPhrase, 'li');
}
+
+ function fixie_fetchDefinitionList() {
+ var html = ''
+ for (var i = 0, l = constrain(3,5); i < l; i++) {
+ html += fetch_suroundWithTag(1, 1, fixie_fetchPhrase, 'dt') + fetch_suroundWithTag(1, 1, fixie_fetchPhrase, 'dd');
+ }
+ console.log(html)
+ return html;
+ }
+
+
// Handle all elements with class 'fixie'
fixie_handle_elements(document.getElementsByClassName('fixie'));
View
@@ -49,13 +49,25 @@ describe("fixie minimal", function () {
});
});
- ['hr'].forEach(function(tagName){
+ it("should fill a &lt;dl&gt; with a pair of 3 dt/dd", function () {
+ var el = createElementAndInitFixie('dl');
+ assert.same(3, el.getElementsByTagName('dd').length);
+ assert.same(3, el.getElementsByTagName('dt').length);
+ el.parentNode.removeChild(el);
+ });
+
+
+ it("should not fill a &lt;hr&gt;", function () {
+ var el = createElementAndInitFixie('hr');
+ assert.same('', el.innerHTML);
+ el.parentNode.removeChild(el);
+ });
- it("should not fill a &lt;" + tagName + "&gt;", function () {
+ ['ol', 'ul'].forEach(function(tagName){
+ it("should fill a &lt;" + tagName + "&gt; with 4 li", function () {
var el = createElementAndInitFixie(tagName);
- assert.same('', el.innerHTML);
+ assert.same(el.getElementsByTagName('li').length, 4);
el.parentNode.removeChild(el);
-
});
});
});
@@ -90,6 +102,24 @@ describe("fixie maximal", function () {
createElementAndTestParagraphAndSentecesAndWordCount(tagName, isSame(7), isSame(7), isSame(9));
});
});
+
+
+ it("should fill a &lt;dl&gt; with a pair of 5 dt/dd", function () {
+ var el = createElementAndInitFixie('dl');
+ console.log(el.getElementsByTagName('dd'))
+ console.log(el.getElementsByTagName('dt'))
+ assert.same(el.getElementsByTagName('dd').length, 5);
+ assert.same(el.getElementsByTagName('dt').length, 5);
+ el.parentNode.removeChild(el);
+ });
+
+ ['ol', 'ul'].forEach(function(tagName){
+ it("should fill a &lt;" + tagName + "&gt; with 8 li", function () {
+ var el = createElementAndInitFixie(tagName);
+ assert.same(el.getElementsByTagName('li').length, 8);
+ el.parentNode.removeChild(el);
+ });
+ });
});

0 comments on commit 63b0c48

Please sign in to comment.