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.ui.RefreshButton", function() {
18 var RefreshButton = window.app.ui.RefreshButton;
20 var r, refresh_handler, change_handler;
22 function openMenuPanel( button, label ) {
23 button.el.find("BUTTON").eq(1).click();
24 $(".uiMenuPanel-label:contains(" + label + ")").click();
25 test.clock.tick(); // menuPanel -> bind _close_handler
29 beforeEach( function() {
31 refresh_handler = jasmine.createSpy("refresh_handler");
32 change_handler = jasmine.createSpy("change_handler");
33 r = new RefreshButton({
34 onRefresh: refresh_handler,
35 onChange: change_handler
37 r.attach( document.body );
40 afterEach( function() {
45 it("should have an initial default value", function() {
46 expect( r.value ).toBe( -1 );
49 it("should fire a refresh event after clicking the refresh button ", function() {
50 r.el.find("BUTTON").eq(0).click();
52 expect( refresh_handler ).toHaveBeenCalled();
55 it("should change the refresh rate when set it called", function() {
57 expect( r.value ).toBe( 100 );
60 it("should set an interval when rate is set to a positive value", function() {
63 expect( refresh_handler.calls.count() ).toBe( 1 );
66 it("should not set an interval when rate is set to a non positive value", function() {
69 expect( refresh_handler.calls.count() ).toBe( 0 );
72 it("should fire a refresh event on intervals if refresh menu item is set to quickly", function() {
73 openMenuPanel( r, "quickly" );
75 expect( refresh_handler.calls.count() ).toBe( 0 );
77 expect( refresh_handler.calls.count() ).toBe( 1 );
79 expect( refresh_handler.calls.count() ).toBe( 2 );
82 it("should not fire refresh events when user selects Manual", function() {
84 openMenuPanel( r, "quickly" );
86 expect( refresh_handler.calls.count() ).toBe( 0 );
88 expect( refresh_handler.calls.count() ).toBe( 1 );
90 openMenuPanel( r, "Manual" );
93 expect( refresh_handler.calls.count() ).toBe( 1 );
95 expect( refresh_handler.calls.count() ).toBe( 1 );
98 it("should fire a change event when a new refresh rate is selected", function() {
99 openMenuPanel( r, "quickly" );
100 expect( change_handler.calls.count() ).toBe( 1 );
101 expect( r.value ).toBe( 100 );
102 openMenuPanel( r, "Manual" );
103 expect( change_handler.calls.count() ).toBe( 2 );
104 expect( r.value ).toBe( -1 );