b91237c6ec52b568e62ef65ad0e34fdc6f6e084c
[ccsdk/features.git] /
1 describe("app.services.ClusterState", function() {
2
3         var ClusterState = window.app.services.ClusterState;
4         var test = window.test;
5
6         var c;
7         var dummyData = {};
8         var dataEventCallback;
9
10         function expectAllDataToBeNull() {
11                 expect( c.clusterState ).toBe( null );
12                 expect( c.status ).toBe( null );
13                 expect( c.nodeStats ).toBe( null );
14                 expect( c.clusterNodes ).toBe( null );
15         }
16
17         beforeEach( function() {
18                 test.cb.use();
19                 dataEventCallback = jasmine.createSpy("onData");
20                 c = new ClusterState({
21                         cluster: {
22                                 get: test.cb.createSpy("get", 1, [ dummyData ] )
23                         },
24                         onData: dataEventCallback
25                 });
26         });
27
28         describe( "when it is initialised", function() {
29
30                 it("should have null data", function() {
31                         expectAllDataToBeNull();
32                 });
33
34         });
35
36         describe( "when refresh is called", function() {
37
38                 beforeEach( function() {
39                         c.refresh();
40                 });
41
42                 it("should not not update models until all network requests have completed", function() {                       
43                         test.cb.execOne();
44                         expectAllDataToBeNull();
45                         test.cb.execOne();
46                         expectAllDataToBeNull();
47                         test.cb.execOne();
48                         expectAllDataToBeNull();
49                         test.cb.execOne();
50                         expectAllDataToBeNull();
51                         test.cb.execOne();
52                         expect( c.clusterState ).toBe( dummyData );
53                         expect( c.status ).toBe( dummyData );
54                         expect( c.nodeStats ).toBe( dummyData );
55                         expect( c.clusterNodes ).toBe( dummyData );
56                 });
57
58                 it("should fire a 'data' event when all data is ready", function() {
59                         test.cb.execAll();
60                         expect( dataEventCallback ).toHaveBeenCalledWith( c );
61                 });
62         });
63
64 });