1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
requireRequest();
suite('webcals/request/propfind', function() {
var Abstract,
Propfind,
FakeXhr,
Xhr,
Template,
oldXhrClass,
SaxResponse;
var url = 'http://google.com',
subject;
suiteSetup(function() {
Abstract = Webcals.require('request/abstract');
Propfind = Webcals.require('request/propfind');
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 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 = [
'<N0:foo />',
'<N0:bar />'
].join('');
var expected = [
subject.template.doctype,
'<N0:propfind xmlns:N0="DAV:">',
'<N0:prop>', tags, '</N0:prop>',
'</N0:propfind>'
].join('');
var result = subject._createPayload();
console.log(result);
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;
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/']);
});
});
});
|