aboutsummaryrefslogtreecommitdiffstats
path: root/test/caldav/sax
diff options
context:
space:
mode:
Diffstat (limited to 'test/caldav/sax')
-rw-r--r--test/caldav/sax/base_test.js95
-rw-r--r--test/caldav/sax/dav_response_test.js81
2 files changed, 176 insertions, 0 deletions
diff --git a/test/caldav/sax/base_test.js b/test/caldav/sax/base_test.js
new file mode 100644
index 0000000..aea5707
--- /dev/null
+++ b/test/caldav/sax/base_test.js
@@ -0,0 +1,95 @@
+testSupport.lib('responder');
+testSupport.lib('sax');
+testSupport.lib('sax/base');
+
+suite('caldav/sax/base', function() {
+
+ var data,
+ subject,
+ parser,
+ Parse,
+ Base,
+ handler;
+
+
+ suiteSetup(function() {
+ Parse = Caldav.require('sax');
+ Base = Caldav.require('sax/base');
+ });
+
+ setup(function() {
+ //we omit the option to pass base parser
+ //because we are the base parser
+ subject = new Parse();
+ });
+
+ test('#create', function() {
+ function childText() {}
+
+ var Child = Base.create({
+ ontext: childText
+ });
+
+ assert.equal(Child.ontext, childText);
+ assert.equal(Child.tagField, Base.tagField);
+
+ assert.isTrue(
+ Base.isPrototypeOf(Child),
+ 'should have base in proto chain'
+ );
+
+ assert.equal(Child._super, Base);
+
+ var ChildChild = Child.create();
+
+ assert.isTrue(
+ Child.isPrototypeOf(ChildChild),
+ 'should have child in childchild protochain'
+ );
+
+ assert.isTrue(
+ Base.isPrototypeOf(ChildChild),
+ 'should have base in childchild protochain'
+ );
+
+ assert.equal(ChildChild._super, Child);
+
+ });
+
+ suite('base parser', function() {
+ var xml, data;
+
+ testSupport.defineSample('xml/simple.xml', function(data) {
+ xml = data;
+ });
+
+ //base baser does not
+ //care about attrs at this point
+ var expected = {
+ simple: {
+ a: [
+ { value: 'Foo' },
+ { value: 'Foo\n bar' }
+ ],
+ div: {
+ span: {
+ value: 'span'
+ }
+ }
+ }
+ };
+
+ test('simple tree', function(done) {
+ subject.once('complete', function(data) {
+ assert.deepEqual(
+ data, expected,
+ "expected \n '" + JSON.stringify(data) + "'\n to equal \n '" +
+ JSON.stringify(expected) + '\n"'
+ );
+ done();
+ });
+ subject.write(xml).close();
+ });
+ });
+
+});
diff --git a/test/caldav/sax/dav_response_test.js b/test/caldav/sax/dav_response_test.js
new file mode 100644
index 0000000..47adca0
--- /dev/null
+++ b/test/caldav/sax/dav_response_test.js
@@ -0,0 +1,81 @@
+testSupport.lib('sax');
+testSupport.lib('sax/base');
+testSupport.lib('sax/dav_response');
+testSupport.lib('ical');
+
+suite('caldav/sax/dav_response', function() {
+
+ var data,
+ subject,
+ parser,
+ Parse,
+ Response,
+ Base,
+ handler;
+
+
+ suiteSetup(function() {
+ Parse = Caldav.require('sax');
+ Base = Caldav.require('sax/base');
+ Response = Caldav.require('sax/dav_response');
+ });
+
+ setup(function() {
+ //we omit the option to pass base parser
+ //because we are the base parser
+ subject = new Parse();
+ subject.registerHandler('DAV:/response', Response);
+ });
+
+ suite('parsing', function() {
+ var xml;
+
+ testSupport.defineSample('xml/propget.xml', function(data) {
+ xml = data;
+ });
+
+ expected = {
+ '/calendar/user/': {
+
+ 'principal-URL': {
+ status: '200',
+ value: '/calendar/pinc/'
+ },
+
+ resourcetype: {
+ status: '200',
+ value: [
+ 'principal',
+ 'collection'
+ ]
+ },
+
+ 'current-user-principal': {
+ status: '404',
+ value: {}
+ }
+ },
+
+ '/calendar/other': {
+ missing: {
+ status: '200',
+ value: {}
+ }
+ }
+
+ };
+
+ test('output', function(done) {
+ subject.once('complete', function(data) {
+ assert.deepEqual(
+ data.multistatus, expected,
+ "expected \n '" + JSON.stringify(data.multistatus) +
+ "'\n to equal \n '" + JSON.stringify(expected) + '\n"'
+ );
+ done();
+ });
+ subject.write(xml).close();
+ });
+ });
+
+});