dayRender.js
2.38 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
describe('dayRender', function() {
beforeEach(function() {
affix('#cal');
});
it('is triggered upon initialization of a view, with correct parameters', function() {
var options = {
defaultView: 'month',
weekMode: 'fixed',
defaultDate: '2014-05-01',
dayRender: function(date, cell) {
expect(moment.isMoment(date)).toEqual(true);
expect(date.hasTime()).toEqual(false);
expect(date.format()).toEqual(cell.data('date'));
expect(cell).toBeInDOM();
}
};
spyOn(options, 'dayRender').and.callThrough();
$('#cal').fullCalendar(options);
expect(options.dayRender.calls.count()).toEqual(42);
});
it('is called when view is changed', function() {
var options = {
defaultView: 'month',
weekMode: 'fixed',
defaultDate: '2014-05-01',
dayRender: function(date, cell) { }
};
spyOn(options, 'dayRender').and.callThrough();
$('#cal').fullCalendar(options);
options.dayRender.calls.reset();
$('#cal').fullCalendar('changeView', 'basicWeek');
expect(options.dayRender.calls.count()).toEqual(7);
});
// called if the date is navigated to a different visible range
it('is called when view is changed', function() {
var options = {
defaultView: 'basicWeek',
defaultDate: '2014-05-01',
dayRender: function(date, cell) { }
};
spyOn(options, 'dayRender').and.callThrough();
$('#cal').fullCalendar(options);
options.dayRender.calls.reset();
$('#cal').fullCalendar('gotoDate', '2014-05-04'); // a day in the next week
expect(options.dayRender.calls.count()).toEqual(7);
});
it('won\'t be called when date is navigated but remains in the current visible range', function() {
var options = {
defaultView: 'basicWeek',
defaultDate: '2014-05-01',
dayRender: function(date, cell) { }
};
spyOn(options, 'dayRender').and.callThrough();
$('#cal').fullCalendar(options);
options.dayRender.calls.reset();
$('#cal').fullCalendar('gotoDate', '2014-05-02'); // a day in the same week
expect(options.dayRender.calls.count()).toEqual(0);
});
it('allows you to modify the element', function() {
var options = {
defaultView: 'month',
weekMode: 'fixed',
defaultDate: '2014-05-01',
dayRender: function(date, cell) {
if (date.isSame('2014-05-01')) {
cell.addClass('mycustomclass');
}
}
};
$('#cal').fullCalendar(options);
expect($('#cal td[data-date="2014-05-01"]')).toHaveClass('mycustomclass');
});
});