eventLimit-popover.js
8.76 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
describe('eventLimit popover', function() {
var options;
beforeEach(function() {
affix('#cal');
options = {
defaultView: 'month',
defaultDate: '2014-08-01',
eventLimit: 3,
events: [
{ title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
{ title: 'event3', start: '2014-07-29', className: 'event3' },
{ title: 'event4', start: '2014-07-29', className: 'event4' }
],
dragScroll: false, // don't do autoscrolling while dragging. close quarters in PhantomJS
popoverViewportConstrain: false, // because PhantomJS window is small, don't do smart repositioning
handleWindowResize: false // because showing the popover causes scrollbars and fires resize
};
});
function init() {
$('#cal').fullCalendar(options);
$('.fc-more').simulate('click');
}
[ 'month', 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
describe('when in ' + viewName + ' view', function() {
beforeEach(function() {
options.defaultView = viewName;
});
it('aligns horizontally with left edge of cell if LTR', function() {
options.isRTL = false;
init();
var cellLeft = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(2)').offset().left;
var popoverLeft = $('.fc-more-popover').offset().left;
var diff = Math.abs(cellLeft - popoverLeft);
expect(diff).toBeLessThan(2);
});
it('aligns horizontally with left edge of cell if RTL', function() {
options.isRTL = true;
init();
var cell = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(4)');
var cellRight = cell.offset().left + cell.outerWidth();
var popover = $('.fc-more-popover');
var popoverRight = popover.offset().left + popover.outerWidth();
var diff = Math.abs(cellRight - popoverRight);
expect(diff).toBeLessThan(2);
});
});
});
describe('when in month view', function() {
beforeEach(function() {
options.defaultView = 'month';
});
it('aligns with top of cell', function() {
init();
var popoverTop = $('.fc-more-popover').offset().top;
var rowTop = $('.fc-day-grid .fc-row:eq(0)').offset().top;
var diff = Math.abs(popoverTop - rowTop);
expect(diff).toBeLessThan(2);
});
it('works with background events', function() {
options.events.push({
start: '2014-07-29',
rendering: 'background'
});
init();
expect($('.fc-more-popover .fc-event').length).toBeGreaterThan(1);
expect($('.fc-more-popover .fc-bgevent').length).toBe(0);
});
it('works with events that have invalid end times', function() {
options.events = [
{ title: 'event1', start: '2014-07-29', end: '2014-07-29' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-28' },
{ title: 'event3', start: '2014-07-29T00:00:00', end: '2014-07-29T00:00:00' },
{ title: 'event4', start: '2014-07-29T00:00:00', end: '2014-07-28T23:00:00' }
];
init();
expect($('.fc-more-popover .fc-event').length).toBe(4);
});
// issue 2385
it('orders events correctly regardless of ID', function() {
options.defaultDate = '2012-03-22';
options.eventLimit = 3;
options.events = [
{
id: '39957',
title: 'event01',
start: '2012-03-22T11:00:00',
end: '2012-03-22T11:30:00',
allDay: false
},
{
id: '40607',
title: 'event02',
start: '2012-03-22T16:15:00',
end: '2012-03-22T16:30:00',
allDay: false
},
{
id: '40760',
title: 'event03',
start: '2012-03-22T16:00:00',
end: '2012-03-22T16:15:00',
allDay: false
},
{
id: '41284',
title: 'event04',
start: '2012-03-22T19:00:00',
end: '2012-03-22T19:15:00',
allDay: false
},
{
id: '41645',
title: 'event05',
start: '2012-03-22T11:30:00',
end: '2012-03-22T12:00:00',
allDay: false
},
{
id: '41679',
title: 'event07',
start: '2012-03-22T12:00:00',
end: '2012-03-22T12:15:00',
allDay: false
},
{
id: '42246',
title: 'event08',
start: '2012-03-22T16:45:00',
end: '2012-03-22T17:00:00',
allDay: false
}
];
init();
var titles = $('.fc-more-popover .fc-event .fc-title').map(function() {
return $(this).text();
}).get();
expect(titles).toEqual([
'event01', 'event05', 'event07', 'event03', 'event02', 'event08', 'event04'
]);
});
});
[ 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
describe('when in ' + viewName + ' view', function() {
beforeEach(function() {
options.defaultView = viewName;
});
it('aligns with top of header', function() {
init();
var popoverTop = $('.fc-more-popover').offset().top;
var headTop = $('.fc-view > table > thead .fc-row').offset().top;
var diff = Math.abs(popoverTop - headTop);
expect(diff).toBeLessThan(2);
});
});
});
// TODO: somehow test how the popover does to the edge of any scroll container
it('closes when user clicks the X', function() {
init();
expect($('.fc-more-popover')).toBeVisible();
$('.fc-more-popover .fc-close')
.simulate('click')
.trigger('click'); // needed this for IE8 for some reason
expect($('.fc-more-popover')).not.toBeVisible();
});
it('doesn\'t close when user clicks somewhere inside of the popover', function() {
init();
expect($('.fc-more-popover')).toBeVisible();
expect($('.fc-more-popover .fc-header')).toBeInDOM();
$('.fc-more-popover .fc-header').simulate('mousedown').simulate('click');
expect($('.fc-more-popover')).toBeVisible();
});
it('closes when user clicks outside of the popover', function() {
init();
expect($('.fc-more-popover')).toBeVisible();
$('body').simulate('mousedown').simulate('click');
expect($('.fc-more-popover')).not.toBeVisible();
});
it('has the correct event contents', function() {
init();
expect($('.fc-more-popover .event1')).toBeMatchedBy('.fc-not-start.fc-end');
expect($('.fc-more-popover .event2')).toBeMatchedBy('.fc-start.fc-not-end');
expect($('.fc-more-popover .event3')).toBeMatchedBy('.fc-start.fc-end');
expect($('.fc-more-popover .event4')).toBeMatchedBy('.fc-start.fc-end');
});
describe('when dragging events out', function() {
beforeEach(function() {
options.editable = true;
});
describe('when dragging an all-day event to a different day', function() {
it('should have the new day and remain all-day', function(done) {
options.eventDrop = function(event) {
expect(event.start).toEqualMoment('2014-07-28');
expect(event.allDay).toBe(true);
done();
};
init();
setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
$('.fc-more-popover .event4').simulate('drag-n-drop', {
dragTarget: $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(1)') // one day before
});
}, 0);
});
});
describe('when dragging a timed event to a whole day', function() {
it('should move to new day but maintain its time', function(done) {
options.events.push({ // add timed event
title: 'event5',
start: '2014-07-29T13:00:00',
className: 'event5'
});
options.eventDrop = function(event) {
expect(event.start).toEqualMoment('2014-07-28T13:00:00');
expect(event.allDay).toBe(false);
done();
};
init();
setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
$('.fc-more-popover .event5').simulate('drag-n-drop', {
dragTarget: $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(1)') // one day before
});
}, 0);
});
});
describe('when dragging a whole day event to a timed slot', function() {
it('should assume the new time, with a cleared end', function(done) {
options.defaultView = 'agendaWeek';
options.scrollTime = '00:00:00';
options.eventDrop = function(event) {
expect(event.start).toEqualMoment('2014-07-30T03:00:00');
expect(event.allDay).toBe(false);
done();
};
init();
setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
$('.fc-more-popover .event4').simulate('drag-n-drop', {
dragTarget: $('.fc-slats tr:eq(6)') // the middle will be 7/30, 3:00am
});
}, 0);
});
});
describe('when a single-day event isn\'t dragged out all the way', function() {
it('shouldn\'t do anything', function(done) {
options.eventDragStop = function() {
setTimeout(function() { // try to wait until drag is over. eventDrop won't fire BTW
expect($('.fc-more-popover')).toBeInDOM();
done();
},0);
};
init();
setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
$('.fc-more-popover .event1 .fc-title').simulate('drag-n-drop', {
dx: 20
});
}, 0);
});
});
});
});