From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../microformats/test/module-tests/dates-test.js | 113 +++++++++++ .../test/module-tests/domutils-test.js | 206 +++++++++++++++++++++ .../microformats/test/module-tests/html-test.js | 50 +++++ .../microformats/test/module-tests/index.html | 76 ++++++++ .../microformats/test/module-tests/isodate-test.js | 145 +++++++++++++++ .../microformats/test/module-tests/text-test.js | 56 ++++++ .../microformats/test/module-tests/url-test.js | 25 +++ .../test/module-tests/utilities-test.js | 93 ++++++++++ 8 files changed, 764 insertions(+) create mode 100644 toolkit/components/microformats/test/module-tests/dates-test.js create mode 100644 toolkit/components/microformats/test/module-tests/domutils-test.js create mode 100644 toolkit/components/microformats/test/module-tests/html-test.js create mode 100644 toolkit/components/microformats/test/module-tests/index.html create mode 100644 toolkit/components/microformats/test/module-tests/isodate-test.js create mode 100644 toolkit/components/microformats/test/module-tests/text-test.js create mode 100644 toolkit/components/microformats/test/module-tests/url-test.js create mode 100644 toolkit/components/microformats/test/module-tests/utilities-test.js (limited to 'toolkit/components/microformats/test/module-tests') diff --git a/toolkit/components/microformats/test/module-tests/dates-test.js b/toolkit/components/microformats/test/module-tests/dates-test.js new file mode 100644 index 000000000..e5e034190 --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/dates-test.js @@ -0,0 +1,113 @@ +/* +Unit test for dates +*/ + +assert = chai.assert; + +// Tests the private Modules.dates object +// Modules.dates is unit tested as it has an interface access by other modules + + +describe('Modules.dates', function() { + + + it('hasAM', function(){ + assert.isTrue( Modules.dates.hasAM( '5am' ) ); + assert.isTrue( Modules.dates.hasAM( '5AM' ) ); + assert.isTrue( Modules.dates.hasAM( '5 am' ) ); + assert.isTrue( Modules.dates.hasAM( '5a.m.' ) ); + assert.isTrue( Modules.dates.hasAM( '5:20 a.m.' ) ); + assert.isFalse( Modules.dates.hasAM( '5pm' ) ); + }); + + + it('hasPM', function(){ + assert.isTrue( Modules.dates.hasPM( '5pm' ) ); + assert.isTrue( Modules.dates.hasPM( '5PM' ) ); + assert.isTrue( Modules.dates.hasPM( '5 pm' ) ); + assert.isTrue( Modules.dates.hasPM( '5p.m.' ) ); + assert.isTrue( Modules.dates.hasPM( '5:20 p.m.' ) ); + assert.isFalse( Modules.dates.hasPM( '5am' ) ); + }); + + + it('removeAMPM', function(){ + assert.equal( Modules.dates.removeAMPM( '5pm' ), '5' ); + assert.equal( Modules.dates.removeAMPM( '5 pm' ), '5 ' ); + assert.equal( Modules.dates.removeAMPM( '5p.m.' ), '5' ); + assert.equal( Modules.dates.removeAMPM( '5am' ), '5' ); + assert.equal( Modules.dates.removeAMPM( '5a.m.' ), '5' ); + assert.equal( Modules.dates.removeAMPM( '5' ), '5' ); + }); + + + it('isDuration', function(){ + assert.isTrue( Modules.dates.isDuration( 'PY17M' ) ); + assert.isTrue( Modules.dates.isDuration( 'PW12' ) ); + assert.isTrue( Modules.dates.isDuration( 'P0.5Y' ) ); + assert.isTrue( Modules.dates.isDuration( 'P3Y6M4DT12H30M5S' ) ); + assert.isFalse( Modules.dates.isDuration( '2015-01-23T13:45' ) ); + assert.isFalse( Modules.dates.isDuration( '2015-01-23 13:45' ) ); + assert.isFalse( Modules.dates.isDuration( '20150123T1345' ) ); + }); + + + it('isTime', function(){ + assert.isTrue( Modules.dates.isTime( '8:43' ) ); + assert.isTrue( Modules.dates.isTime( '08:43' ) ); + assert.isTrue( Modules.dates.isTime( '15:23:00:0567' ) ); + assert.isTrue( Modules.dates.isTime( '10:34pm' ) ); + assert.isTrue( Modules.dates.isTime( '10:34 p.m.' ) ); + assert.isTrue( Modules.dates.isTime( '+01:00:00' ) ); + assert.isTrue( Modules.dates.isTime( '-02:00' ) ); + assert.isTrue( Modules.dates.isTime( 'z15:00' ) ); + assert.isTrue( Modules.dates.isTime( '0843' ) ); + assert.isFalse( Modules.dates.isTime( 'P3Y6M4DT12H30M5S' ) ); + assert.isFalse( Modules.dates.isTime( '2015-01-23T13:45' ) ); + assert.isFalse( Modules.dates.isTime( '2015-01-23 13:45' ) ); + assert.isFalse( Modules.dates.isTime( '20150123T1345' ) ); + assert.isFalse( Modules.dates.isTime( 'abc' ) ); + assert.isFalse( Modules.dates.isTime( '12345' ) ); + }); + + + it('parseAmPmTime', function(){ + assert.equal( Modules.dates.parseAmPmTime( '5am' ), '05' ); + assert.equal( Modules.dates.parseAmPmTime( '12pm' ), '12' ); + assert.equal( Modules.dates.parseAmPmTime( '5a.m.' ), '05' ); + assert.equal( Modules.dates.parseAmPmTime( '5pm' ), '17' ); + assert.equal( Modules.dates.parseAmPmTime( '5:34pm' ), '17:34' ); + assert.equal( Modules.dates.parseAmPmTime( '5:04pm' ), '17:04' ); + assert.equal( Modules.dates.parseAmPmTime( '05:34:00' ), '05:34:00' ); + assert.equal( Modules.dates.parseAmPmTime( '05:34:00' ), '05:34:00' ); + assert.equal( Modules.dates.parseAmPmTime( '1:52:04pm' ), '13:52:04' ); + }); + + + it('dateTimeUnion', function(){ + assert.equal( Modules.dates.dateTimeUnion( '2015-01-23', '05:34:00', 'HTML5' ).toString('HTML5'), '2015-01-23 05:34:00' ); + assert.equal( Modules.dates.dateTimeUnion( '2015-01-23', '05:34', 'HTML5' ).toString('HTML5'), '2015-01-23 05:34' ); + assert.equal( Modules.dates.dateTimeUnion( '2015-01-23', '05', 'HTML5' ).toString('HTML5'), '2015-01-23 05' ); + assert.equal( Modules.dates.dateTimeUnion( '2009-06-26T19:00', '2200', 'HTML5' ).toString('HTML5'), '2009-06-26 22:00' ); + + assert.equal( Modules.dates.dateTimeUnion( '2015-01-23', '', 'HTML5' ).toString('HTML5'), '2015-01-23' ); + assert.equal( Modules.dates.dateTimeUnion( '', '', 'HTML5' ).toString('HTML5'), '' ); + }); + + + it('concatFragments', function(){ + assert.equal( Modules.dates.concatFragments( ['2015-01-23', '05:34:00'], 'HTML5' ).toString('HTML5'), '2015-01-23 05:34:00' ); + assert.equal( Modules.dates.concatFragments( ['05:34:00', '2015-01-23'], 'HTML5' ).toString('HTML5'), '2015-01-23 05:34:00' ); + assert.equal( Modules.dates.concatFragments( ['2015-01-23T05:34:00'], 'HTML5' ).toString('HTML5'), '2015-01-23 05:34:00' ); + assert.equal( Modules.dates.concatFragments( ['2015-01-23', '05:34:00', 'z'], 'HTML5' ).toString('HTML5'), '2015-01-23 05:34:00Z' ); + assert.equal( Modules.dates.concatFragments( ['2015-01-23', '05:34', '-01'], 'HTML5' ).toString('HTML5'), '2015-01-23 05:34-01' ); + assert.equal( Modules.dates.concatFragments( ['2015-01-23', '05:34', '-01:00'], 'HTML5' ).toString('HTML5'), '2015-01-23 05:34-01:00' ); + assert.equal( Modules.dates.concatFragments( ['2015-01-23', '05:34-01:00'], 'HTML5' ).toString('HTML5'), '2015-01-23 05:34-01:00' ); + + }); + + + + + +}); diff --git a/toolkit/components/microformats/test/module-tests/domutils-test.js b/toolkit/components/microformats/test/module-tests/domutils-test.js new file mode 100644 index 000000000..5d3f036a9 --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/domutils-test.js @@ -0,0 +1,206 @@ +/* +Unit test for domutils +*/ + +assert = chai.assert; + + +// Tests the private Modules.domUtils object +// Modules.domUtils is unit tested as it has an interface access by other modules + + +describe('Modules.domutils', function() { + + + it('ownerDocument', function(){ + var node = document.createElement('div'); + assert.equal( Modules.domUtils.ownerDocument( node ).nodeType, 9); + }); + + + it('innerHTML', function(){ + var html = 'Glenn Jones', + node = document.createElement('div'); + + node.innerHTML = html; + assert.equal( Modules.domUtils.innerHTML( node ), html ); + }); + + + it('hasAttribute', function(){ + var node = document.createElement('a'); + + node.href = 'http://glennjones.net'; + assert.isTrue( Modules.domUtils.hasAttribute( node, 'href' ) ); + assert.isFalse( Modules.domUtils.hasAttribute( node, 'class' ) ); + }); + + + it('hasAttributeValue', function(){ + var node = document.createElement('a'); + + node.href = 'http://glennjones.net'; + assert.isTrue( Modules.domUtils.hasAttributeValue( node, 'href', 'http://glennjones.net' ) ); + assert.isFalse( Modules.domUtils.hasAttributeValue( node, 'href', 'http://example.net' ) ); + assert.isFalse( Modules.domUtils.hasAttributeValue( node, 'class', 'test' ) ); + }); + + + it('getAttribute', function(){ + var node = document.createElement('a'); + + node.href = 'http://glennjones.net'; + assert.equal( Modules.domUtils.getAttribute( node, 'href' ), 'http://glennjones.net' ); + }); + + + it('setAttribute', function(){ + var node = document.createElement('a'); + + Modules.domUtils.setAttribute(node, 'href', 'http://glennjones.net') + assert.equal( Modules.domUtils.getAttribute( node, 'href' ), 'http://glennjones.net' ); + }); + + + it('removeAttribute', function(){ + var node = document.createElement('a'); + + node.href = 'http://glennjones.net'; + Modules.domUtils.removeAttribute(node, 'href') + assert.isFalse( Modules.domUtils.hasAttribute( node, 'href' ) ); + }); + + + it('getAttributeList', function(){ + var node = document.createElement('a'); + + node.rel = 'next'; + assert.deepEqual( Modules.domUtils.getAttributeList( node, 'rel'), ['next'] ); + node.rel = 'next bookmark'; + assert.deepEqual( Modules.domUtils.getAttributeList( node, 'rel'), ['next','bookmark'] ); + }); + + + it('hasAttributeValue', function(){ + var node = document.createElement('a'); + + node.href = 'http://glennjones.net'; + node.rel = 'next bookmark'; + assert.isTrue( Modules.domUtils.hasAttributeValue( node, 'href', 'http://glennjones.net' ) ); + assert.isFalse( Modules.domUtils.hasAttributeValue( node, 'href', 'http://codebits.glennjones.net' ) ); + assert.isFalse( Modules.domUtils.hasAttributeValue( node, 'class', 'p-name' ) ); + assert.isTrue( Modules.domUtils.hasAttributeValue( node, 'rel', 'bookmark' ) ); + assert.isFalse( Modules.domUtils.hasAttributeValue( node, 'rel', 'previous' ) ); + }); + + + it('getNodesByAttribute', function(){ + var node = document.createElement('ul'); + node.innerHTML = '
  • one
  • two
  • three
  • '; + + assert.equal( Modules.domUtils.getNodesByAttribute( node, 'class' ).length, 2 ); + assert.equal( Modules.domUtils.getNodesByAttribute( node, 'href' ).length, 0 ); + }); + + + it('getNodesByAttributeValue', function(){ + var node = document.createElement('ul'); + node.innerHTML = '
  • one
  • two
  • three
  • four
  • '; + + assert.equal( Modules.domUtils.getNodesByAttributeValue( node, 'class', 'h-card' ).length, 2 ); + assert.equal( Modules.domUtils.getNodesByAttributeValue( node, 'class', 'p-name' ).length, 1 ); + assert.equal( Modules.domUtils.getNodesByAttributeValue( node, 'class', 'u-url' ).length, 0 ); + }); + + + it('getAttrValFromTagList', function(){ + var node = document.createElement('a'); + + node.href = 'http://glennjones.net'; + + assert.equal( Modules.domUtils.getAttrValFromTagList( node, ['a','area'], 'href' ), 'http://glennjones.net' ); + assert.equal( Modules.domUtils.getAttrValFromTagList( node, ['a','area'], 'class' ), null ); + assert.equal( Modules.domUtils.getAttrValFromTagList( node, ['p'], 'href' ), null ); + }); + + + it('getSingleDescendant', function(){ + var html = 'Glenn Jones', + node = document.createElement('div'); + + node.innerHTML = html, + + // one instance of a element + assert.equal( Modules.domUtils.getSingleDescendant( node ).outerHTML, html ); + + // two instances of a element + node.appendChild(document.createElement('a')); + assert.equal( Modules.domUtils.getSingleDescendant( node ), null ); + + }); + + + it('getSingleDescendantOfType', function(){ + var html = 'Glenn Jones', + node = document.createElement('div'); + + node.innerHTML = html, + + // one instance of a element + assert.equal( Modules.domUtils.getSingleDescendantOfType( node, ['a', 'link']).outerHTML, html ); + assert.equal( Modules.domUtils.getSingleDescendantOfType( node, ['img','area']), null ); + + node.appendChild(document.createElement('p')); + assert.equal( Modules.domUtils.getSingleDescendantOfType( node, ['a', 'link']).outerHTML, html ); + + // two instances of a element + node.appendChild(document.createElement('a')); + assert.equal( Modules.domUtils.getSingleDescendantOfType( node, ['a', 'link']), null ); + + }); + + + it('appendChild', function(){ + var node = document.createElement('div'), + child = document.createElement('a'); + + Modules.domUtils.appendChild( node, child ); + assert.equal( node.innerHTML, '' ); + }); + + + it('removeChild', function(){ + var node = document.createElement('div'), + child = document.createElement('a'); + + node.appendChild(child) + + assert.equal( node.innerHTML, '' ); + Modules.domUtils.removeChild( child ); + assert.equal( node.innerHTML, '' ); + }); + + + it('clone', function(){ + var node = document.createElement('div'); + + node.innerHTML = 'text content'; + assert.equal( Modules.domUtils.clone( node ).outerHTML, '
    text content
    ' ); + }); + + + it('getElementText', function(){ + assert.equal( Modules.domUtils.getElementText( {} ), '' ); + }); + + + it('getNodePath', function(){ + var node = document.createElement('ul'); + node.innerHTML = '
    '; + var child = node.querySelector('.p-name'); + + assert.deepEqual( Modules.domUtils.getNodePath( child ), [0,0,3] ); + }); + + +}); diff --git a/toolkit/components/microformats/test/module-tests/html-test.js b/toolkit/components/microformats/test/module-tests/html-test.js new file mode 100644 index 000000000..cd06c7b7f --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/html-test.js @@ -0,0 +1,50 @@ +/* +Unit test for html +*/ + +assert = chai.assert; + +// Tests the private Modules.html object +// Modules.html is unit tested as it has an interface access by other modules + +describe('Modules.html', function() { + + + it('parse', function(){ + var html = 'Glenn Jones', + bloghtml = '
    1. This be the title

      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque venenatis nunc vitae libero iaculis elementum. Nullam et justo non sapien dapibus blandit nec et leo. Ut ut malesuada tellus.

    ', + node = document.createElement('div'); + + node.innerHTML = html; + assert.equal(Modules.html.parse( node ), html ); + + // make sure excludes 'data-include' marked items + var child = document.createElement('p'); + child.setAttribute('data-include', 'true'); + node.appendChild(child); + assert.equal( Modules.html.parse( node ), html ); + + node = document.createElement('div'); + node.innerHTML = bloghtml; + assert.equal( Modules.html.parse( node ), bloghtml ); + + node = document.createElement('div'); + assert.equal( Modules.html.parse( node ), '' ); + + child = document.createElement('br'); + node.appendChild(child); + assert.equal( Modules.html.parse( node ), '
    ' ); + + node = document.createComment('test comment'); + assert.equal( Modules.html.parse( node ), '' ); + + }); + + + + + + + + +}); diff --git a/toolkit/components/microformats/test/module-tests/index.html b/toolkit/components/microformats/test/module-tests/index.html new file mode 100644 index 000000000..0eb3c2040 --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/index.html @@ -0,0 +1,76 @@ +Mocha + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    Microformats-shiv: module tests

    +
    + + + diff --git a/toolkit/components/microformats/test/module-tests/isodate-test.js b/toolkit/components/microformats/test/module-tests/isodate-test.js new file mode 100644 index 000000000..5f081f81c --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/isodate-test.js @@ -0,0 +1,145 @@ +/* +Unit test for dates +*/ + +assert = chai.assert; + + +// Tests private Modules.ISODate object +// Modules.ISODate is unit tested as it has an interface access by other modules + + +describe('Modules.ISODates', function() { + + + + it('constructor', function(){ + assert.equal( new Modules.ISODate().toString('auto'), '' ); + assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'html5').toString('html5'), '2015-01-23 05:34:00' ); + assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'w3c').toString('w3c'), '2015-01-23T05:34:00' ); + assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'html5').toString('rfc3339'), '20150123T053400' ); + assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'auto').toString('auto'), '2015-01-23T05:34:00' ); + }); + + + it('parse', function(){ + assert.equal( new Modules.ISODate().parse('2015-01-23T05:34:00', 'html5').toString('html5'), '2015-01-23 05:34:00' ); + assert.equal( new Modules.ISODate().parse('2015-01-23T05:34:00', 'auto').toString('auto'), '2015-01-23T05:34:00' ); + assert.equal( new Modules.ISODate().parse('2015-01-23t05:34:00', 'auto').toString('auto'), '2015-01-23t05:34:00' ); + + assert.equal( new Modules.ISODate().parse('2015-01-23t05:34:00Z', 'auto').toString('auto'), '2015-01-23t05:34:00Z' ); + assert.equal( new Modules.ISODate().parse('2015-01-23t05:34:00z', 'auto').toString('auto'), '2015-01-23t05:34:00z' ); + assert.equal( new Modules.ISODate().parse('2015-01-23 05:34:00Z', 'auto').toString('auto'), '2015-01-23 05:34:00Z' ); + assert.equal( new Modules.ISODate().parse('2015-01-23 05:34', 'auto').toString('auto'), '2015-01-23 05:34' ); + assert.equal( new Modules.ISODate().parse('2015-01-23 05', 'auto').toString('auto'), '2015-01-23 05' ); + + assert.equal( new Modules.ISODate().parse('2015-01-23 05:34+01:00', 'auto').toString('auto'), '2015-01-23 05:34+01:00' ); + assert.equal( new Modules.ISODate().parse('2015-01-23 05:34-01:00', 'auto').toString('auto'), '2015-01-23 05:34-01:00' ); + assert.equal( new Modules.ISODate().parse('2015-01-23 05:34-01', 'auto').toString('auto'), '2015-01-23 05:34-01' ); + + + assert.equal( new Modules.ISODate().parse('2015-01-23', 'auto').toString('auto'), '2015-01-23' ); + // TODO support for importing rfc3339 profile dates + // assert.equal( new Modules.ISODate().parse('20150123t0534', 'auto').toString('auto'), '2015-01-23 05:34' ); + }); + + + it('parseDate', function(){ + assert.equal( new Modules.ISODate().parseDate('2015-01-23T05:34:00', 'html5'), '2015-01-23' ); + assert.equal( new Modules.ISODate().parseDate('2015-01-23', 'auto'), '2015-01-23' ); + assert.equal( new Modules.ISODate().parseDate('2015-01', 'auto'), '2015-01' ); + assert.equal( new Modules.ISODate().parseDate('2015', 'auto'), '2015' ); + assert.equal( new Modules.ISODate().parseDate('2015-134', 'auto'), '2015-134' ); + }); + + + it('parseTime', function(){ + assert.equal( new Modules.ISODate().parseTime('05:34:00.1267', 'html5'), '05:34:00.1267' ); + assert.equal( new Modules.ISODate().parseTime('05:34:00', 'html5'), '05:34:00' ); + assert.equal( new Modules.ISODate().parseTime('05:34', 'html5'), '05:34' ); + assert.equal( new Modules.ISODate().parseTime('05', 'html5'), '05' ); + }); + + it('parseTimeZone', function(){ + var date = new Modules.ISODate(); + date.parseTime('14:00'); + assert.equal( date.parseTimeZone('-01:00', 'auto'), '14:00-01:00' ); + + date.clear(); + date.parseTime('14:00'); + assert.equal( date.parseTimeZone('-01', 'auto'), '14:00-01' ); + + date.clear(); + date.parseTime('14:00'); + assert.equal( date.parseTimeZone('+01:00', 'auto').toString('auto'), '14:00+01:00' ); + + date.clear(); + date.parseTime('15:00'); + assert.equal( date.parseTimeZone('Z', 'auto').toString('auto'), '15:00Z' ); + + date.clear(); + date.parseTime('16:00'); + assert.equal( date.parseTimeZone('z', 'auto'), '16:00z' ); + + }); + + + + it('toString', function(){ + var date = new Modules.ISODate(); + date.parseTime('05:34:00.1267'); + + assert.equal( date.toString('html5'), '05:34:00.1267' ); + }); + + + it('toTimeString', function(){ + var date = new Modules.ISODate(); + date.parseTime('05:34:00.1267'); + + assert.equal( date.toTimeString('html5'), '05:34:00.1267' ); + }); + + + it('hasFullDate', function(){ + var dateEmpty = new Modules.ISODate(), + date = new Modules.ISODate('2015-01-23T05:34:00'); + + assert.isFalse( dateEmpty.hasFullDate() ); + assert.isTrue( date.hasFullDate() ); + }); + + + it('hasDate', function(){ + var dateEmpty = new Modules.ISODate(), + date = new Modules.ISODate('2015-01-23'); + + assert.isFalse( dateEmpty.hasDate() ); + assert.isTrue( date.hasDate() ); + }); + + + it('hasTime', function(){ + var dateEmpty = new Modules.ISODate(), + date = new Modules.ISODate(); + + date.parseTime('12:34'); + + assert.isFalse( dateEmpty.hasTime() ); + assert.isTrue( date.hasTime() ); + }); + + + it('hasTimeZone', function(){ + var dateEmpty = new Modules.ISODate(), + date = new Modules.ISODate(); + + date.parseTime('12:34'), + date.parseTimeZone('-01:00'); + + assert.isFalse( dateEmpty.hasTimeZone() ); + assert.isTrue( date.hasTimeZone() ); + }); + + +}); diff --git a/toolkit/components/microformats/test/module-tests/text-test.js b/toolkit/components/microformats/test/module-tests/text-test.js new file mode 100644 index 000000000..f1f2e775c --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/text-test.js @@ -0,0 +1,56 @@ +/* +Unit test for text +*/ + +assert = chai.assert; + +// Tests the private Modules.text object +// Modules.text is unit tested as it has an interface access by other modules + + +describe('Modules.text', function() { + + + it('parse', function(){ + var html = '\n Glenn\n Jones \n \n', + node = document.createElement('div'); + + node.innerHTML = html; + assert.equal( Modules.text.parse( document, node, 'whitespacetrimmed' ), 'Glenn\n Jones' ); + assert.equal( Modules.text.parse( document, node, 'whitespace' ), '\n Glenn\n Jones \n \n' ); + assert.equal( Modules.text.parse( document, node, 'normalised' ), 'Glenn Jones' ); + + // exclude tags + node.innerHTML = 'text'; + assert.equal( Modules.text.parse( document, node, 'normalised' ), 'text' ); + + // block level + node.innerHTML = '

    test

    text'; + //assert.equal( Modules.text.parse( document, node, 'normalised' ), 'test text' ); + + // node with no text data + node = document.createComment('test comment'); + assert.equal( Modules.text.parse( document, node, 'normalised' ), '' ); + + }); + + + it('parseText', function(){ + var text = '\n Glenn\n Jones \n \n'; + + // create DOM context first + Modules.domUtils.getDOMContext( {} ); + + assert.equal( Modules.text.parseText( document, text, 'whitespacetrimmed' ), 'Glenn\n Jones' ); + assert.equal( Modules.text.parseText( document, text, 'whitespace' ), '\n Glenn\n Jones \n \n' ); + assert.equal( Modules.text.parseText( document, text, 'normalised' ), 'Glenn Jones' ); + }); + + + it('formatText', function(){ + assert.equal( Modules.text.formatText( document, null, 'whitespacetrimmed' ), '' ); + }); + + + +}); diff --git a/toolkit/components/microformats/test/module-tests/url-test.js b/toolkit/components/microformats/test/module-tests/url-test.js new file mode 100644 index 000000000..788e8fdb5 --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/url-test.js @@ -0,0 +1,25 @@ +/* +Unit test for url +*/ + +assert = chai.assert; + + +// Tests the private Modules.url object +// Modules.url is unit tested as it has an interface access by other modules + + +describe('Modules.url', function() { + + it('resolve', function(){ + assert.equal( Modules.url.resolve( 'docs/index.html', 'http://example.org' ), 'http://example.org/docs/index.html' ); + assert.equal( Modules.url.resolve( '../index.html', 'http://example.org/docs/' ), 'http://example.org/index.html' ); + assert.equal( Modules.url.resolve( '/', 'http://example.org/' ), 'http://example.org/' ); + assert.equal( Modules.url.resolve( 'http://glennjones.net/', 'http://example.org/' ), 'http://glennjones.net/' ); + + assert.equal( Modules.url.resolve( undefined, 'http://example.org/' ), '' ); + assert.equal( Modules.url.resolve( undefined, undefined ), '' ); + assert.equal( Modules.url.resolve( 'http://glennjones.net/', undefined ), 'http://glennjones.net/' ); + }); + +}); diff --git a/toolkit/components/microformats/test/module-tests/utilities-test.js b/toolkit/components/microformats/test/module-tests/utilities-test.js new file mode 100644 index 000000000..b37236a6b --- /dev/null +++ b/toolkit/components/microformats/test/module-tests/utilities-test.js @@ -0,0 +1,93 @@ +/* +Unit test for utilities +*/ + +assert = chai.assert; + +// Tests the private Modules.utils object +// Modules.utils is unit tested as it has an interface access by other modules + + +describe('Modules.utilities', function() { + + + it('isString', function(){ + assert.isTrue( Modules.utils.isString( 'abc' ) ); + assert.isFalse( Modules.utils.isString( 123 ) ); + assert.isFalse( Modules.utils.isString( 1.23 ) ); + assert.isFalse( Modules.utils.isString( {'abc': 'abc'} ) ); + assert.isFalse( Modules.utils.isString( ['abc'] ) ); + assert.isFalse( Modules.utils.isString( true ) ); + }); + + + it('isArray', function(){ + assert.isTrue( Modules.utils.isArray( ['abc'] ) ); + assert.isFalse( Modules.utils.isArray( 123 ) ); + assert.isFalse( Modules.utils.isArray( 1.23 ) ); + assert.isFalse( Modules.utils.isArray( 'abc' ) ); + assert.isFalse( Modules.utils.isArray( {'abc': 'abc'} ) ); + assert.isFalse( Modules.utils.isArray( true ) ); + }); + + + it('isNumber', function(){ + assert.isTrue( Modules.utils.isNumber( 123 ) ); + assert.isTrue( Modules.utils.isNumber( 1.23 ) ); + assert.isFalse( Modules.utils.isNumber( 'abc' ) ); + assert.isFalse( Modules.utils.isNumber( {'abc': 'abc'} ) ); + assert.isFalse( Modules.utils.isNumber( ['abc'] ) ); + assert.isFalse( Modules.utils.isNumber( true ) ); + }); + + + it('startWith', function(){ + assert.isTrue( Modules.utils.startWith( 'p-name', 'p-' ) ); + assert.isFalse( Modules.utils.startWith( 'p-name', 'name' ) ); + assert.isFalse( Modules.utils.startWith( 'p-name', 'u-' ) ); + }); + + + it('trim', function(){ + assert.equal( Modules.utils.trim( ' Glenn Jones ' ), 'Glenn Jones' ); + assert.equal( Modules.utils.trim( 'Glenn Jones' ), 'Glenn Jones' ); + assert.equal( Modules.utils.trim( undefined ), '' ); + }); + + + it('replaceCharAt', function(){ + assert.equal( Modules.utils.replaceCharAt( 'Glenn Jones', 5, '-' ), 'Glenn-Jones' ); + assert.equal( Modules.utils.replaceCharAt( 'Glenn Jones', 50, '-' ), 'Glenn Jones' ); + }); + + + it('isOnlyWhiteSpace', function(){ + assert.isTrue( Modules.utils.isOnlyWhiteSpace( ' ') ); + assert.isTrue( Modules.utils.isOnlyWhiteSpace( ' \n\r') ); + assert.isFalse( Modules.utils.isOnlyWhiteSpace( ' text\n\r') ); + }); + + + it('collapseWhiteSpace', function(){ + assert.equal( Modules.utils.collapseWhiteSpace( ' '), ' ' ); + assert.equal( Modules.utils.collapseWhiteSpace( ' \n\r'), ' ' ); + assert.equal( Modules.utils.collapseWhiteSpace( ' text\n\r'), ' text ' ); + }); + + + it('hasProperties', function(){ + assert.isTrue( Modules.utils.hasProperties( {name: 'glennjones'} ) ); + assert.isFalse( Modules.utils.hasProperties( {} ) ); + }); + + + it('sortObjects', function(){ + var arr = [{'name': 'one'},{'name': 'two'},{'name': 'three'},{'name': 'three'}]; + + assert.deepEqual( arr.sort( Modules.utils.sortObjects( 'name', true ) ), [{"name":"two"},{"name":"three"},{'name': 'three'},{"name":"one"}] ); + assert.deepEqual( arr.sort( Modules.utils.sortObjects( 'name', false ) ), [{"name":"one"},{"name":"three"},{'name': 'three'},{"name":"two"}] ); + }); + + + +}); -- cgit v1.2.3