diff options
Diffstat (limited to 'test/webcals/request/calendar_query_test.js')
-rw-r--r-- | test/webcals/request/calendar_query_test.js | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/test/webcals/request/calendar_query_test.js b/test/webcals/request/calendar_query_test.js new file mode 100644 index 0000000..803b09a --- /dev/null +++ b/test/webcals/request/calendar_query_test.js @@ -0,0 +1,104 @@ +requireRequest(); +requireLib('request/propfind'); +requireLib('request/calendar_query'); + +suite('webcals/request/propfind', function() { + var Abstract, + Propfind, + FakeXhr, + CalendarQuery, + Xhr, + Template, + oldXhrClass, + SaxResponse; + + var url = 'http://google.com', + subject; + + suiteSetup(function() { + Propfind = Webcals.require('request/propfind'); + CalendarQuery = Webcals.require('request/calendar_query'); + SaxResponse = Webcals.require('sax/dav_response'); + FakeXhr = Webcals.require('support/fake_xhr'); + Template = Webcals.require('template'); + Xhr = Webcals.require('xhr'); + + oldXhrClass = Xhr.prototype.xhrClass; + Xhr.prototype.xhrClass = FakeXhr; + }); + + suiteTeardown(function() { + Xhr.prototype.xhrClass = oldXhrClass; + }); + + setup(function() { + subject = new CalendarQuery(url); + FakeXhr.instances.length = 0; + }); + + test('initializer', function() { + assert.instanceOf(subject, Propfind); + assert.deepEqual(subject._props, []); + assert.equal(subject.xhr.headers['Depth'], 1); + assert.equal(subject.xhr.method, 'REPORT'); + }); + + test('#prop', function() { + var expected = subject.template.tag('test'); + + subject.prop('test'); + + assert.deepEqual(subject._props, [expected]); + }); + + test('#_createPayload', function() { + return; + subject.prop('foo'); + subject.prop('bar'); + + var tags = [ + '<N0:foo />', + '<N0:bar />' + ].join(''); + + var expected = [ + subject.template.doctype, + '<N0:propfind xmlns:N0="DAV:">', + '<N0:prop>', tags, '</N0:prop>', + '</N0:propfind>' + ].join(''); + + assert.equal(subject._createPayload(), expected); + }); + + suite('integration', function() { + return; + var xml, + data, + result, + xhr, + calledWith; + + 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/']); + }); + }); + +}); + |