eventLimit.js
7.94 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
describe('eventLimit', function() {
var options;
beforeEach(function() {
affix('#cal');
options = {
defaultDate: '2014-08-01' // important that it is the first week, so works w/ month + week views
};
});
describe('as a number', function() {
beforeEach(function() {
options.eventLimit = 3;
});
[ 'month', 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
describe('when in ' + viewName + ' view', function() {
beforeEach(function() {
options.defaultView = viewName;
});
it('doesn\'t display a more link when limit is more than the # of events', function() {
options.events = [
{ title: 'event1', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' }
];
$('#cal').fullCalendar(options);
expect($('.fc-more').length).toBe(0);
});
it('doesn\'t display a more link when limit equal to the # of events', function() {
options.events = [
{ title: 'event1', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' }
];
$('#cal').fullCalendar(options);
expect($('.fc-more').length).toBe(0);
});
it('displays a more link when limit is less than the # of events', function() {
options.events = [
{ title: 'event1', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' }
];
$('#cal').fullCalendar(options);
expect($('.fc-more').length).toBe(1);
expect($('.fc-more')).toHaveText('+2 more');
});
it('displays one more per day, when a multi-day event is above', function() {
options.events = [
{ title: 'event1', start: '2014-07-29', end: '2014-07-31' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-31' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-31' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-31' }
];
$('#cal').fullCalendar(options);
var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)');
expect($('.fc-more').length).toBe(2);
expect($('.fc-more').eq(0)).toHaveText('+2 more');
expect($('.fc-more').eq(0)).toBeBoundedBy(cells.eq(2));
expect($('.fc-more').eq(1)).toHaveText('+2 more');
expect($('.fc-more').eq(1)).toBeBoundedBy(cells.eq(3));
});
it('will render a link in a multi-day event\'s second column ' +
'if it has already been hidden in the first',
function() {
options.events = [
{ title: 'event1', start: '2014-07-29', end: '2014-07-31' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-31' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-31' },
{ title: 'event2', start: '2014-07-29' }
];
$('#cal').fullCalendar(options);
var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)');
expect($('.fc-more').length).toBe(2);
expect($('.fc-more').eq(0)).toHaveText('+2 more');
expect($('.fc-more').eq(0)).toBeBoundedBy(cells.eq(2));
expect($('.fc-more').eq(1)).toHaveText('+1 more');
expect($('.fc-more').eq(1)).toBeBoundedBy(cells.eq(3));
});
it('will render a link in a multi-day event\'s second column ' +
'if it has already been hidden in the first even if he second column hardly has any events',
function() {
options.events = [
{ title: 'event1', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-29', end: '2014-07-31' }
];
$('#cal').fullCalendar(options);
var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)');
var link = $('.fc-more').eq(0); // will appear to be the third link, but will be in first row, so 0dom
expect(link.length).toBe(1);
expect(link).toHaveText('+1 more');
expect(link).toBeBoundedBy(cells.eq(3));
});
it('will render a link in place of a hidden single day event, if covered by a multi-day', function() {
options.events = [
{ title: 'event1', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-28' },
{ title: 'event2', start: '2014-07-28' }
];
$('#cal').fullCalendar(options);
var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)');
var link = $('.fc-more').eq(0);
expect(link.length).toBe(1);
expect(link).toHaveText('+2 more');
expect(link).toBeBoundedBy(cells.eq(1));
});
it('will render a link in place of a hidden single day event, if covered by a multi-day ' +
'and in its second column',
function() {
options.events = [
{ title: 'event1', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' }
];
$('#cal').fullCalendar(options);
var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)');
var link = $('.fc-more').eq(0);
expect(link.length).toBe(1);
expect(link).toHaveText('+2 more');
expect(link).toBeBoundedBy(cells.eq(2));
});
});
});
});
describe('when auto', function() {
beforeEach(function() {
options.eventLimit = true;
});
describe('in month view', function() {
beforeEach(function() {
options.defaultView = 'month';
options.events = [
{ title: 'event1', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-28', end: '2014-07-30' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' }
];
});
it('renders the heights of all the rows the same, regardless of # of events', function() {
$('#cal').fullCalendar(options);
var rowEls = $('.fc-day-grid .fc-row').slice(0, -1); // remove last b/c it will be a different height
expect(rowEls.length).toBeGreaterThan(0);
var height = rowEls.height();
rowEls.each(function(i, node) {
expect($(node).height()).toBe(height);
});
});
it('renders a more link when there are obviously too many events', function() {
$('#cal').width(800);
$('#cal').fullCalendar(options);
expect($('#cal .fc-more').length).toBe(1);
});
});
[ 'month', 'basicWeek' ].forEach(function(viewName) {
describe('in ' + viewName + ' view', function() {
beforeEach(function() {
options.defaultView = viewName;
});
it('doesn\'t render a more link where there should obviously not be a limit', function() {
options.events = [
{ title: 'event1', start: '2014-07-28', end: '2014-07-30' }
];
$('#cal').fullCalendar(options);
expect($('.fc-more').length).toBe(0);
});
});
});
describe('in agendaWeek view', function() {
beforeEach(function() {
options.defaultView = 'agendaWeek';
});
it('behaves as if limit is 5', function() {
options.events = [
{ title: 'event1', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' },
{ title: 'event2', start: '2014-07-29' }
];
$('#cal').fullCalendar(options);
expect($('.fc-event:visible').length).toBe(4);
expect($('.fc-more').length).toBe(1);
expect($('.fc-more')).toHaveText('+3 more');
});
});
});
});