event-obj.js
4.4 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
describe('event object creation', function() {
/*
NOTE: Where possible, if there is a specific option that affects event object creation
behavior, write your tests in the individual file for that option, instead of here.
Examples of this:
allDayDefault (tests allDay guessing behavior too)
eventDataTransform
forceEventDuration
*/
var event;
beforeEach(function() {
affix('#cal');
event = null;
});
function init(singleEventData) {
$('#cal').fullCalendar({
events: [ singleEventData ]
});
event = $('#cal').fullCalendar('clientEvents')[0];
}
it('accepts `date` property as alias for `start`', function() {
init({
date: '2014-05-05'
});
expect(moment.isMoment(event.start)).toEqual(true);
expect(event.start).toEqualMoment('2014-05-05');
});
it('doesn\'t produce an event when an invalid start', function() {
init({
start: new Date('asdf') // we use Date constructor to avoid annoying momentjs warning
});
expect(event).toBeUndefined();
});
it('produces null end when given an invalid date', function() {
init({
start: '2014-05-01',
end: new Date('asdf') // we use Date constructor to avoid annoying momentjs warning
});
expect(event.start).toEqualMoment('2014-05-01');
expect(event.end).toBe(null);
});
it('produces null end when given a timed end before the start', function() {
init({
start: '2014-05-02T00:00:00',
end: '2014-05-01T23:00:00'
});
expect(event.start).toEqualMoment('2014-05-02T00:00:00');
expect(event.end).toBe(null);
});
it('produces null end when given a timed end equal to the start', function() {
init({
start: '2014-05-02T00:00:00',
end: '2014-05-01T00:00:00'
});
expect(event.start).toEqualMoment('2014-05-02T00:00:00');
expect(event.end).toBe(null);
});
it('produces null end when given an all-day end before the start', function() {
init({
start: '2014-05-02',
end: '2014-05-02'
});
expect(event.start).toEqualMoment('2014-05-02');
expect(event.end).toBe(null);
});
it('produces null end when given an all-day end equal to the start', function() {
init({
start: '2014-05-02T00:00:00',
end: '2014-05-02T00:00:00'
});
expect(event.start).toEqualMoment('2014-05-02T00:00:00');
expect(event.end).toBe(null);
});
it('allows ASP dates for start', function() {
init({
start: '\/Date(1239018869048)\/',
end: '\/Date(1239105269048)\/'
});
expect(moment.isMoment(event.start)).toBe(true);
expect(+event.start).toBe(1239018869048);
expect(moment.isMoment(event.end)).toBe(true);
expect(+event.end).toBe(1239105269048);
});
it('produces null end when given an invalid ASP date end', function() {
init({
start: '\/Date(1239018869048)\/',
end: '\/Date(1239018869048)\/' // same as start
});
expect(moment.isMoment(event.start)).toBe(true);
expect(+event.start).toBe(1239018869048);
expect(event.end).toBe(null);
});
it('strips times of dates when event is all-day', function() {
init({
start: '2014-05-01T01:00:00-12:00',
end: '2014-05-02T01:00:00+12:00',
allDay: true
});
expect(event.start.hasTime()).toEqual(false);
expect(event.start).toEqualMoment('2014-05-01');
expect(event.end.hasTime()).toEqual(false);
expect(event.end).toEqualMoment('2014-05-02');
});
it('gives 00:00 times to ambiguously-timed dates when event is timed', function() {
init({
start: '2014-05-01',
end: '2014-05-03',
allDay: false
});
expect(event.start.hasTime()).toEqual(true);
expect(event.start).toEqualMoment('2014-05-01T00:00:00');
expect(event.end.hasTime()).toEqual(true);
expect(event.end).toEqualMoment('2014-05-03T00:00:00');
});
it('sets the source', function() {
init({
start: '2014-05-01'
});
expect(typeof event.source).toEqual('object');
});
it('accepts an array `className`', function() {
init({
start: '2014-05-01',
className: [ 'class1', 'class2' ]
});
expect($.isArray(event.className)).toEqual(true);
expect(event.className).toEqual([ 'class1', 'class2' ]);
});
it('accepts a string `className`', function() {
init({
start: '2014-05-01',
className: 'class1 class2'
});
expect($.isArray(event.className)).toEqual(true);
expect(event.className).toEqual([ 'class1', 'class2' ]);
});
it('copies over custom properties', function() {
init({
start: '2014-05-01',
prop1: 'prop1val',
prop2: [ 'a', 'b' ]
});
expect(event.prop1).toEqual('prop1val');
expect(event.prop2).toEqual([ 'a', 'b' ]);
});
});