2 * Copyright 2010-2013 Ben Birch
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 describe("app.services.ClusterState", function() {
18 var ClusterState = window.app.services.ClusterState;
19 var test = window.test;
23 var dataEventCallback;
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 );
32 beforeEach( function() {
34 dataEventCallback = jasmine.createSpy("onData");
35 c = new ClusterState({
37 get: test.cb.createSpy("get", 1, [ dummyData ] )
39 onData: dataEventCallback
43 describe( "when it is initialised", function() {
45 it("should have null data", function() {
46 expectAllDataToBeNull();
51 describe( "when refresh is called", function() {
53 beforeEach( function() {
57 it("should not not update models until all network requests have completed", function() {
59 expectAllDataToBeNull();
61 expectAllDataToBeNull();
63 expectAllDataToBeNull();
65 expectAllDataToBeNull();
67 expect( c.clusterState ).toBe( dummyData );
68 expect( c.status ).toBe( dummyData );
69 expect( c.nodeStats ).toBe( dummyData );
70 expect( c.clusterNodes ).toBe( dummyData );
73 it("should fire a 'data' event when all data is ready", function() {
75 expect( dataEventCallback ).toHaveBeenCalledWith( c );