removeEventSource.js
2.64 KB
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
describe('removeEventSource', function() {
var options;
beforeEach(function() {
affix('#cal');
options = {
defaultDate: '2014-08-01'
};
$.mockjax({
url: '*',
contentType: 'text/json',
responseText: buildEventArray()
});
$.mockjaxSettings.log = function() { }; // don't console.log
});
afterEach(function() {
$.mockjaxClear();
});
describe('with a URL', function() {
testInput('/myscript.php'); // will go to mockjax
});
describe('with an array', function() {
testInput(buildEventArray());
});
describe('with a function', function() {
testInput(function(start, end, timezone, callback) {
callback(buildEventArray());
});
});
describe('with an object+url', function() {
testInput({
url: '/myscript.php' // will go to mockjax
});
});
describe('with an object+array', function() {
testInput({
events: buildEventArray()
});
});
describe('with an object+function', function() {
testInput({
events: function(start, end, timezone, callback) {
callback(buildEventArray());
}
});
});
function testInput(eventInput) {
it('correctly removes events provided via `events` at initialization', function(done) {
var callCnt = 0;
options.eventAfterAllRender = function() {
if (!(callCnt++)) { // only the first time
expectEventCnt(2);
$('#cal').fullCalendar('removeEventSource', eventInput);
expectEventCnt(0);
done();
}
};
options.events = eventInput;
$('#cal').fullCalendar(options);
});
it('correctly removes events provided via `eventSources` at initialization', function(done) {
var callCnt = 0;
options.eventAfterAllRender = function() {
if (!(callCnt++)) { // only the first time
expectEventCnt(2);
$('#cal').fullCalendar('removeEventSource', eventInput);
expectEventCnt(0);
done();
}
};
options.eventSources = [ eventInput ];
$('#cal').fullCalendar(options);
});
it('correctly removes events provided via `addEventSource` method', function(done) {
var callCnt = 0;
options.eventAfterAllRender = function() {
if ((callCnt++) === 1) { // the second time (the first time is upon initial render)
expectEventCnt(2);
$('#cal').fullCalendar('removeEventSource', eventInput);
expectEventCnt(0);
done();
}
};
$('#cal').fullCalendar(options);
$('#cal').fullCalendar('addEventSource', eventInput);
});
}
function buildEventArray() {
return [
{ title: 'event1', start: '2014-08-01' },
{ title: 'event2', start: '2014-08-02' }
];
}
function expectEventCnt(cnt) {
expect($('.fc-event').length).toBe(cnt);
expect($('#cal').fullCalendar('clientEvents').length).toBe(cnt);
}
});