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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
testSupport.lib('template');
testSupport.lib('query_builder');
suite('caldav/query_builder', function() {
// classes
var Builder;
var Template;
// instances
var subject;
var template;
suiteSetup(function() {
Builder = Caldav.require('query_builder');
Template = Caldav.require('template');
});
setup(function() {
template = new Template('container');
});
suite('Node', function() {
var builder;
setup(function() {
builder = new Builder({ template: template });
});
test('export', function() {
assert.ok(Builder.Node);
});
test('#appendString', function() {
var subject = new Builder.Node(builder, 'foo');
subject.appendString('<a></a>');
var out = subject.toString();
assert.equal(
out,
'<N0:comp name="foo"><a></a></N0:comp>'
);
});
});
test('no template given', function() {
assert.throws(function() {
new Builder();
}, TypeError);
});
test('empty document', function() {
var subject = new Builder({ template: template });
var out = subject.toString();
assert.equal(out, '<N0:calendar-data />');
});
test('#setRecurrenceSetLimit', function() {
var subject = new Builder({ template: template });
subject.setRecurrenceSetLimit({
start: 'a',
end: 'b'
});
var expected = [
'<N0:calendar-data>',
'<N0:limit-recurrence-set start="a" end="b" />',
'</N0:calendar-data>'
].join('');
var out = subject.toString();
assert.equal(out, expected);
});
// based on (calendar-data):
// http://pretty-rfc.herokuapp.com/RFC4791#example-partial-retrieval-of-events-by-time-range
suite('spec test - calendar data', function() {
var expected = [
'<N0:calendar-data>',
'<N0:comp name="VCALENDAR">',
'<N0:prop name="VERSION" />',
'<N0:comp name="VTIMEZONE" />',
'<N0:comp name="VEVENT">',
'<N0:prop name="SUMMARY" />',
'<N0:prop name="UID" />',
'<N0:prop name="DTSTART" />',
'<N0:prop name="DTEND" />',
'<N0:prop name="DURATION" />',
'<N0:prop name="RRULE" />',
'<N0:prop name="RDATE" />',
'<N0:prop name="EXRULE" />',
'<N0:prop name="EXDATE" />',
'<N0:prop name="RECURRENCE-ID" />',
'</N0:comp>',
'</N0:comp>',
'</N0:calendar-data>'
].join('');
test('output', function() {
var builder = new Builder({
template: template,
tag: ['caldav', 'calendar-data'],
compTag: ['caldav', 'comp'],
propTag: ['caldav', 'prop']
});
// set the root component
var cal = builder.setComp('VCALENDAR');
cal.prop('VERSION');
// vtimezone
cal.comp('VTIMEZONE');
// vevent
var event = cal.comp('VEVENT');
//shortcut method
event.prop([
'SUMMARY',
'UID',
'DTSTART',
'DTEND',
'DURATION',
'RRULE',
'RDATE',
'EXRULE',
'EXDATE',
'RECURRENCE-ID'
]);
var output = builder.toString();
assert.deepEqual(
output.trim(),
expected.trim()
);
});
});
// based on (calendar-filter):
// http://pretty-rfc.herokuapp.com/RFC4791#example-partial-retrieval-of-events-by-time-range
suite('spec test - filter', function() {
var expected = [
'<N0:filter>',
'<N0:comp-filter name="VCALENDAR">',
'<N0:comp-filter name="VEVENT">',
'<N0:time-range start="20060104T000000Z" ',
'end="20060105T000000Z" />',
'</N0:comp-filter>',
'</N0:comp-filter>',
'</N0:filter>'
].join('');
test('output', function() {
var filter = new Builder({
tag: ['caldav', 'filter'],
compTag: ['caldav', 'comp-filter'],
propTag: ['caldav', 'prop-filter'],
template: template
});
var event = filter.setComp('VCALENDAR').
comp('VEVENT');
event.setTimeRange({
start: '20060104T000000Z',
end: '20060105T000000Z'
});
var output = filter.toString();
assert.equal(expected, output);
});
});
});
|