summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/directives/calendar/test/calendarSpec.js
blob: b3e9ac01b618ec5694fbaf2af8801b891eb0f356 (plain)
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
/*global beforeEach, afterEach, describe, it, inject, expect, module, spyOn, fullcalendar, angular, $*/
describe('uiCalendar', function () {
    'use strict';

    var scope, $compile;

    beforeEach(module('ui'));
    beforeEach(inject(function (_$rootScope_, _$compile_) {
        scope = _$rootScope_.$new();
        $compile = _$compile_;

        
          //Date Objects needed for event
          var date = new Date();
          var d = date.getDate();
          var m = date.getMonth();
          var y = date.getFullYear();

          // create an array of events, to pass into the directive. 
          scope.events = [
            {title: 'All Day Event',start: new Date(y, m, 1),url: 'http://www.angularjs.org'},
            {title: 'Long Event',start: new Date(y, m, d - 5),end: new Date(y, m, d - 2)},
            {id: 999,title: 'Repeating Event',start: new Date(y, m, d - 3, 16, 0),allDay: false},
            {id: 999,title: 'Repeating Event',start: new Date(y, m, d + 4, 16, 0),allDay: true}];

          // create an array of events, to pass into the directive. 
          scope.events2 = [
            {title: 'All Day Event 2',start: new Date(y, m, 1),url: 'http://www.atlantacarlocksmith.com'},
            {title: 'Long Event 2',start: new Date(y, m, d - 5),end: new Date(y, m, d - 2)},
            {id: 998,title: 'Repeating Event 2',start: new Date(y, m, d - 3, 16, 0),allDay: false},
            {id: 998,title: 'Repeating Event 2',start: new Date(y, m, d + 4, 16, 0),allDay: true}];
          //array to test equalsTracker with
          scope.events3 = [
            {title: 'All Day Event 3',start: new Date(y, m, 1),url: 'http://www.atlantacarlocksmith.com'},
            {title: 'Long Event 3',start: new Date(y, m, d - 5),end: new Date(y, m, d - 2)},
            {id: 998,title: 'Repeating Event 3',start: new Date(y, m, d - 3, 16, 0),allDay: false},
            {id: 998,title: 'Repeating Event 3',start: new Date(y, m, d + 4, 16, 0),allDay: true}];

          // create an array of events, to pass into the directive. 
          scope.events4 = [{title: 'All Day Event 3',start: new Date(y, m, 1),url: 'http://www.yoyoyo.com'}];

          //equalsTracker to force the calendar to update on rare occasions
          //ie... an event source is replacing another and has the same length as the prior eventSource
          //or... replacing an eventSource that is an object with another eventSource
          scope.equalsTracker = 0;

          //event Sources array  
          scope.eventSources = [scope.events,scope.events2]; //End of Events Array
          
          scope.addSource = function(source) {
            scope.eventSources.push(source);
          };

          scope.addChild = function(array) {
            array.push({
              title: 'Click for Google ' + scope.events.length,
              start: new Date(y, m, 28),
              end: new Date(y, m, 29),
              url: 'http://google.com/'
            });
          };

          scope.remove = function(array,index) {
            array.splice(index,1);
          };

          scope.uiConfig = {
            calendar:{
              height: 200,
              weekends: false,
              defaultView: 'month'
           }
          };
         
    }));

    afterEach(function() {
      angular.module('ui.config').value('ui.config', {}); // cleanup
    });

    describe('compiling this directive and checking for events inside the calendar', function () {


        /* test the calendar's events length  */
        it('should excpect to load 4 events to scope', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toBe(4);
        });
        /* test to check the title of the first event. */
        it('should excpect to be All Day Event', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][0].title).toBe('All Day Event');
        });
        /* test to make sure the event has a url assigned to it. */
        it('should expect the url to = http://www.angularjs.org', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][0].url).toBe('http://www.angularjs.org');
            expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[1][0].url).toBe('http://www.atlantacarlocksmith.com');
        });
        /* test the 3rd events' allDay field. */
        it('should expect the fourth Events all Day field to equal true', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][3].allDay).toNotBe(false);
        });
        /* Tests the height of the calendar. */
        it('should expect the calendar attribute height to be 200', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].height).toEqual(200);  
        });
        /* Tests the weekends boolean of the calendar. */
        it('should expect the calendar attribute weekends to be false', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].weekends).toEqual(false);
        });
        /* Test to make sure that when an event is added to the calendar everything is updated with the new event. */
        it('should expect the scopes events to increase by 2', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toEqual(4);
            scope.addChild(scope.events);
            scope.addChild(scope.events);
            expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toEqual(6);
        });
        /* Test to make sure the calendar is updating itself on changes to events length. */
        it('should expect the calendar to update itself with new events', function () {
            spyOn($.fn, 'fullCalendar');
            $compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
            var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
            expect(clientEventsLength).toEqual(4);
            //remove an event from the scope.
            scope.remove(scope.events,0);
            //events should auto update inside the calendar. 
            clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
            expect(clientEventsLength).toEqual(3);
        });
        /* Test to make sure header options can be overwritten */
        it('should overwrite default header options', function () {
            spyOn($.fn, 'fullCalendar');
            scope.uiConfig2 = {
              calendar:{
                header: {center: 'title'} 
             }
            };
            $compile('<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>')(scope);
            expect($.fn.fullCalendar.mostRecentCall.args[0].hasOwnProperty('header')).toEqual(true);
            var header = $.fn.fullCalendar.mostRecentCall.args[0].header;