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 --- .../test/interface-tests/count-test.js | 107 ++++ .../test/interface-tests/experimental-test.js | 37 ++ .../microformats/test/interface-tests/get-test.js | 605 +++++++++++++++++++++ .../test/interface-tests/getParent-test.js | 220 ++++++++ .../test/interface-tests/hasMicroformats-test.js | 185 +++++++ .../microformats/test/interface-tests/index.html | 69 +++ .../test/interface-tests/isMicroformat-test.js | 146 +++++ 7 files changed, 1369 insertions(+) create mode 100644 toolkit/components/microformats/test/interface-tests/count-test.js create mode 100644 toolkit/components/microformats/test/interface-tests/experimental-test.js create mode 100644 toolkit/components/microformats/test/interface-tests/get-test.js create mode 100644 toolkit/components/microformats/test/interface-tests/getParent-test.js create mode 100644 toolkit/components/microformats/test/interface-tests/hasMicroformats-test.js create mode 100644 toolkit/components/microformats/test/interface-tests/index.html create mode 100644 toolkit/components/microformats/test/interface-tests/isMicroformat-test.js (limited to 'toolkit/components/microformats/test/interface-tests') diff --git a/toolkit/components/microformats/test/interface-tests/count-test.js b/toolkit/components/microformats/test/interface-tests/count-test.js new file mode 100644 index 000000000..baac56c2b --- /dev/null +++ b/toolkit/components/microformats/test/interface-tests/count-test.js @@ -0,0 +1,107 @@ +/* +Unit test for count +*/ + +assert = chai.assert; + + +describe('Microformat.count', function() { + + it('count', function(){ + + var doc, + node, + result; + + var html = 'GlennJaneEvent2015-07-01'; + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = html; + doc.body.appendChild(node); + + options ={ + 'node': node, + }; + + result = Microformats.count(options); + assert.deepEqual( result, {'h-event': 1,'h-card': 2} ); + + }); + + + it('count rels', function(){ + + var doc, + node, + result; + + var html = 'GlennJaneEvent2015-07-01'; + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = html; + doc.body.appendChild(node); + + options ={ + 'node': node, + }; + + result = Microformats.count(options); + assert.deepEqual( result, {'h-event': 1,'h-card': 2, 'rels': 1} ); + + }); + + + it('count - no results', function(){ + + var doc, + node, + result; + + var html = 'Jane'; + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = html; + doc.body.appendChild(node); + + options ={ + 'node': node, + }; + + result = Microformats.count(options); + assert.deepEqual( result, {} ); + + }); + + + + it('count - no options', function(){ + + var result; + + result = Microformats.count({}); + assert.deepEqual( result, {} ); + + }); + + + it('count - options.html', function(){ + + var options = {}, + result; + + options.html = 'GlennJaneEvent2015-07-01'; + + result = Microformats.count(options); + assert.deepEqual( result, {'h-event': 1,'h-card': 2} ); + + }); + + + + }); diff --git a/toolkit/components/microformats/test/interface-tests/experimental-test.js b/toolkit/components/microformats/test/interface-tests/experimental-test.js new file mode 100644 index 000000000..4d32b83c0 --- /dev/null +++ b/toolkit/components/microformats/test/interface-tests/experimental-test.js @@ -0,0 +1,37 @@ +/* +Unit test for get +*/ + +assert = chai.assert; + + +describe('experimental', function() { + + it('h-geo - geo data writen as lat;lon', function(){ + + var expected = { + 'items': [{ + 'type': ['h-geo'], + 'properties': { + 'name': ['30.267991;-97.739568'], + 'latitude': [30.267991], + 'longitude': [-97.739568] + } + }], + 'rels': {}, + 'rel-urls': {} + }, + options = { + 'html': '
30.267991;-97.739568
', + 'baseUrl': 'http://example.com', + 'dateFormat': 'html5', + 'parseLatLonGeo': true + }; + + var result = Microformats.get(options); + assert.deepEqual( result, expected ); + + }); + + +}); diff --git a/toolkit/components/microformats/test/interface-tests/get-test.js b/toolkit/components/microformats/test/interface-tests/get-test.js new file mode 100644 index 000000000..098ff4e3d --- /dev/null +++ b/toolkit/components/microformats/test/interface-tests/get-test.js @@ -0,0 +1,605 @@ +/* +Unit test for get +*/ + +assert = chai.assert; + + +describe('Microformat.get', function() { + + + var expected = { + 'items': [{ + 'type': ['h-card'], + 'properties': { + 'name': ['Glenn Jones'], + 'url': ['http://glennjones.net'] + } + }], + 'rels': { + 'bookmark': ['http://glennjones.net'], + 'alternate': ['http://example.com/fr'], + 'home': ['http://example.com/fr'] + }, + 'rel-urls': { + 'http://glennjones.net': { + 'text': 'Glenn Jones', + 'rels': ['bookmark'] + }, + 'http://example.com/fr': { + 'media': 'handheld', + 'hreflang': 'fr', + 'text': 'French mobile homepage', + 'rels': ['alternate', 'home'] + } + } + }, + html = '
Glenn Jones
French mobile homepage'; + + + + + + it('get - no options.node parse this document', function(){ + var result; + + result = Microformats.get({}); + assert.deepEqual( result.items, [] ); + }); + + + it('get - standard', function(){ + + var doc, + node, + options, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = html; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'baseUrl': 'http://example.com', + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, expected ); + + }); + + + it('get - doc pass to node', function(){ + + var doc, + node, + options, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = html; + doc.body.appendChild(node); + + options ={ + 'node': doc, + 'baseUrl': 'http://example.com', + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, expected ); + + }); + + + it('get - pass base tag', function(){ + + var doc, + node, + options, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = html + ''; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, expected ); + + }); + + + it('get - pass no document', function(){ + + var doc, + node, + options, + parser, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = html + ''; + doc.body.appendChild(node); + + options ={ + 'node': doc, + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, expected ); + + }); + + + it('get - textFormat: normalised', function(){ + + var doc, + node, + options, + result; + + var altHTML = '\n'; + altHTML += ' Glenn\n'; + altHTML += ' Jones\n'; + altHTML += '\n'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'textFormat': 'normalised', + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.equal( result.items[0].properties.name[0], 'Glenn Jones' ); + + }); + + + it('get - textFormat: whitespace', function(){ + + var doc, + node, + options, + parser, + result; + + var altHTML = '\n'; + altHTML += ' Glenn\n'; + altHTML += ' Jones\n'; + altHTML += '\n'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'textFormat': 'whitespace', + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.equal( result.items[0].properties.name[0], '\n Glenn\n Jones\n' ); + + }); + + + + it('get - textFormat: whitespacetrimmed', function(){ + + var doc, + node, + options, + result; + + var altHTML = '\n'; + altHTML += ' Glenn\n'; + altHTML += ' Jones\n'; + altHTML += '\n'; + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'textFormat': 'whitespacetrimmed', + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.equal( result.items[0].properties.name[0], 'Glenn\n Jones' ); + + }); + + + it('get - dateFormat: auto', function(){ + + var doc, + node, + options, + result; + + var altHTML = '
Pub2015-07-01t17:30z
'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'dateFormat': 'auto' + }; + + result = Microformats.get(options); + assert.equal( result.items[0].properties.start[0], '2015-07-01t17:30z' ); + + }); + + + it('get - dateFormat: w3c', function(){ + + var doc, + node, + options, + result; + + var altHTML = '
Pub2015-07-01t17:30z
'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'dateFormat': 'w3c' + }; + + result = Microformats.get(options); + assert.equal( result.items[0].properties.start[0], '2015-07-01T17:30Z' ); + + }); + + + it('get - dateFormat: html5', function(){ + + var doc, + node, + options, + result; + + var altHTML = '
Pub2015-07-01t17:30z
'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.equal( result.items[0].properties.start[0], '2015-07-01 17:30Z' ); + + }); + + + + it('get - dateFormat: rfc3339', function(){ + + var doc, + node, + options, + + result; + + var altHTML = '
Pub2015-07-01t17:30z
'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'dateFormat': 'rfc3339' + }; + + result = Microformats.get(options); + assert.equal( result.items[0].properties.start[0], '20150701T1730Z' ); + + }); + + + + it('get - filters h-card', function(){ + + var doc, + node, + options, + parser, + result; + + var altHTML = '
Pub2015-07-01t17:30z
Glenn Jones'; + var altExpected = { + 'items': [{ + 'type': ['h-card'], + 'properties': { + 'name': ['Glenn Jones'], + 'url': ['http://glennjones.net'] + } + }], + 'rels': {}, + 'rel-urls': {} + } + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + // filter as an array + options ={ + 'node': node, + 'filters': ['h-card'], + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, altExpected ); + + // filter as an string + options ={ + 'node': node, + 'filters': 'h-card', + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, altExpected ); + }); + + + it('get - filters h-event', function(){ + + var doc, + node, + options, + result; + + var altHTML = '
Pub2015-07-01t17:30z
Glenn Jones'; + var altExpected = { + 'items': [{ + 'type': ['h-event'], + 'properties': { + 'name': ['Pub'], + 'start': ['2015-07-01 17:30Z'] + } + }], + 'rels': {}, + 'rel-urls': {} + } + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'filters': ['h-event'], + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, altExpected ); + + }); + + + it('get - filters h-card and h-event', function(){ + + var doc, + node, + options, + result; + + var altHTML = '
Pub2015-07-01t17:30z
Glenn Jones'; + var altExpected = { + 'items': [{ + 'type': ['h-event'], + 'properties': { + 'name': ['Pub'], + 'start': ['2015-07-01 17:30Z'] + } + }, + { + 'type': ['h-card'], + 'properties': { + 'name': ['Glenn Jones'], + 'url': ['http://glennjones.net'] + } + }], + 'rels': {}, + 'rel-urls': {} + } + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'filter': ['h-event'], + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, altExpected ); + + }); + + + it('get - filters h-card no result', function(){ + + var doc, + node, + options, + result; + + var altHTML = '
Pub2015-07-01t17:30z
'; + var altExpected = { + 'items': [], + 'rels': {}, + 'rel-urls': {} + } + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'filters': ['h-card'], + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, altExpected ); + + }); + + + it('get - filters h-card match v1 format', function(){ + + var doc, + node, + options, + parser, + result; + + var altHTML = 'Glenn Jones'; + var altExpected = { + 'items': [{ + 'type': ['h-card'], + 'properties': { + 'name': ['Glenn Jones'] + } + }], + 'rels': {}, + 'rel-urls': {} + } + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'filter': ['h-card'], + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, altExpected ); + + }); + + + it('get - add new v1 format through options', function(){ + + var doc, + node, + options, + result; + + var altHTML = '
£36.78
'; + var altExpected = { + 'items': [{ + 'type': ['h-payment'], + 'properties': { + 'amount': ['36.78'] + } + }], + 'rels': {}, + 'rel-urls': {} + }; + var v1Definition = { + root: 'hpayment', + name: 'h-payment', + properties: { + 'amount': {} + } + }; + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + + options ={ + 'node': node, + 'maps': v1Definition, + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, altExpected ); + + }); + + + it('get - options.html', function(){ + + var options, + result; + + options ={ + 'html': html, + 'baseUrl': 'http://example.com', + 'dateFormat': 'html5' + }; + + result = Microformats.get(options); + assert.deepEqual( result, expected ); + + }); + + + + + +}); diff --git a/toolkit/components/microformats/test/interface-tests/getParent-test.js b/toolkit/components/microformats/test/interface-tests/getParent-test.js new file mode 100644 index 000000000..56ccbb2ba --- /dev/null +++ b/toolkit/components/microformats/test/interface-tests/getParent-test.js @@ -0,0 +1,220 @@ +/* +Unit test for getParent +*/ + +assert = chai.assert; + + +describe('Microformat.getParent', function() { + + var HTML = '
Pub2015-07-01t17:30z
'; + var emptyExpected = { + "items": [], + "rels": {}, + "rel-urls": {} + }; + var expected = { + "items": [ + { + "type": [ + "h-event" + ], + "properties": { + "name": [ + "Pub" + ], + "start": [ + "2015-07-01 17:30Z" + ] + } + } + ], + "rels": {}, + "rel-urls": {} + }; + var options = {'dateFormat': 'html5'}; + + + + + it('getParent with parent', function(){ + + var doc, + node, + span, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = HTML; + doc.body.appendChild(node); + span = doc.querySelector('.dt-start'); + + result = Microformats.getParent(span,options); + assert.deepEqual( result, expected ); + + }); + + + + it('getParent without parent', function(){ + + var doc, + node, + parser, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = HTML; + doc.body.appendChild(node); + + result = Microformats.getParent(node,options); + assert.deepEqual( result, emptyExpected ); + + }); + + + it('getParent found with option.filters', function(){ + + var doc, + node, + span, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = HTML; + doc.body.appendChild(node); + span = doc.querySelector('.dt-start'); + + result = Microformats.getParent( span, {'filters': ['h-event'], 'dateFormat': 'html5'} ); + assert.deepEqual( result, expected ); + + }); + + + it('getParent not found with option.filters', function(){ + + var doc, + node, + span, + result; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = HTML; + doc.body.appendChild(node); + span = doc.querySelector('.dt-start'); + + result = Microformats.getParent( span, {'filters': ['h-card'], 'dateFormat': 'html5'} ); + assert.deepEqual( result, emptyExpected ); + + }); + + + it('getParent use option.filters to up through h-*', function(){ + + var doc, + node, + span, + result; + + var altHTML = '

test

this
Glenn Jones2015-07-01t17:30z
'; + var altExpected = { + "items": [ + { + "type": [ + "h-entry" + ], + "properties": { + "name": [ + "test" + ], + "content": [ + { + "value": "this", + "html": "this" + } + ], + "author": [ + { + "value": "Glenn Jones", + "type": [ + "h-card" + ], + "properties": { + "name": [ + "Glenn Jones" + ], + "url": [ + "http://glennjones.net" + ] + } + } + ], + "publish": [ + "2015-07-01 17:30Z" + ] + } + } + ], + "rels": {}, + "rel-urls": {} + }; + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + span = doc.querySelector('.h-card .p-name'); + + result = Microformats.getParent( span, {'filters': ['h-entry'], 'dateFormat': 'html5'} ); + assert.deepEqual( result, altExpected ); + + }); + + + it('getParent stop at first h-* parent', function(){ + + var doc, + node, + span, + result; + + var altHTML = '

test

this
Glenn Jones2015-07-01t17:30z
'; + var altExpected = { + "items": [ + { + "type": [ + "h-card" + ], + "properties": { + "name": [ + "Glenn Jones" + ], + "url": [ + "http://glennjones.net" + ] + } + } + ], + "rels": {}, + "rel-urls": {} + }; + + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + node.innerHTML = altHTML; + doc.body.appendChild(node); + span = doc.querySelector('.h-card .p-name'); + + result = Microformats.getParent( span, options ); + assert.deepEqual( result, altExpected ); + + }); + + +}); diff --git a/toolkit/components/microformats/test/interface-tests/hasMicroformats-test.js b/toolkit/components/microformats/test/interface-tests/hasMicroformats-test.js new file mode 100644 index 000000000..98c79a855 --- /dev/null +++ b/toolkit/components/microformats/test/interface-tests/hasMicroformats-test.js @@ -0,0 +1,185 @@ +/* +Unit test for hasMicroformat +*/ + +assert = chai.assert; + + +describe('Microformat.hasMicroformats', function() { + + it('true - v2 on node', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.hasMicroformats( node ) ); + + }); + + + it('true - v1 on node', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.hasMicroformats( node ) ); + + }); + + + it('true - v2 filter on node', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.hasMicroformats( node, {'filters': ['h-card']} ) ); + + }); + + + it('true - v1 filter on node', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.hasMicroformats( node, {'filters': ['h-card']} ) ); + + }); + + + it('false - v2 filter on node', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isFalse( Microformats.hasMicroformats( node, {'filters': ['h-entry']} ) ); + + }); + + + + it('false - property', function(){ + + var doc, + node, + parser; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'span' ); + + assert.isFalse( Microformats.hasMicroformats( node ) ); + + }); + + + it('false - no class', function(){ + + var doc, + node, + parser; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'span' ); + + assert.isFalse( Microformats.hasMicroformats( node ) ); + + }); + + + it('false - no node', function(){ + assert.isFalse( Microformats.hasMicroformats( ) ); + }); + + + it('false - undefined node', function(){ + assert.isFalse( Microformats.hasMicroformats( undefined ) ); + }); + + + it('true - child', function(){ + + var doc, + node; + + var html = '
Glenn
'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + + assert.isTrue( Microformats.hasMicroformats( node ) ); + + }); + + + + it('true - document', function(){ + + var doc, + node; + + var html = '
Glenn
'; + + var dom = new DOMParser(); + doc = dom.parseFromString( html, 'text/html' ); + + assert.isTrue( Microformats.hasMicroformats( doc ) ); + + }); + + + + + + }); diff --git a/toolkit/components/microformats/test/interface-tests/index.html b/toolkit/components/microformats/test/interface-tests/index.html new file mode 100644 index 000000000..61759790e --- /dev/null +++ b/toolkit/components/microformats/test/interface-tests/index.html @@ -0,0 +1,69 @@ +Mocha + + + + + + + + + + + + + + + + + + + + + + + + + +

Microformats-shiv: interface tests

+
+ + + diff --git a/toolkit/components/microformats/test/interface-tests/isMicroformat-test.js b/toolkit/components/microformats/test/interface-tests/isMicroformat-test.js new file mode 100644 index 000000000..7081b2880 --- /dev/null +++ b/toolkit/components/microformats/test/interface-tests/isMicroformat-test.js @@ -0,0 +1,146 @@ +/* +Unit test for isMicroformat +*/ + +assert = chai.assert; + + +describe('Microformat.isMicroformat', function() { + + it('true - v2', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.isMicroformat( node ) ); + + }); + + + it('true - v1', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.isMicroformat( node ) ); + + }); + + + it('true - v2 filter', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.isMicroformat( node, {'filters': ['h-card']} ) ); + + }); + + + it('true - v1 filter', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isTrue( Microformats.isMicroformat( node, {'filters': ['h-card']} ) ); + + }); + + + it('false - v2 filter', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'a' ); + + assert.isFalse( Microformats.isMicroformat( node, {'filters': ['h-entry']} ) ); + + }); + + + + it('false - property', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'span' ); + + assert.isFalse( Microformats.isMicroformat( node ) ); + + }); + + + it('false - no class', function(){ + + var doc, + node; + + var html = 'Glenn'; + + doc = document.implementation.createHTMLDocument('New Document'); + node = document.createElement('div'); + doc.body.appendChild( node ); + node.innerHTML = html; + node = doc.querySelector( 'span' ); + + assert.isFalse( Microformats.isMicroformat( node ) ); + + }); + + + it('false - no node', function(){ + assert.isFalse( Microformats.isMicroformat( ) ); + }); + + + it('false - undefined node', function(){ + assert.isFalse( Microformats.isMicroformat( undefined ) ); + }); + + }); -- cgit v1.2.3