From 20711f003e97a4a57d1e2838ba78a994c5faf6c0 Mon Sep 17 00:00:00 2001 From: James Lal Date: Fri, 6 Jul 2012 08:13:15 -0700 Subject: webcals -> caldav rename (yes, back again) --- test/caldav/request/propfind_test.js | 123 +++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 test/caldav/request/propfind_test.js (limited to 'test/caldav/request/propfind_test.js') diff --git a/test/caldav/request/propfind_test.js b/test/caldav/request/propfind_test.js new file mode 100644 index 0000000..069aaf3 --- /dev/null +++ b/test/caldav/request/propfind_test.js @@ -0,0 +1,123 @@ +requireRequest(); +testSupport.lib('request/propfind'); + +suite('caldav/request/propfind', function() { + var Abstract, + Propfind, + FakeXhr, + Xhr, + Template, + oldXhrClass, + SaxResponse; + + var url = 'http://google.com', + subject; + + suiteSetup(function() { + Abstract = Caldav.require('request/abstract'); + Propfind = Caldav.require('request/propfind'); + SaxResponse = Caldav.require('sax/dav_response'); + FakeXhr = Caldav.require('support/fake_xhr'); + Template = Caldav.require('template'); + Xhr = Caldav.require('xhr'); + + oldXhrClass = Xhr.prototype.xhrClass; + Xhr.prototype.xhrClass = FakeXhr; + }); + + suiteTeardown(function() { + Xhr.prototype.xhrClass = oldXhrClass; + }); + + setup(function() { + subject = new Propfind(url); + FakeXhr.instances.length = 0; + }); + + test('initializer', function() { + assert.instanceOf(subject, Abstract); + assert.instanceOf(subject.template, Template); + assert.deepEqual(subject._props, []); + assert.equal( + subject.sax.handles['DAV:/response'], + SaxResponse + ); + + assert.equal(subject.xhr.headers['Depth'], 0); + assert.equal(subject.xhr.method, 'PROPFIND'); + }); + + test('#prop', function() { + var expected = subject.template.tag('test'); + + subject.prop('test'); + + assert.deepEqual(subject._props, [expected]); + }); + + test('#_createPayload', function() { + subject.prop('foo'); + subject.prop('bar'); + + var tags = [ + '', + '' + ].join(''); + + var expected = [ + subject.template.doctype, + '', + '', tags, '', + '' + ].join(''); + + var result = subject._createPayload(); + + assert.equal(subject._createPayload(), expected); + }); + + test('#_processResult', function(done) { + var inner = {}, + req = {}; + + subject.sax.root = { + multistatus: inner + }; + + subject._processResult(req, function(err, obj, xhr) { + assert.equal(xhr, req); + assert.equal(obj, inner); + assert.equal(err, null); + done(); + }); + }); + + suite('integration', function() { + var xml, + data, + result, + xhr, + calledWith; + + testSupport.defineSample('xml/propget.xml', function(data) { + xml = data; + }); + + setup(function(done) { + subject.prop('foo'); + + subject.send(function(err, tree) { + data = tree; + done(); + }); + + xhr = FakeXhr.instances.pop(); + xhr.respond(xml, 207); + }); + + test('simple tree', function() { + assert.ok(data['/calendar/user/']); + }); + }); + +}); -- cgit