diff --git a/JsTestDriver.jar b/JsTestDriver.jar deleted file mode 100644 index f3183ed..0000000 Binary files a/JsTestDriver.jar and /dev/null differ diff --git a/jsTestDriver.conf b/jsTestDriver.conf deleted file mode 100644 index dc4d090..0000000 --- a/jsTestDriver.conf +++ /dev/null @@ -1,8 +0,0 @@ -server: http://localhost:4224 - -load: - - src/FTColumnflow.js - - test/css/*.css - - test/*.js - -serve: diff --git a/test/BaselineGridTest.js b/test/BaselineGridTest.js deleted file mode 100644 index bdbee9f..0000000 --- a/test/BaselineGridTest.js +++ /dev/null @@ -1,290 +0,0 @@ -/** - * FTColumnflow BaselineGrid test suite - * - * @copyright The Financial Times Limited [All Rights Reserved] -*/ - - -function createCf(config) { - cf = new FTColumnflow('targetid', 'viewportid', config || { - columnGap : 25, - columnCount : 3 - }); - target = document.getElementById('targetid'); - - return cf; -} - -TestCase('BaselineGrid', { - - setUp : function() { - document.body.innerHTML = '
flowedContent
'); - - var column = target.querySelector('.cf-column-1'); - var p = column.querySelector('p'); - - assertEquals(0, p.offsetTop); - assertEquals('0px', window.getComputedStyle(p).getPropertyValue('margin-top')); - }, - - testItShouldReduceColumnHeightToNearestMultipleOfLineheight : function() { - - document.body.classList.add('lineheight17'); - - createCf().flow('flowedContent
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(595, column.offsetHeight); - }, - - testItShouldReduceColumnHeightToNearestMultipleOfLineheight : function() { - - document.body.classList.add('lineheight17'); - - createCf().flow('flowedContent
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(595, column.offsetHeight); - }, - - testItShouldCalculateCorrectGridHeightWhenLineheightIsInEms : function() { - - document.body.classList.add('lineheight-in-ems'); - - createCf({ - columnGap : 20, - columnCount : 2, - pagePadding : 50, - pageArrangement : 'vertical', - }).flow('flowedContent
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(493, column.offsetHeight); - }, - - testItShouldCalculateCorrectGridHeightWhenLineheightIsInPercent : function() { - - document.body.classList.add('lineheight-in-percent'); - - createCf({ - columnGap : 20, - columnCount : 2, - pagePadding : 50, - pageArrangement : 'vertical', - }).flow('flowedContent
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(493, column.offsetHeight); - }, - - testItShouldCalculateCorrectGridHeightWhenLineheightIsInherit : function() { - - document.body.classList.add('lineheight-inherit'); - - createCf({ - columnGap : 20, - columnCount : 2, - pagePadding : 50, - pageArrangement : 'vertical', - }).flow('flowedContent
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(493, column.offsetHeight); - }, - - testItShouldCalculateCorrectGridHeightWhenLineheightIsMultiplier : function() { - - document.body.classList.add('lineheight-multiplier'); - - createCf({ - columnGap : 20, - columnCount : 2, - pagePadding : 50, - pageArrangement : 'vertical', - }).flow('flowedContent
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(493, column.offsetHeight); - }, - - testItShouldCalculateCorrectGridHeightWhenLineheightIsNormal : function() { - - document.body.classList.add('lineheight-normal'); - - createCf().flow('Test paragraph
Test paragraph
Test paragraph
Test paragraph
Test paragraph
Test paragraph
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(595, column.offsetHeight); - }, - - testItShouldAddMoreElementsIfThereAreNotEnoughToGetAMedianSample : function() { - - document.body.classList.add('lineheight-variable'); - - createCf().flow('Test paragraph
Test paragraph
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(595, column.offsetHeight); - }, - - testItShouldUseLineHeightIfSpecifiedAndNotCalculateIt : function() { - - document.body.classList.add('lineheight-variable'); - - createCf({ - columnGap : 25, - columnCount : 3, - lineHeight : 19 - }).flow('Test paragraph
Test paragraph
Test paragraph
Test paragraph
Test paragraph
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(589, column.offsetHeight); - }, - - testitShouldNotPadElementsByDefault : function() { - - document.body.classList.add('unpadded-parags'); - - createCf().flow('Test paragraph
Test paragraph
Test paragraph
'); - - var column = target.querySelector('.cf-column-1'); - var parags = column.getElementsByTagName('p'); - - assertEquals(53, parags[0].offsetHeight); - assertEquals(53, parags[1].offsetHeight); - assertEquals(53, parags[2].offsetHeight); - - assertEquals(0, parags[0].offsetTop); - assertEquals(73, parags[1].offsetTop); - assertEquals(146, parags[2].offsetTop); - }, - - testitShouldPadElementsWhenConfigured : function() { - - document.body.classList.add('unpadded-parags'); - - createCf({ - standardiseLineHeight : true, - }).flow('Test paragraph
Test paragraph
Test paragraph
'); - - var column = target.querySelector('.cf-column-1'); - var parags = column.getElementsByTagName('p'); - - assertEquals(60, parags[0].offsetHeight); - assertEquals(60, parags[1].offsetHeight); - assertEquals(60, parags[2].offsetHeight); - - assertEquals(0, parags[0].offsetTop); - assertEquals(80, parags[1].offsetTop); - assertEquals(160, parags[2].offsetTop); - }, - - testitShouldPadElementsIgnoringPlainTextNodes : function() { - - document.body.classList.add('unpadded-parags'); - - createCf({ - standardiseLineHeight : true, - }).flow('Test paragraph
\nTest paragraph
\nTest paragraph
'); - - var column = target.querySelector('.cf-column-1'); - var parags = column.getElementsByTagName('p'); - - assertEquals(60, parags[0].offsetHeight); - assertEquals(60, parags[1].offsetHeight); - assertEquals(60, parags[2].offsetHeight); - - assertEquals(0, parags[0].offsetTop); - assertEquals(80, parags[1].offsetTop); - assertEquals(160, parags[2].offsetTop); - }, - - testRegressionItShouldNotMissOffEndOfLastElement : function() { - - document.body.classList.add('unequal-margin'); - - createCf().flow('height1140
height40
'); - - var column1 = target.querySelector('.cf-column-1'); - var column2 = target.querySelector('.cf-column-2'); - var column3 = target.querySelector('.cf-column-3'); - - assertEquals(1, column1.childNodes.length); - assertEquals(2, column2.childNodes.length); - assertEquals(1, column3.childNodes.length); - - assertEquals('-20px', column3.childNodes[0].style.marginTop); - }, - - testRegressionItShouldNotRepeatALine : function() { - - document.body.classList.add('unequal-margin'); - - createCf().flow('height600
height620
'); - - var column1 = target.querySelector('.cf-column-1'); - var column2 = target.querySelector('.cf-column-2'); - var column3 = target.querySelector('.cf-column-3'); - - assertEquals(1, column1.childNodes.length); - assertEquals(1, column2.childNodes.length); - assertEquals(1, column3.childNodes.length); - - assertEquals('-600px', column3.childNodes[0].style.marginTop); - }, - - testRegressionItShouldRemoveTopMarginOfFirstParagInAColumn : function() { - - document.body.classList.add('unequal-margin'); - - createCf().flow('test parag
'); - - var column1 = target.querySelector('.cf-column-1'); - var column2 = target.querySelector('.cf-column-2'); - - assertEquals(1, column1.childNodes.length); - assertEquals(1, column2.childNodes.length); - - assertEquals('0px', column2.childNodes[0].style.marginTop); - }, - -//*/ - -}); \ No newline at end of file diff --git a/test/ColumnWrapTest.js b/test/ColumnWrapTest.js deleted file mode 100644 index fdef458..0000000 --- a/test/ColumnWrapTest.js +++ /dev/null @@ -1,980 +0,0 @@ -/** - * FTColumnflow ColumnWrap test suite - * - * @copyright The Financial Times Limited [All Rights Reserved] -*/ - - -var _exactHeightWrap = 'foo
'); - }); - - assertException(function test() { - cf.flow(new Array); - }, 'FTColumnflowFlowedContentException'); - }, - - testItShouldAcceptNodeOrStringAsFixedParameter : function() { - - createCf(); - - assertNoException(function test() { - cf.flow('', document.createElement('p')); - }); - - assertNoException(function test() { - cf.flow('', 'foo
'); - }); - - assertException(function test() { - cf.flow('', new Array); - }, 'FTColumnflowFixedContentException'); - }, - - testItShouldNotChangeExistingTargetId : function() { - - createCf().flow(); - assertTrue(target instanceof HTMLElement); - }, - - testItShouldAddAnIdToTargetIfNotSet : function() { - - document.body.innerHTML = 'Hello there!
'); - - var preload = target.querySelector('.cf-preload'); - var column = preload.childNodes[0]; - - assertMatch(/^Hello there!
', document.getElementById('contentContainer').innerHTML); - }, - - testItShouldAddAShortParagraphToPage1Column1 : function() { - - createCf().flow('Hello there!
'); - - var page = target.querySelector('.cf-page-1'); - assertTrue(page instanceof HTMLElement); - assertClassName('cf-page', page); - - var column = page.querySelector('.cf-column-1'); - assertTrue(column instanceof HTMLElement); - assertClassName('cf-column', column); - - assertMatch(/^Hello there!
'); - - assertNoMatch(/OVERWRITE/, target.innerHTML); - }, - - testItShouldSetCorrectPageDimensions : function() { - - createCf().flow('Hello there!
'); - - var page = target.querySelector('.cf-page-1'); - - assertEquals(800, page.clientWidth); - assertEquals(600, page.clientHeight); - }, - - testItShouldRespectConfigColumnAndClassNames : function() { - - createCf({ - pageClass : 'mypage', - columnClass : 'mycol', - }).flow('Hello there!
'); - - var page = target.querySelector('.mypage-1'); - assertClassName('mypage', page); - - var column = page.querySelector('.mycol-1'); - assertClassName('mycol', column); - }, - - testItShouldHideOverflowOnGeneratedColumns : function() { - - createCf().flow('Hello there!
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals('hidden', window.getComputedStyle(column).getPropertyValue('overflow')); - }, - - testItShouldSetTheCorrectWidthAndHeightOnTheGeneratedColumn : function() { - - createCf().flow('Hello there!
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(250, column.clientWidth); - assertEquals(600, column.clientHeight); - }, - - testItShouldSetCorrectAbsolutePositioningCss : function() { - - createCf().flow('Hello there!
'); - - var page = target.querySelector('.cf-page-1'); - var column = target.querySelector('.cf-column-1'); - - assertEquals('relative', window.getComputedStyle(target).getPropertyValue('position')); - assertEquals('absolute', window.getComputedStyle(page).getPropertyValue('position')); - assertEquals('absolute', window.getComputedStyle(column).getPropertyValue('position')); - }, - - testItShouldSetTheCorrectPositionOnColumn1 : function() { - - createCf().flow('Hello there!
'); - - var column = target.querySelector('.cf-column-1'); - - assertEquals(0, column.offsetTop); - assertEquals(0, column.offsetLeft); - }, - - testItShouldCreateASecondColumnWhenFirstIsFull : function() { - - createCf().flow(_exactHeightWrap); - - var column1 = target.querySelector('.cf-column-1'); - - var column2 = target.querySelector('.cf-column-2'); - assertTrue(column2 instanceof HTMLElement); - - }, - - testItShouldSetCorrectDimensionsAndPositionOnSecondColumn : function() { - - createCf().flow(_exactHeightWrap); - - var column1 = target.querySelector('.cf-column-1'); - var column2 = target.querySelector('.cf-column-2'); - - assertEquals(250, column1.clientWidth); - assertEquals(600, column1.clientHeight); - - assertEquals(250, column2.clientWidth); - assertEquals(0, column2.offsetTop); - assertEquals(275, column2.offsetLeft); - }, - - testItShouldWriteCorrectElementsToColumns : function() { - - createCf().flow(_exactHeightWrap); - - var column1 = target.querySelector('.cf-column-1'); - var column2 = target.querySelector('.cf-column-2'); - - assertEquals(2, column1.childNodes.length); - - assertClassName('height500', column1.childNodes[0]); - assertClassName('height100', column1.childNodes[1]); - - assertEquals(1, column2.childNodes.length); - - assertClassName('height100', column2.childNodes[0]); - }, - - testItShouldFillColumnsAndCreateSecondPage : function() { - - createCf().flow(_wrapToPage2); - - var page1 = target.querySelector('.cf-page-1'); - var page2 = target.querySelector('.cf-page-2'); - - assertEquals(3, page1.childNodes.length); - - assertTrue(page2 instanceof HTMLElement); - assertEquals(1, page2.childNodes.length); - - var page2col1 = page2.querySelector('.cf-column-1'); - - assertEquals(1, page2col1.childNodes.length); - assertClassName('height100', page2col1.childNodes[0]); - }, - - testItShouldDisplayPagesHorizontallyByDefault : function() { - - createCf().flow(_wrapToPage2); - - var page1 = target.querySelector('.cf-page-1'); - var page2 = target.querySelector('.cf-page-2'); - - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('left')); - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('top')); - - assertEquals('800px', window.getComputedStyle(page2).getPropertyValue('left')); - assertEquals('0px', window.getComputedStyle(page2).getPropertyValue('top')); - }, - - testItShouldDisplayPagesVerticallyWhenSpecified : function() { - - createCf({ - columnGap : 25, - columnCount : 3, - pageArrangement : 'vertical', - }).flow(_wrapToPage2); - - var page1 = target.querySelector('.cf-page-1'); - var page2 = target.querySelector('.cf-page-2'); - - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('left')); - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('top')); - - assertEquals('0px', window.getComputedStyle(page2).getPropertyValue('left')); - assertEquals('600px', window.getComputedStyle(page2).getPropertyValue('top')); - }, - - testItShouldAddPagePadding : function() { - - createCf({ - pagePadding : 50, - columnGap : 25, - columnCount : 5, - }).flow(_wrapToPage2 + _wrapToPage2); - - var page1 = target.querySelector('.cf-page-1'); - var page2 = target.querySelector('.cf-page-2'); - - assertEquals(800, page1.clientWidth); - assertEquals(600, page1.clientHeight); - - assertEquals(800, page2.clientWidth); - assertEquals(600, page2.clientHeight); - - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('left')); - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('top')); - - assertEquals('800px', window.getComputedStyle(page2).getPropertyValue('left')); - assertEquals('0px', window.getComputedStyle(page2).getPropertyValue('top')); - - assertEquals(50, page1.querySelector('.cf-column-1').offsetLeft); - assertEquals(120, page1.querySelector('.cf-column-1').offsetWidth); - - assertEquals(195, page1.querySelector('.cf-column-2').offsetLeft); - assertEquals(630, page1.querySelector('.cf-column-5').offsetLeft); - - assertEquals(50, page2.querySelector('.cf-column-1').offsetLeft); - }, - - testItShouldAddVerticalPagePadding : function() { - - createCf({ - pagePadding : 50, - columnGap : 25, - columnCount : 5, - pageArrangement : 'vertical', - }).flow(_wrapToPage2 + _wrapToPage2); - - var page1 = target.querySelector('.cf-page-1'); - var page2 = target.querySelector('.cf-page-2'); - - assertEquals(800, page1.clientWidth); - assertEquals(600, page1.clientHeight); - - assertEquals(800, page2.clientWidth); - assertEquals(600, page2.clientHeight); - - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('left')); - assertEquals('0px', window.getComputedStyle(page1).getPropertyValue('top')); - - assertEquals('0px', window.getComputedStyle(page2).getPropertyValue('left')); - assertEquals('600px', window.getComputedStyle(page2).getPropertyValue('top')); - - assertEquals(0, page1.querySelector('.cf-column-1').offsetLeft); - assertEquals(50, page1.querySelector('.cf-column-1').offsetTop); - assertEquals(140, page1.querySelector('.cf-column-1').offsetWidth); - assertEquals(500, page1.querySelector('.cf-column-1').offsetHeight); - - assertEquals(50, page2.querySelector('.cf-column-1').offsetTop); - }, - - testItShouldRepeatAnOverflowedElementOnTheNextColumn : function() { - - createCf().flow(_overflowedElement); - - var column1 = target.querySelector('.cf-column-1'); - - assertClassName('height100', column1.childNodes[column1.childNodes.length - 1]); - - var column2 = target.querySelector('.cf-column-2'); - assertTrue(column2 instanceof HTMLElement); - - assertEquals(1, column2.childNodes.length); - assertClassName('height100', column2.childNodes[0]); - - assertEquals(column1.childNodes[2].innerHTML, column2.childNodes[0].innerHTML); - }, - - testItShouldSetNegativeTopMarginOnRemainderOfOverflowedElement : function() { - - createCf().flow(_overflowedElement); - - var column2 = target.querySelector('.cf-column-2'); - var element = column2.childNodes[0]; - - assertEquals('-50px', window.getComputedStyle(element).getPropertyValue('margin-top')); - }, - - testItShouldCorrectlyWrapALargeElementOverManyColumns : function() { - - createCf().flow('parag 1
\nparag 2
\n'); - - var column = target.querySelector('.cf-column-1'); - - assertMatch(/^height600
height600
'); - - var column1 = target.querySelector('.cf-column-1'); - var column2 = target.querySelector('.cf-column-2'); - - assertEquals(1, column1.childNodes.length); - assertEquals(1, column2.childNodes.length); - - assertNull(target.querySelector('.cf-column-3')); - assertEquals('0px', column2.childNodes[0].style.marginTop); - }, - - testItShouldCorrectlyReportSinglePageCount : function() { - - createCf({ - columnCount : 1 - }).flow('flowedContent
'); + + var column = target.querySelector('.cf-column-1'); + var p = column.querySelector('p'); + + assert.match(p.offsetTop, 0); + assert.match(cssProp(p, 'margin-top'), '0px'); + }, + + 'ShouldReduceColumnHeightToNearestMultipleOfLineheight' : function() { + + document.body.className = 'lineheight17'; + + createCf().flow('flowedContent
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 595); + }, + + 'ShouldReduceColumnHeightToNearestMultipleOfLineheight' : function() { + + document.body.className = 'lineheight17'; + + createCf().flow('flowedContent
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 595); + }, + + 'ShouldCalculateCorrectGridHeightWhenLineheightIsInEms' : function() { + + document.body.className = 'lineheight-in-ems'; + + createCf({ + columnGap : 20, + columnCount : 2, + pagePadding : 50, + pageArrangement : 'vertical', + }).flow('flowedContent
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 493); + }, + + 'ShouldCalculateCorrectGridHeightWhenLineheightIsInPercent' : function() { + + document.body.className = 'lineheight-in-percent'; + + createCf({ + columnGap : 20, + columnCount : 2, + pagePadding : 50, + pageArrangement : 'vertical', + }).flow('flowedContent
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 493); + }, + + 'ShouldCalculateCorrectGridHeightWhenLineheightIsInherit' : function() { + + document.body.className = 'lineheight-inherit'; + + createCf({ + columnGap : 20, + columnCount : 2, + pagePadding : 50, + pageArrangement : 'vertical', + }).flow('flowedContent
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 493); + }, + + 'ShouldCalculateCorrectGridHeightWhenLineheightIsMultiplier' : function() { + + document.body.className = 'lineheight-multiplier'; + + createCf({ + columnGap : 20, + columnCount : 2, + pagePadding : 50, + pageArrangement : 'vertical', + }).flow('flowedContent
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 493); + }, + + 'ShouldCalculateCorrectGridHeightWhenLineheightIsNormal' : function() { + + document.body.className = 'lineheight-normal'; + + createCf().flow('Test paragraph
Test paragraph
Test paragraph
Test paragraph
Test paragraph
Test paragraph
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 595); + }, + + 'ShouldAddMoreElementsIfThereAreNotEnoughToGetAMedianSample' : function() { + + document.body.className = 'lineheight-variable'; + + createCf().flow('Test paragraph
Test paragraph
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 595); + }, + + 'ShouldUseLineHeightIfSpecifiedAndNotCalculateIt' : function() { + + document.body.className = 'lineheight-variable'; + + createCf({ + columnGap : 25, + columnCount : 3, + lineHeight : 19 + }).flow('Test paragraph
Test paragraph
Test paragraph
Test paragraph
Test paragraph
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetHeight, 589); + }, + + 'ShouldNotPadElementsByDefault' : function() { + + document.body.className = 'unpadded-parags'; + + createCf().flow('Test paragraph
Test paragraph
Test paragraph
'); + + var column = target.querySelector('.cf-column-1'); + var parags = column.getElementsByTagName('p'); + + assert.match(parags[0].offsetHeight, 53); + assert.match(parags[1].offsetHeight, 53); + assert.match(parags[2].offsetHeight, 53); + + assert.match(parags[0].offsetTop, 0); + assert.match(parags[1].offsetTop, 73); + assert.match(parags[2].offsetTop, 146); + }, + + 'ShouldPadElementsWhenConfigured' : function() { + + document.body.className = 'unpadded-parags'; + + createCf({ + standardiseLineHeight : true, + }).flow('Test paragraph
Test paragraph
Test paragraph
'); + + var column = target.querySelector('.cf-column-1'); + var parags = column.getElementsByTagName('p'); + + assert.match(parags[0].offsetHeight, 60); + assert.match(parags[1].offsetHeight, 60); + assert.match(parags[2].offsetHeight, 60); + + assert.match(parags[0].offsetTop, 0); + assert.match(parags[1].offsetTop, 80); + assert.match(parags[2].offsetTop, 160); + }, + + 'ShouldPadElementsIgnoringPlainTextNodes' : function() { + + document.body.className = 'unpadded-parags'; + + createCf({ + standardiseLineHeight : true, + }).flow('Test paragraph
\nTest paragraph
\nTest paragraph
'); + + var column = target.querySelector('.cf-column-1'); + var parags = column.getElementsByTagName('p'); + + assert.match(parags[0].offsetHeight, 60); + assert.match(parags[1].offsetHeight, 60); + assert.match(parags[2].offsetHeight, 60); + + assert.match(parags[0].offsetTop, 0); + assert.match(parags[1].offsetTop, 80); + assert.match(parags[2].offsetTop, 160); + }, + + 'RegressionItShouldNotMissOffEndOfLastElement' : function() { + + document.body.className = 'unequal-margin'; + + createCf().flow('height1140
height40
'); + + var column1 = target.querySelector('.cf-column-1'); + var column2 = target.querySelector('.cf-column-2'); + var column3 = target.querySelector('.cf-column-3'); + + assert.match(column1.childNodes.length, 1); + assert.match(column2.childNodes.length, 2); + assert.match(column3.childNodes.length, 1); + + assert.match(column3.childNodes[0].style.marginTop, '-20px'); + }, + + 'RegressionItShouldNotRepeatALine' : function() { + + document.body.className = 'unequal-margin'; + + createCf().flow('height600
height620
'); + + var column1 = target.querySelector('.cf-column-1'); + var column2 = target.querySelector('.cf-column-2'); + var column3 = target.querySelector('.cf-column-3'); + + assert.match(column1.childNodes.length, 1); + assert.match(column2.childNodes.length, 1); + assert.match(column3.childNodes.length, 1); + + assert.match(column3.childNodes[0].style.marginTop, '-600px'); + }, + + 'RegressionItShouldRemoveTopMarginOfFirstParagInAColumn' : function() { + + document.body.className = 'unequal-margin'; + + createCf().flow('test parag
'); + + var column1 = target.querySelector('.cf-column-1'); + var column2 = target.querySelector('.cf-column-2'); + + assert.match(column1.childNodes.length, 1); + assert.match(column2.childNodes.length, 1); + + assert.match(column2.childNodes[0].style.marginTop, '0px'); + }, + +//*/ + +}); \ No newline at end of file diff --git a/test/buster.js b/test/buster.js new file mode 100644 index 0000000..5de6342 --- /dev/null +++ b/test/buster.js @@ -0,0 +1,58 @@ +var config = module.exports; + + +config["My tests"] = { + rootPath: "../", + environment: "browser", // or "node" + sources: [ + "src/FTColumnflow.js", + ], + tests: [ + "test/*-test.js" + ], + testHelpers: [ + "test/helpers/*.js" + ], + resources: [ + { + path: "/", + content: '\n' + + '\n' + + ' \n' + + 'foo
'); + }); + + assert.exception(function test() { + cf.flow(new Array); + }, 'FTColumnflowFlowedContentException'); + }, + + 'ShouldAcceptNodeOrStringAsFixedParameter' : function() { + + createCf(); + + refute.exception(function test() { + cf.flow('', document.createElement('p')); + }); + + refute.exception(function test() { + cf.flow('', 'foo
'); + }); + + assert.exception(function test() { + cf.flow('', new Array); + }, 'FTColumnflowFixedContentException'); + }, + + 'ShouldNotChangeExistingTargetId' : function() { + + createCf().flow(); + assert(target instanceof HTMLElement); + }, + + 'ShouldAddAnIdToTargetIfNotSet' : function() { + + document.body.innerHTML = 'Hello there!
'); + + var preload = target.querySelector('.cf-preload'); + var column = preload.childNodes[0]; + + assert.match(column.innerHTML, /^Hello there!
'); + }, + + 'ShouldAddAShortParagraphToPage1Column1' : function() { + + createCf().flow('Hello there!
'); + + var page = target.querySelector('.cf-page-1'); + assert(page instanceof HTMLElement); + assert.className(page, 'cf-page'); + + var column = page.querySelector('.cf-column-1'); + assert(column instanceof HTMLElement); + assert.className(column, 'cf-column'); + + assert.match(column.innerHTML, /^Hello there!
'); + + refute.match(target.innerHTML, /OVERWRITE/); + }, + + 'ShouldSetCorrectPageDimensions' : function() { + + createCf().flow('Hello there!
'); + + var page = target.querySelector('.cf-page-1'); + + assert.match(page.clientWidth, 800); + assert.match(page.clientHeight, 600); + }, + + 'ShouldRespectConfigColumnAndClassNames' : function() { + + createCf({ + pageClass : 'mypage', + columnClass : 'mycol', + }).flow('Hello there!
'); + + var page = target.querySelector('.mypage-1'); + assert.className(page, 'mypage'); + + var column = page.querySelector('.mycol-1'); + assert.className(column, 'mycol'); + }, + + 'ShouldHideOverflowOnGeneratedColumns' : function() { + + createCf().flow('Hello there!
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(cssProp(column, 'overflow'), 'hidden'); + }, + + 'ShouldSetTheCorrectWidthAndHeightOnTheGeneratedColumn' : function() { + + createCf().flow('Hello there!
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.clientWidth, 250); + assert.match(column.clientHeight, 600); + }, + + 'ShouldSetCorrectAbsolutePositioningCss' : function() { + + createCf().flow('Hello there!
'); + + var page = target.querySelector('.cf-page-1'); + var column = target.querySelector('.cf-column-1'); + + assert.match(cssProp(target, 'position'), 'relative'); + assert.match(cssProp(page, 'position'), 'absolute'); + assert.match(cssProp(column, 'position'), 'absolute'); + }, + + 'ShouldSetTheCorrectPositionOnColumn1' : function() { + + createCf().flow('Hello there!
'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.offsetTop, 0); + assert.match(column.offsetLeft, 0); + }, + + 'ShouldCreateASecondColumnWhenFirstIsFull' : function() { + + createCf().flow(_exactHeightWrap); + + var column1 = target.querySelector('.cf-column-1'); + + var column2 = target.querySelector('.cf-column-2'); + assert(column2 instanceof HTMLElement); + + }, + + 'ShouldSetCorrectDimensionsAndPositionOnSecondColumn' : function() { + + createCf().flow(_exactHeightWrap); + + var column1 = target.querySelector('.cf-column-1'); + var column2 = target.querySelector('.cf-column-2'); + + assert.match(column1.clientWidth, 250); + assert.match(column1.clientHeight, 600); + + assert.match(column2.clientWidth, 250); + assert.match(column2.offsetTop, 0); + assert.match(column2.offsetLeft, 275); + }, + + 'ShouldWriteCorrectElementsToColumns' : function() { + + createCf().flow(_exactHeightWrap); + + var column1 = target.querySelector('.cf-column-1'); + var column2 = target.querySelector('.cf-column-2'); + + assert.match(column1.childNodes.length, 2); + + assert.className(column1.childNodes[0], 'height500'); + assert.className(column1.childNodes[1], 'height100'); + + assert.match(column2.childNodes.length, 1); + + assert.className(column2.childNodes[0], 'height100'); + }, + + 'ShouldFillColumnsAndCreateSecondPage' : function() { + + createCf().flow(_wrapToPage2); + + var page1 = target.querySelector('.cf-page-1'); + var page2 = target.querySelector('.cf-page-2'); + + assert.match(page1.childNodes.length, 3); + + assert(page2 instanceof HTMLElement); + assert.match(page2.childNodes.length, 1); + + var page2col1 = page2.querySelector('.cf-column-1'); + + assert.match(page2col1.childNodes.length, 1); + assert.className(page2col1.childNodes[0], 'height100'); + }, + + 'ShouldDisplayPagesHorizontallyByDefault' : function() { + + createCf().flow(_wrapToPage2); + + var page1 = target.querySelector('.cf-page-1'); + var page2 = target.querySelector('.cf-page-2'); + + assert.match(cssProp(page1, 'left'), '0px'); + assert.match(cssProp(page1, 'top'), '0px'); + + assert.match(cssProp(page2, 'left'), '800px'); + assert.match(cssProp(page2, 'top'), '0px'); + }, + + 'ShouldDisplayPagesVerticallyWhenSpecified' : function() { + + createCf({ + columnGap : 25, + columnCount : 3, + pageArrangement : 'vertical', + }).flow(_wrapToPage2); + + var page1 = target.querySelector('.cf-page-1'); + var page2 = target.querySelector('.cf-page-2'); + + assert.match(cssProp(page1, 'left'), '0px'); + assert.match(cssProp(page1, 'top'), '0px'); + + assert.match(cssProp(page2, 'left'), '0px'); + assert.match(cssProp(page2, 'top'), '600px'); + }, + + 'ShouldAddPagePadding' : function() { + + createCf({ + pagePadding : 50, + columnGap : 25, + columnCount : 5, + }).flow(_wrapToPage2 + _wrapToPage2); + + var page1 = target.querySelector('.cf-page-1'); + var page2 = target.querySelector('.cf-page-2'); + + assert.match(page1.clientWidth, 800); + assert.match(page1.clientHeight, 600); + + assert.match(page2.clientWidth, 800); + assert.match(page2.clientHeight, 600); + + assert.match(cssProp(page1, 'left'), '0px'); + assert.match(cssProp(page1, 'top'), '0px'); + + assert.match(cssProp(page2, 'left'), '800px'); + assert.match(cssProp(page2, 'top'), '0px'); + + assert.match(page1.querySelector('.cf-column-1').offsetLeft, 50); + assert.match(page1.querySelector('.cf-column-1').offsetWidth, 120); + + assert.match(page1.querySelector('.cf-column-2').offsetLeft, 195); + assert.match(page1.querySelector('.cf-column-5').offsetLeft, 630); + + assert.match(page2.querySelector('.cf-column-1').offsetLeft, 50); + }, + + 'ShouldAddVerticalPagePadding' : function() { + + createCf({ + pagePadding : 50, + columnGap : 25, + columnCount : 5, + pageArrangement : 'vertical', + }).flow(_wrapToPage2 + _wrapToPage2); + + var page1 = target.querySelector('.cf-page-1'); + var page2 = target.querySelector('.cf-page-2'); + + assert.match(page1.clientWidth, 800); + assert.match(page1.clientHeight, 600); + + assert.match(page2.clientWidth, 800); + assert.match(page2.clientHeight, 600); + + assert.match(cssProp(page1, 'left'), '0px'); + assert.match(cssProp(page1, 'top'), '0px'); + + assert.match(cssProp(page2, 'left'), '0px'); + assert.match(cssProp(page2, 'top'), '600px'); + + assert.match(page1.querySelector('.cf-column-1').offsetLeft, 0); + assert.match(page1.querySelector('.cf-column-1').offsetTop, 50); + assert.match(page1.querySelector('.cf-column-1').offsetWidth, 140); + assert.match(page1.querySelector('.cf-column-1').offsetHeight, 500); + + assert.match(page2.querySelector('.cf-column-1').offsetTop, 50); + }, + + 'ShouldRepeatAnOverflowedElementOnTheNextColumn' : function() { + + createCf().flow(_overflowedElement); + + var column1 = target.querySelector('.cf-column-1'); + + assert.className(column1.childNodes[column1.childNodes.length - 1], 'height100'); + + var column2 = target.querySelector('.cf-column-2'); + assert(column2 instanceof HTMLElement); + + assert.match(column2.childNodes.length, 1); + assert.className(column2.childNodes[0], 'height100'); + + assert.match(column2.childNodes[0].innerHTML, column1.childNodes[2].innerHTML); + }, + + 'ShouldSetNegativeTopMarginOnRemainderOfOverflowedElement' : function() { + + createCf().flow(_overflowedElement); + + var column2 = target.querySelector('.cf-column-2'); + var element = column2.childNodes[0]; + + assert.match(cssProp(element, 'margin-top'), '-50px'); + }, + + 'ShouldCorrectlyWrapALargeElementOverManyColumns' : function() { + + createCf().flow('parag 1
\nparag 2
\n'); + + var column = target.querySelector('.cf-column-1'); + + assert.match(column.innerHTML, /^height600
height600
'); + + var column1 = target.querySelector('.cf-column-1'); + var column2 = target.querySelector('.cf-column-2'); + + assert.match(column1.childNodes.length, 1); + assert.match(column2.childNodes.length, 1); + + assert.isNull(target.querySelector('.cf-column-3')); + assert.match(column2.childNodes[0].style.marginTop, '0px'); + }, + + 'ShouldCorrectlyReportSinglePageCount' : function() { + + createCf({ + columnCount : 1 + }).flow('flowedContent
', 'flowedContent
', '\nflowedContent
', 'flowedContent
', 'flowedContent
', 'flowedContent
', '