1 describe("app.ui.RefreshButton", function() {
3 var RefreshButton = window.app.ui.RefreshButton;
5 var r, refresh_handler, change_handler;
7 function openMenuPanel( button, label ) {
8 button.el.find("BUTTON").eq(1).click();
9 $(".uiMenuPanel-label:contains(" + label + ")").click();
10 test.clock.tick(); // menuPanel -> bind _close_handler
14 beforeEach( function() {
16 refresh_handler = jasmine.createSpy("refresh_handler");
17 change_handler = jasmine.createSpy("change_handler");
18 r = new RefreshButton({
19 onRefresh: refresh_handler,
20 onChange: change_handler
22 r.attach( document.body );
25 afterEach( function() {
30 it("should have an initial default value", function() {
31 expect( r.value ).toBe( -1 );
34 it("should fire a refresh event after clicking the refresh button ", function() {
35 r.el.find("BUTTON").eq(0).click();
37 expect( refresh_handler ).toHaveBeenCalled();
40 it("should change the refresh rate when set it called", function() {
42 expect( r.value ).toBe( 100 );
45 it("should set an interval when rate is set to a positive value", function() {
48 expect( refresh_handler.calls.count() ).toBe( 1 );
51 it("should not set an interval when rate is set to a non positive value", function() {
54 expect( refresh_handler.calls.count() ).toBe( 0 );
57 it("should fire a refresh event on intervals if refresh menu item is set to quickly", function() {
58 openMenuPanel( r, "quickly" );
60 expect( refresh_handler.calls.count() ).toBe( 0 );
62 expect( refresh_handler.calls.count() ).toBe( 1 );
64 expect( refresh_handler.calls.count() ).toBe( 2 );
67 it("should not fire refresh events when user selects Manual", function() {
69 openMenuPanel( r, "quickly" );
71 expect( refresh_handler.calls.count() ).toBe( 0 );
73 expect( refresh_handler.calls.count() ).toBe( 1 );
75 openMenuPanel( r, "Manual" );
78 expect( refresh_handler.calls.count() ).toBe( 1 );
80 expect( refresh_handler.calls.count() ).toBe( 1 );
83 it("should fire a change event when a new refresh rate is selected", function() {
84 openMenuPanel( r, "quickly" );
85 expect( change_handler.calls.count() ).toBe( 1 );
86 expect( r.value ).toBe( 100 );
87 openMenuPanel( r, "Manual" );
88 expect( change_handler.calls.count() ).toBe( 2 );
89 expect( r.value ).toBe( -1 );