@@ -18,38 +18,48 @@ describe('uiCalendar', function () {
18
18
19
19
// create an array of events, to pass into the directive.
20
20
scope . events = [
21
- {
22
- title : 'All Day Event' ,
23
- start : new Date ( y , m , 1 ) ,
24
- url : 'http://www.angularjs.org' } ,
25
- {
26
- title : 'Long Event' ,
27
- start : new Date ( y , m , d - 5 ) ,
28
- end : new Date ( y , m , d - 2 ) } ,
29
- {
30
- id : 999 ,
31
- title : 'Repeating Event' ,
32
- start : new Date ( y , m , d - 3 , 16 , 0 ) ,
33
- allDay : false } ,
34
- {
35
- id : 999 ,
36
- title : 'Repeating Event' ,
37
- start : new Date ( y , m , d + 4 , 16 , 0 ) ,
38
- allDay : true }
39
- ] ; //End of Events Array
40
-
41
- scope . addChild = function ( ) {
42
- scope . events . push ( {
21
+ { title : 'All Day Event' , start : new Date ( y , m , 1 ) , url : 'http://www.angularjs.org' } ,
22
+ { title : 'Long Event' , start : new Date ( y , m , d - 5 ) , end : new Date ( y , m , d - 2 ) } ,
23
+ { id : 999 , title : 'Repeating Event' , start : new Date ( y , m , d - 3 , 16 , 0 ) , allDay : false } ,
24
+ { id : 999 , title : 'Repeating Event' , start : new Date ( y , m , d + 4 , 16 , 0 ) , allDay : true } ] ;
25
+
26
+ // create an array of events, to pass into the directive.
27
+ scope . events2 = [
28
+ { title : 'All Day Event 2' , start : new Date ( y , m , 1 ) , url : 'http://www.atlantacarlocksmith.com' } ,
29
+ { title : 'Long Event 2' , start : new Date ( y , m , d - 5 ) , end : new Date ( y , m , d - 2 ) } ,
30
+ { id : 998 , title : 'Repeating Event 2' , start : new Date ( y , m , d - 3 , 16 , 0 ) , allDay : false } ,
31
+ { id : 998 , title : 'Repeating Event 2' , start : new Date ( y , m , d + 4 , 16 , 0 ) , allDay : true } ] ;
32
+
33
+ // create an array of events, to pass into the directive.
34
+ scope . events3 = [ { title : 'All Day Event 3' , start : new Date ( y , m , 1 ) , url : 'http://www.yoyoyo.com' } ] ;
35
+
36
+ //event Sources array
37
+ scope . eventSources = [ scope . events , scope . events2 ] ; //End of Events Array
38
+
39
+ scope . addSource = function ( source ) {
40
+ scope . eventSources . push ( source ) ;
41
+ } ;
42
+
43
+ scope . addChild = function ( array ) {
44
+ array . push ( {
43
45
title : 'Click for Google ' + scope . events . length ,
44
46
start : new Date ( y , m , 28 ) ,
45
47
end : new Date ( y , m , 29 ) ,
46
48
url : 'http://google.com/'
47
49
} ) ;
48
50
} ;
49
51
50
- scope . remove = function ( index ) {
51
- scope . events . splice ( index , 1 ) ;
52
- } ;
52
+ scope . remove = function ( array , index ) {
53
+ array . splice ( index , 1 ) ;
54
+ } ;
55
+
56
+ scope . uiConfig = {
57
+ calendar :{
58
+ height : 200 ,
59
+ weekends : false ,
60
+ defaultView : 'month'
61
+ }
62
+ } ;
53
63
54
64
} ) ) ;
55
65
@@ -60,66 +70,113 @@ describe('uiCalendar', function () {
60
70
describe ( 'compiling this directive and checking for events inside the calendar' , function ( ) {
61
71
62
72
63
- // test the calendars events length to be 4
73
+ /* test the calendar's events length */
64
74
it ( 'should excpect to load 4 events to scope' , function ( ) {
65
75
spyOn ( $ . fn , 'fullCalendar' ) ;
66
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false} " ng-model="events "></div>' ) ( scope ) ;
67
- expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events . length ) . toBe ( 4 ) ;
76
+ $compile ( '<div ui-calendar="uiConfig.calendar " ng-model="eventSources "></div>' ) ( scope ) ;
77
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ) . toBe ( 4 ) ;
68
78
} ) ;
69
- // test to check the title of the first event.
79
+ /* test to check the title of the first event. */
70
80
it ( 'should excpect to be All Day Event' , function ( ) {
71
81
spyOn ( $ . fn , 'fullCalendar' ) ;
72
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false} " ng-model="events "></div>' ) ( scope ) ;
73
- expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events [ 0 ] . title ) . toBe ( 'All Day Event' ) ;
82
+ $compile ( '<div ui-calendar="uiConfig.calendar " ng-model="eventSources "></div>' ) ( scope ) ;
83
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] [ 0 ] . title ) . toBe ( 'All Day Event' ) ;
74
84
} ) ;
75
- // test to make sure the event has a url assigned to it.
85
+ /* test to make sure the event has a url assigned to it. */
76
86
it ( 'should expect the url to = http://www.angularjs.org' , function ( ) {
77
87
spyOn ( $ . fn , 'fullCalendar' ) ;
78
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false}" ng-model="events"></div>' ) ( scope ) ;
79
- expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events [ 0 ] . url ) . toBe ( 'http://www.angularjs.org' ) ;
88
+ $compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
89
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] [ 0 ] . url ) . toBe ( 'http://www.angularjs.org' ) ;
90
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 1 ] [ 0 ] . url ) . toBe ( 'http://www.atlantacarlocksmith.com' ) ;
80
91
} ) ;
81
- // test the 3rd events' allDay field.
92
+ /* test the 3rd events' allDay field. */
82
93
it ( 'should expect the fourth Events all Day field to equal true' , function ( ) {
83
94
spyOn ( $ . fn , 'fullCalendar' ) ;
84
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false} " ng-model="events "></div>' ) ( scope ) ;
85
- expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events [ 3 ] . allDay ) . toNotBe ( false ) ;
95
+ $compile ( '<div ui-calendar="uiConfig.calendar " ng-model="eventSources "></div>' ) ( scope ) ;
96
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] [ 3 ] . allDay ) . toNotBe ( false ) ;
86
97
} ) ;
87
- // Tests the height of the calendar.
98
+ /* Tests the height of the calendar. */
88
99
it ( 'should expect the calendar attribute height to be 200' , function ( ) {
89
100
spyOn ( $ . fn , 'fullCalendar' ) ;
90
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false}" ng-model="events"></div>' ) ( scope ) ;
91
- //console.log('hello ' + $.fn.fullCalendar.mostRecentCall.args[0]);
92
- expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . height ) . toEqual ( 200 ) ;
93
-
101
+ $compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
102
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . height ) . toEqual ( 200 ) ;
94
103
} ) ;
95
- // Tests the weekends boolean of the calendar.
104
+ /* Tests the weekends boolean of the calendar. */
96
105
it ( 'should expect the calendar attribute weekends to be false' , function ( ) {
97
106
spyOn ( $ . fn , 'fullCalendar' ) ;
98
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false} " ng-model="events "></div>' ) ( scope ) ;
107
+ $compile ( '<div ui-calendar="uiConfig.calendar " ng-model="eventSources "></div>' ) ( scope ) ;
99
108
expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . weekends ) . toEqual ( false ) ;
100
109
} ) ;
101
- // Test to make sure that when an event is added to the calendar everything is updated with the new event.
110
+ /* Test to make sure that when an event is added to the calendar everything is updated with the new event. */
102
111
it ( 'should expect the scopes events to increase by 2' , function ( ) {
103
112
spyOn ( $ . fn , 'fullCalendar' ) ;
104
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false} " ng-model="events "></div>' ) ( scope ) ;
105
- expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events . length ) . toEqual ( 4 ) ;
106
- scope . addChild ( ) ;
107
- scope . addChild ( ) ;
108
- expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events . length ) . toEqual ( 6 ) ;
113
+ $compile ( '<div ui-calendar="uiConfig.calendar " ng-model="eventSources "></div>' ) ( scope ) ;
114
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ) . toEqual ( 4 ) ;
115
+ scope . addChild ( scope . events ) ;
116
+ scope . addChild ( scope . events ) ;
117
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ) . toEqual ( 6 ) ;
109
118
} ) ;
110
- // Test to make sure the calendar is updating itself on changes to events length.
119
+ /* Test to make sure the calendar is updating itself on changes to events length. */
111
120
it ( 'should expect the calendar to update itself with new events' , function ( ) {
112
121
spyOn ( $ . fn , 'fullCalendar' ) ;
113
- $compile ( '<div id="uicalendar" ui-calendar="{height: 200, weekends: false} " ng-model="events "></div>' ) ( scope ) ;
114
- var clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events . length ;
122
+ $compile ( '<div ui-calendar="uiConfig.calendar " ng-model="eventSources "></div>' ) ( scope ) ;
123
+ var clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
115
124
expect ( clientEventsLength ) . toEqual ( 4 ) ;
116
125
//remove an event from the scope.
117
- scope . remove ( 0 ) ;
126
+ scope . remove ( scope . events , 0 ) ;
118
127
//events should auto update inside the calendar.
119
- clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . events . length ;
128
+ clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
120
129
expect ( clientEventsLength ) . toEqual ( 3 ) ;
121
130
} ) ;
131
+ /* Test to make sure header options can be overwritten */
132
+ it ( 'should overwrite default header options' , function ( ) {
133
+ spyOn ( $ . fn , 'fullCalendar' ) ;
134
+ scope . uiConfig2 = {
135
+ calendar :{
136
+ header : { center : 'title' }
137
+ }
138
+ } ;
139
+ $compile ( '<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
140
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . hasOwnProperty ( 'header' ) ) . toEqual ( true ) ;
141
+ var header = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . header ;
142
+ expect ( header ) . toEqual ( { center : 'title' } ) ;
143
+ } ) ;
144
+ /* Test to see if calendar is watching all eventSources for changes. */
145
+ it ( 'should update the calendar if any eventSource array contains a delta' , function ( ) {
146
+ spyOn ( $ . fn , 'fullCalendar' ) ;
147
+ $compile ( '<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
148
+ var clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
149
+ var clientEventsLength2 = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 1 ] . length ;
150
+ expect ( clientEventsLength ) . toEqual ( 4 ) ;
151
+ expect ( clientEventsLength2 ) . toEqual ( 4 ) ;
152
+ //remove an event from the scope.
153
+ scope . remove ( scope . events2 , 0 ) ;
154
+ //events should auto update inside the calendar.
155
+ clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
156
+ clientEventsLength2 = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 1 ] . length ;
157
+ expect ( clientEventsLength ) . toEqual ( 4 ) ;
158
+ expect ( clientEventsLength2 ) . toEqual ( 3 ) ;
159
+ scope . remove ( scope . events , 0 ) ;
160
+ clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
161
+ expect ( clientEventsLength ) . toEqual ( 3 ) ;
162
+ } ) ;
163
+ /* Test to see if calendar is updating when a new eventSource is added. */
164
+ it ( 'should update the calendar if an eventSource is Added' , function ( ) {
165
+ spyOn ( $ . fn , 'fullCalendar' ) ;
166
+ $compile ( '<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
167
+ var clientEventSources = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources . length ;
168
+ expect ( clientEventSources ) . toEqual ( 2 ) ;
169
+ //add new source to calendar
170
+ scope . addSource ( scope . events3 ) ;
171
+ //eventSources should auto update inside the calendar.
172
+ clientEventSources = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources . length ;
173
+ expect ( clientEventSources ) . toEqual ( 3 ) ;
174
+ //go ahead and add some more events to the array and check those too.
175
+ scope . addChild ( scope . events3 ) ;
176
+ var clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 2 ] . length ;
177
+ expect ( clientEventsLength ) . toEqual ( 2 ) ;
178
+ } ) ;
122
179
123
180
} ) ;
124
181
125
- } ) ;
182
+ } ) ;
0 commit comments