ccbf5757b5c0b34e5166d10df8bb7578caec0fa8
[ccsdk/features.git] /
1 /**
2  * Copyright 2010-2013 Ben Birch
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this software except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 describe("app.services.ClusterState", function() {
17
18         var ClusterState = window.app.services.ClusterState;
19         var test = window.test;
20
21         var c;
22         var dummyData = {};
23         var dataEventCallback;
24
25         function expectAllDataToBeNull() {
26                 expect( c.clusterState ).toBe( null );
27                 expect( c.status ).toBe( null );
28                 expect( c.nodeStats ).toBe( null );
29                 expect( c.clusterNodes ).toBe( null );
30         }
31
32         beforeEach( function() {
33                 test.cb.use();
34                 dataEventCallback = jasmine.createSpy("onData");
35                 c = new ClusterState({
36                         cluster: {
37                                 get: test.cb.createSpy("get", 1, [ dummyData ] )
38                         },
39                         onData: dataEventCallback
40                 });
41         });
42
43         describe( "when it is initialised", function() {
44
45                 it("should have null data", function() {
46                         expectAllDataToBeNull();
47                 });
48
49         });
50
51         describe( "when refresh is called", function() {
52
53                 beforeEach( function() {
54                         c.refresh();
55                 });
56
57                 it("should not not update models until all network requests have completed", function() {                       
58                         test.cb.execOne();
59                         expectAllDataToBeNull();
60                         test.cb.execOne();
61                         expectAllDataToBeNull();
62                         test.cb.execOne();
63                         expectAllDataToBeNull();
64                         test.cb.execOne();
65                         expectAllDataToBeNull();
66                         test.cb.execOne();
67                         expect( c.clusterState ).toBe( dummyData );
68                         expect( c.status ).toBe( dummyData );
69                         expect( c.nodeStats ).toBe( dummyData );
70                         expect( c.clusterNodes ).toBe( dummyData );
71                 });
72
73                 it("should fire a 'data' event when all data is ready", function() {
74                         test.cb.execAll();
75                         expect( dataEventCallback ).toHaveBeenCalledWith( c );
76                 });
77         });
78
79 });