From 8c763cdf9836e9e97432167e92d0a5808e033ba2 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 09:21:25 -0500 Subject: Progressbar: Define defaults for callbacks. --- tests/unit/progressbar/progressbar_common.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/unit/progressbar') diff --git a/tests/unit/progressbar/progressbar_common.js b/tests/unit/progressbar/progressbar_common.js index 2f97a78bb..ceee3fbec 100644 --- a/tests/unit/progressbar/progressbar_common.js +++ b/tests/unit/progressbar/progressbar_common.js @@ -5,6 +5,8 @@ TestHelpers.commonWidgetTests( "progressbar", { max: 100, //callbacks + change: null, + complete: null, create: null } }); -- cgit v1.2.3 From f1be88e7956fe9114ae20d19242cd8190a6ff399 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 09:35:41 -0500 Subject: Progressbar: Only remove aria-valuenow for indeterminate progressbars. Added more accessibility tests. --- tests/unit/progressbar/progressbar_common.js | 2 +- tests/unit/progressbar/progressbar_core.js | 10 +++++++++- ui/jquery.ui.progressbar.js | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'tests/unit/progressbar') diff --git a/tests/unit/progressbar/progressbar_common.js b/tests/unit/progressbar/progressbar_common.js index ceee3fbec..0768576f5 100644 --- a/tests/unit/progressbar/progressbar_common.js +++ b/tests/unit/progressbar/progressbar_common.js @@ -1,8 +1,8 @@ TestHelpers.commonWidgetTests( "progressbar", { defaults: { disabled: false, - value: 0, max: 100, + value: 0, //callbacks change: null, diff --git a/tests/unit/progressbar/progressbar_core.js b/tests/unit/progressbar/progressbar_core.js index 0a2ef895b..54a33cc9d 100644 --- a/tests/unit/progressbar/progressbar_core.js +++ b/tests/unit/progressbar/progressbar_core.js @@ -1,7 +1,7 @@ module( "progressbar: core" ); test( "accessibility", function() { - expect( 7 ); + expect( 11 ); var element = $( "#progressbar" ).progressbar(); equal( element.attr( "role" ), "progressbar", "aria role" ); @@ -12,9 +12,17 @@ test( "accessibility", function() { element.progressbar( "value", 77 ); equal( element.attr( "aria-valuenow" ), 77, "aria-valuenow" ); + element.progressbar( "option", "max", 150 ); + equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" ); + element.progressbar( "disable" ); equal( element.attr( "aria-disabled" ), "true", "aria-disabled on" ); element.progressbar( "enable" ); equal( element.attr( "aria-disabled" ), "false", "aria-disabled off" ); + + element.progressbar( "option", "value", false ); + equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" ); + equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" ); + strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow initially" ); }); diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 53c9508ed..348f1d061 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -33,10 +33,10 @@ $.widget( "ui.progressbar", { this.element .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) .attr({ + // Only set static values, aria-valuenow and aria-valuemax are + // set inside _refreshValue() role: "progressbar", - "aria-valuemin": this.min, - "aria-valuemax": this.options.max, - "aria-valuenow": this.options.value + "aria-valuemin": this.min }); this.valueDiv = $( "
" ) @@ -126,7 +126,7 @@ $.widget( "ui.progressbar", { .width( percentage.toFixed(0) + "%" ); if ( this.indeterminate ) { - this.element.removeAttr( "aria-valuemax" ).removeAttr( "aria-valuenow" ); + this.element.removeAttr( "aria-valuenow" ); if ( !this.overlayDiv ) { this.overlayDiv = $( "
" ).appendTo( this.valueDiv ); } -- cgit v1.2.3 From 9d0df536240f1b5e84d1f772ef95117280acd4d8 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 09:50:33 -0500 Subject: Progress tests: Cleanup. --- tests/unit/progressbar/progressbar_events.js | 26 ++++++++++------- tests/unit/progressbar/progressbar_methods.js | 2 +- tests/unit/progressbar/progressbar_options.js | 42 +++++++++++---------------- 3 files changed, 34 insertions(+), 36 deletions(-) (limited to 'tests/unit/progressbar') diff --git a/tests/unit/progressbar/progressbar_events.js b/tests/unit/progressbar/progressbar_events.js index fe05182a1..95effda75 100644 --- a/tests/unit/progressbar/progressbar_events.js +++ b/tests/unit/progressbar/progressbar_events.js @@ -5,34 +5,40 @@ test( "create", function() { $( "#progressbar" ).progressbar({ value: 5, create: function() { - deepEqual( 5, $( this ).progressbar( "value" ) ); + equal( $( this ).progressbar( "value" ), 5, "Correct value at create" ); }, change: function() { - ok( false, "create() has triggered change()" ); + ok( false, "create has triggered change()" ); } }); }); test( "change", function() { - expect( 1 ); - $( "#progressbar" ).progressbar({ - change: function() { - deepEqual( 5, $( this ).progressbar( "value" ) ); - } - }).progressbar( "value", 5 ); + expect( 2 ); + var element = $( "#progressbar" ).progressbar(); + + element.one( "progressbarchange", function() { + equal( element.progressbar( "value" ), 5, "change triggered for middle value" ); + }); + element.progressbar( "value", 5 ); + element.one( "progressbarchange", function() { + equal( element.progressbar( "value" ), 100, "change triggered for final value" ); + }); + element.progressbar( "value", 100 ); }); test( "complete", function() { - expect( 4 ); + expect( 5 ); var value, changes = 0, element = $( "#progressbar" ).progressbar({ change: function() { changes++; - deepEqual( element.progressbar( "value" ), value, "change at " + value ); + equal( element.progressbar( "value" ), value, "change at " + value ); }, complete: function() { equal( changes, 3, "complete triggered after change and not on indeterminate" ); + equal( element.progressbar( "value" ), 100, "value is 100" ); } }); diff --git a/tests/unit/progressbar/progressbar_methods.js b/tests/unit/progressbar/progressbar_methods.js index 990739c6e..cf7faf6af 100644 --- a/tests/unit/progressbar/progressbar_methods.js +++ b/tests/unit/progressbar/progressbar_methods.js @@ -12,7 +12,7 @@ test( "value", function() { var element = $( "
" ).progressbar({ value: 20 }); equal( element.progressbar( "value" ), 20, "correct value as getter" ); - equal( element.progressbar( "value", 30), element, "chainable as setter" ); + strictEqual( element.progressbar( "value", 30 ), element, "chainable as setter" ); equal( element.progressbar( "option", "value" ), 30, "correct value after setter" ); }); diff --git a/tests/unit/progressbar/progressbar_options.js b/tests/unit/progressbar/progressbar_options.js index e4d9b7ab8..bc0b5d00d 100644 --- a/tests/unit/progressbar/progressbar_options.js +++ b/tests/unit/progressbar/progressbar_options.js @@ -1,14 +1,14 @@ module( "progressbar: options" ); -test( "{ value : 0 }, default", function() { +test( "{ value: 0 }, default", function() { expect( 1 ); $( "#progressbar" ).progressbar(); - equal( 0, $( "#progressbar" ).progressbar( "value" ) ); + equal( $( "#progressbar" ).progressbar( "value" ), 0 ); }); // Ticket #7231 - valueDiv should be hidden when value is at 0% test( "value: visibility of valueDiv", function() { - expect( 5 ); + expect( 4 ); var element = $( "#progressbar" ).progressbar({ value: 0 }); @@ -23,58 +23,50 @@ test( "value: visibility of valueDiv", function() { element.progressbar( "value", 0 ); ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ), "valueDiv hidden when value is set to 0" ); - element.progressbar( "value", -1 ); - ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ), - "valueDiv hidden when value set to -1 (normalizes to 0)" ); }); -test( "{ value : 5 }", function() { +test( "{ value: 5 }", function() { expect( 1 ); $( "#progressbar" ).progressbar({ value: 5 }); - equal( 5, $( "#progressbar" ).progressbar( "value" ) ); + equal( $( "#progressbar" ).progressbar( "value" ), 5 ); }); -test( "{ value : -5 }", function() { +test( "{ value: -5 }", function() { expect( 1 ); $( "#progressbar" ).progressbar({ value: -5 }); - deepEqual( 0, $( "#progressbar" ).progressbar( "value" ) ); + equal( $( "#progressbar" ).progressbar( "value" ), 0, + "value constrained at min" ); }); -test( "{ value : 105 }", function() { +test( "{ value: 105 }", function() { expect( 1 ); $( "#progressbar" ).progressbar({ value: 105 }); - deepEqual( 100, $( "#progressbar" ).progressbar( "value" ) ); -}); - -test( "{ max : 5, value : 10 }", function() { - expect( 1 ); - $("#progressbar").progressbar({ - max: 5, - value: 10 - }); - deepEqual( 5, $( "#progressbar" ).progressbar( "value" ) ); + equal( $( "#progressbar" ).progressbar( "value" ), 100, + "value constrained at max" ); }); -test( "{ value : 10, max : 5 }", function() { +test( "{ value: 10, max: 5 }", function() { expect( 1 ); $("#progressbar").progressbar({ max: 5, value: 10 }); - deepEqual( 5, $( "#progressbar" ).progressbar( "value" ) ); + equal( $( "#progressbar" ).progressbar( "value" ), 5, + "value constrained at max" ); }); -test( "{ max : 5 }", function() { +test( "change max below value", function() { expect( 1 ); $("#progressbar").progressbar({ max: 10, value: 10 }).progressbar( "option", "max", 5 ); - deepEqual( 5, $( "#progressbar" ).progressbar( "value" ) ); + equal( $( "#progressbar" ).progressbar( "value" ), 5, + "value constrained at max" ); }); -- cgit v1.2.3 From f7614706abfdbc653de53fbc31361f9aacab8821 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 6 Dec 2012 10:10:07 -0500 Subject: Progressbar: Cleanup, byte shaving. --- tests/unit/progressbar/progressbar_core.js | 2 +- ui/jquery.ui.progressbar.js | 42 ++++++++++++------------------ 2 files changed, 17 insertions(+), 27 deletions(-) (limited to 'tests/unit/progressbar') diff --git a/tests/unit/progressbar/progressbar_core.js b/tests/unit/progressbar/progressbar_core.js index 54a33cc9d..cffd84d21 100644 --- a/tests/unit/progressbar/progressbar_core.js +++ b/tests/unit/progressbar/progressbar_core.js @@ -24,5 +24,5 @@ test( "accessibility", function() { element.progressbar( "option", "value", false ); equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" ); equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" ); - strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow initially" ); + strictEqual( element.attr( "aria-valuenow" ), undefined, "aria-valuenow" ); }); diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index 348f1d061..46051d2c9 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -28,7 +28,7 @@ $.widget( "ui.progressbar", { _create: function() { // Constrain initial value - this.options.value = this._constrainedValue(); + this.oldValue = this.options.value = this._constrainedValue(); this.element .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) @@ -42,7 +42,6 @@ $.widget( "ui.progressbar", { this.valueDiv = $( "
" ) .appendTo( this.element ); - this.oldValue = this.options.value; this._refreshValue(); }, @@ -62,53 +61,44 @@ $.widget( "ui.progressbar", { return this.options.value; } - this._setOption( "value", this._constrainedValue( newValue ) ); - return this; + this.options.value = this._constrainedValue( newValue ); + this._refreshValue(); }, _constrainedValue: function( newValue ) { - var val; if ( newValue === undefined ) { - val = this.options.value; - } else { - val = newValue; + newValue = this.options.value; } - this.indeterminate = val === false; + this.indeterminate = newValue === false; // sanitize value - if ( typeof val !== "number" ) { - val = 0; + if ( typeof newValue !== "number" ) { + newValue = 0; } - return this.indeterminate ? false : Math.min( this.options.max, Math.max( this.min, val ) ); + + return this.indeterminate ? false : + Math.min( this.options.max, Math.max( this.min, newValue ) ); }, _setOptions: function( options ) { - var val = options.value; - // Ensure "value" option is set after other values (like max) + var value = options.value; delete options.value; + this._super( options ); - if ( val !== undefined ) { - this._setOption( "value", val ); - } + this.options.value = this._constrainedValue( value ); + this._refreshValue(); }, _setOption: function( key, value ) { if ( key === "max" ) { // Don't allow a max less than min - this.options.max = Math.max( this.min, value ); - this.options.value = this._constrainedValue(); - } - if ( key === "value" ) { - this.options.value = this._constrainedValue( value ); - } - else { - this._super( key, value ); + value = Math.max( this.min, value ); } - this._refreshValue(); + this._super( key, value ); }, _percentage: function() { -- cgit v1.2.3