header-rendering.js
4.14 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
describe('header rendering', function() {
beforeEach(function() {
affix('#calendar');
});
describe('when using default header options', function() {
it('should have title as default on left', function() {
$('#calendar').fullCalendar();
expect($('#calendar > .fc-toolbar > .fc-left > *')).toBeMatchedBy('h2');
});
it('should have empty center', function() {
$('#calendar').fullCalendar();
var center = $('#calendar > .fc-toolbar > .fc-center');
expect(center).toBeEmpty();
});
it('should have right with today|space|left|right', function() {
$('#calendar').fullCalendar();
var rightChildren = $('#calendar > .fc-toolbar > .fc-right > *');
var todayButton = rightChildren.eq(0);
var buttonGroup = rightChildren.eq(1);
var prevNextButtons = buttonGroup.children();
expect(todayButton).toHaveClass('fc-today-button');
expect(buttonGroup).toHaveClass('fc-button-group');
expect(prevNextButtons.eq(0)).toHaveClass('fc-prev-button');
expect(prevNextButtons.eq(1)).toHaveClass('fc-next-button');
});
});
describe('when supplying header options', function() {
beforeEach(function() {
var options = {
header: {
left: 'next,prev',
center: 'prevYear today nextYear agendaView,dayView',
right: 'title'
}
};
$('#calendar').fullCalendar(options);
});
it('should have title on the right', function() {
expect($('#calendar > .fc-toolbar > .fc-right > *')).toBeMatchedBy('h2');
});
it('should have next|prev on left', function() {
var buttonGroup = $('#calendar > .fc-toolbar > .fc-left > *');
var prevNextButtons = buttonGroup.children();
expect(prevNextButtons.eq(0)).toHaveClass('fc-next-button');
expect(prevNextButtons.eq(1)).toHaveClass('fc-prev-button');
});
it('should have prevYear|space|today|space|nextYear in center', function() {
var items = $('#calendar > .fc-toolbar > .fc-center > *');
expect(items.eq(0)).toHaveClass('fc-prevYear-button');
expect(items.eq(1)).toHaveClass('fc-today-button');
expect(items.eq(2)).toHaveClass('fc-nextYear-button');
});
});
describe('when setting header to false', function() {
beforeEach(function() {
var options = {
header: false
};
$('#calendar').fullCalendar(options);
});
it('should not have header table', function() {
expect($('.fc-toolbar')).not.toBeInDOM();
});
});
describe('renders left and right literally', function() {
[ true, false ].forEach(function(isRTL) {
describe('when isRTL is ' + isRTL, function() {
beforeEach(function() {
var options = {};
$('#calendar').fullCalendar({
header: {
left: 'prev',
center: 'today',
right: 'next'
},
isRTL: isRTL
});
});
it('should have prev in left', function() {
var fcHeaderLeft = $('#calendar .fc-toolbar > .fc-left');
expect(fcHeaderLeft).toContainElement('.fc-prev-button');
});
it('should have today in center', function() {
var fcHeaderCenter = $('#calendar .fc-toolbar > .fc-center');
expect(fcHeaderCenter).toContainElement('.fc-today-button');
});
it('should have next in right', function() {
var fcHeaderRight = $('#calendar .fc-toolbar > .fc-right');
expect(fcHeaderRight).toContainElement('.fc-next-button');
});
});
});
});
describe('when calendar is within a form', function() {
beforeEach(function() {
$('#calendar').wrap('<form action="http://google.com/"></form>');
});
it('should not submit the form when clicking the button', function(done) {
var options = {
header: {
left: 'prev,next',
right: 'title'
}
};
var unloadCalled = false;
function beforeUnloadHandler() {
console.log('when calendar is within a form, it submits!!!');
unloadCalled = true;
cleanup();
return 'click stay on this page';
}
$(window).on('beforeunload', beforeUnloadHandler);
function cleanup() {
$(window).off('beforeunload', beforeUnloadHandler);
}
$('#calendar').fullCalendar(options);
$('.fc-next-button').simulate('click');
setTimeout(function() { // wait to see if handler was called
expect(unloadCalled).toBe(false);
cleanup();
done();
}, 100);
});
});
});