removeEvents.js
3.97 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
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
describe('removeEvents', function() {
var options;
var eventArray = [
{ id: 0, title: 'event zero', start: '2014-06-24', className: 'event-zero' },
{ id: 1, title: 'event one', start: '2014-06-24', className: 'event-non-zero event-one' },
{ id: 2, title: 'event two', start: '2014-06-24', className: 'event-non-zero event-two' }
];
var eventFunc = function(start, end, timezone, callback) {
callback(eventArray);
};
beforeEach(function() {
affix('#cal');
options = {
defaultDate: '2014-06-24',
defaultView: 'month'
};
});
$.each({
'with an array of events': eventArray,
'with an event function': eventFunc
}, function(description, events) {
describe(description, function() {
it('can remove all events if no args specified', function(done) {
go(
events,
function() {
$('#cal').fullCalendar('removeEvents');
},
function() {
expect($('#cal').fullCalendar('clientEvents').length).toEqual(0);
expect($('.fc-event').length).toEqual(0);
},
done
);
});
it('can remove events with a numeric ID', function(done) {
go(
events,
function() {
$('#cal').fullCalendar('removeEvents', 1);
},
function() {
expect($('#cal').fullCalendar('clientEvents').length).toEqual(2);
expect($('.fc-event').length).toEqual(2);
expect($('.event-zero').length).toEqual(1);
expect($('.event-two').length).toEqual(1);
},
done
);
});
it('can remove events with a string ID', function(done) {
go(
events,
function() {
$('#cal').fullCalendar('removeEvents', '1');
},
function() {
expect($('#cal').fullCalendar('clientEvents').length).toEqual(2);
expect($('.fc-event').length).toEqual(2);
expect($('.event-zero').length).toEqual(1);
expect($('.event-two').length).toEqual(1);
},
done
);
});
it('can remove events with a filter function', function(done) {
go(
events,
function() {
$('#cal').fullCalendar('removeEvents', function(event) {
return $.inArray('event-one', event.className) !== -1;
});
},
function() {
expect($('#cal').fullCalendar('clientEvents').length).toEqual(2);
expect($('.fc-event').length).toEqual(2);
expect($('.event-zero').length).toEqual(1);
expect($('.event-two').length).toEqual(1);
},
done
);
});
it('can remove an event with ID 0', function(done) { // for issue 2082
go(
events,
function() {
$('#cal').fullCalendar('removeEvents', 0);
},
function() {
expect($('#cal').fullCalendar('clientEvents').length).toEqual(2);
expect($('.fc-event').length).toEqual(2);
expect($('.event-zero').length).toEqual(0);
expect($('.event-non-zero').length).toEqual(2);
},
done
);
});
});
});
// Verifies the actions in removeFunc executed correctly by calling checkFunc.
function go(events, removeFunc, checkFunc, doneFunc) {
var called = false;
options.events = events;
options.eventAfterAllRender = function() {
if (!called) { // don't execute on subsequent removeEvents/next/prev
called = true;
checkAllEvents(); // make sure all events initially rendered correctly
removeFunc(); // remove the events
checkFunc(); // check correctness
// move the calendar back out of view, then back in
$('#cal').fullCalendar('next');
$('#cal').fullCalendar('prev');
// array event sources should maintain the same state
// whereas "dynamic" event sources should refetch and reset the state
if ($.isArray(events)) {
checkFunc(); // for issue 2187
}
else {
checkAllEvents();
}
doneFunc();
}
};
$('#cal').fullCalendar(options);
}
// Checks to make sure all events have been rendered and that the calendar
// has internal info on all the events.
function checkAllEvents() {
expect($('#cal').fullCalendar('clientEvents').length).toEqual(3);
expect($('.fc-event').length).toEqual(3);
}
});