diff options
author | James Lal <james@lightsofapollo.com> | 2012-06-26 10:45:17 +0200 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2012-06-26 10:45:17 +0200 |
commit | 8d3e9701a3c4640255788d585afc609a9efa177d (patch) | |
tree | ef82ba9e1f8179397299eec5a0524c192cb32062 /test | |
parent | 646e0b6991c9e85de9b8eee20e601079fb128429 (diff) | |
download | jsCalDAV-8d3e9701a3c4640255788d585afc609a9efa177d.tar.gz |
xml builder
Diffstat (limited to 'test')
-rw-r--r-- | test/webcals/template_test.js | 126 | ||||
-rw-r--r-- | test/webcals/templates/propfind_test.js | 11 |
2 files changed, 137 insertions, 0 deletions
diff --git a/test/webcals/template_test.js b/test/webcals/template_test.js new file mode 100644 index 0000000..c0836d4 --- /dev/null +++ b/test/webcals/template_test.js @@ -0,0 +1,126 @@ +requireLib('template'); + +suite('templates', function() { + + var Template, + subject; + + suiteSetup(function() { + Template = Webcals.require('template'); + }); + + setup(function() { + subject = new Template('propget', { prop: 'val' }); + }); + + test('initializer', function() { + assert.equal(subject.rootTag, 'propget'); + assert.deepEqual(subject.activeNamespaces, {}); + assert.deepEqual(subject.rootAttrs, { + prop: 'val' + }); + }); + + suite('#_registerTag', function() { + var tag = 'foo'; + var prefix = 'dav'; + var firstOut; + + setup(function() { + firstOut = subject._registerTag(prefix, tag); + }); + + test('same tag', function() { + assert.deepEqual( + subject.activeNamespaces['DAV:'], + 'N0', + 'should register namespace' + ); + + assert.equal( + subject.rootAttrs['xmlns:N0'], + 'DAV:', + 'should add xmlns to root attrs' + ); + + assert.equal( + firstOut, + subject._registerTag(prefix, tag), + 'tag should render the same each time' + ); + }); + + test('second tag', function() { + var result = subject._registerTag('ical', 'baz'); + + assert.equal( + result, + 'N1:baz' + ); + }); + }); + + suite('#tag', function() { + + test('when given a non-existant namespace', function() { + var out = subject.tag(['foo', 'bar'], 'content'); + + assert.deepEqual( + subject.activeNamespaces['foo'], + 'N0' + ); + + assert.equal(out, '<N0:bar>content</N0:bar>'); + }); + + test('with attrs', function() { + var out = subject.tag('bar', { + value: 'val' + }, 'foo'); + + assert.deepEqual( + subject.activeNamespaces['DAV:'], + 'N0' + ); + + assert.equal( + out, + '<N0:bar value="val">foo</N0:bar>' + ); + }); + + test('given an array', function() { + var out = subject.tag( + ['bar', 'baz'], + 'foo' + ); + + assert.equal( + out, + '<N0:baz>foo</N0:baz>' + ); + }); + + test('given a string', function() { + var out = subject.tag('baz', 'foo'); + assert.equal( + out, + '<N0:baz>foo</N0:baz>' + ); + }); + }); + + test('#render', function() { + var tag = subject.tag('href', 'value'); + var out = subject.render(tag); + var output = ''; + + output += subject.doctype; + output += '<N0:propget prop="val" xmlns:N0="DAV:">'; + output += tag; + output += '</N0:propget>'; + + assert.equal(subject.render(tag), output); + }); + +}); diff --git a/test/webcals/templates/propfind_test.js b/test/webcals/templates/propfind_test.js new file mode 100644 index 0000000..6d2399e --- /dev/null +++ b/test/webcals/templates/propfind_test.js @@ -0,0 +1,11 @@ +requireLib('templates/propfind'); + +suite('templates/propfind', function() { + + var Propfind; + + suiteSetup(function() { + Propfind = Webcals.require('templates/propfind'); + }); + +}); |