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('');
var out = subject.toString();
assert.equal(
out,
''
);
});
});
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, '');
});
test('#setRecurrenceSetLimit', function() {
var subject = new Builder({ template: template });
subject.setRecurrenceSetLimit({
start: 'a',
end: 'b'
});
var expected = [
'',
'',
''
].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 = [
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
].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 = [
'',
'',
'',
'',
'',
'',
''
].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);
});
});
});