Progressbar: Shift to use no globals

This commit is contained in:
Amanpreet Singh 2016-04-06 18:38:28 +05:30
parent 059b5b17a1
commit b7b53d2163
5 changed files with 85 additions and 81 deletions

View File

@ -14,7 +14,7 @@ common.testWidget( "progressbar", {
max: 100,
value: 0,
//callbacks
//Callbacks
change: null,
complete: null,
create: null

View File

@ -1,12 +1,13 @@
define( [
"qunit",
"jquery",
"ui/widgets/progressbar"
], function( $ ) {
], function( QUnit, $ ) {
module( "progressbar: core" );
QUnit.module( "progressbar: core" );
test( "markup structure", function( assert ) {
expect( 7 );
QUnit.test( "markup structure", function( assert ) {
assert.expect( 7 );
var element = $( "#progressbar" ).progressbar(),
value = element.children().eq( 0 );
@ -14,51 +15,51 @@ test( "markup structure", function( assert ) {
assert.hasClasses( value, "ui-progressbar-value ui-widget-header" );
assert.lacksClasses( value, "ui-progressbar-complete" );
assert.lacksClasses( element, "ui-progressbar-indeterminate" );
equal( element.children().length, 1, "Main element contains one child" );
assert.equal( element.children().length, 1, "Main element contains one child" );
element.progressbar( "option", "value", 100 );
assert.hasClasses( value, "ui-progressbar-complete ui-widget-header ui-progressbar-value" );
equal( element.children().children().length, 0, "no overlay div" );
assert.equal( element.children().children().length, 0, "no overlay div" );
} );
test( "markup structure - indeterminate", function( assert ) {
expect( 5 );
QUnit.test( "markup structure - indeterminate", function( assert ) {
assert.expect( 5 );
var element = $( "#progressbar" ).progressbar( { value: false } ),
children = element.children();
assert.hasClasses( element, "ui-progressbar ui-progressbar-indeterminate ui-widget ui-widget-content" );
assert.hasClasses( children[ 0 ], "ui-progressbar-value ui-widget-header" );
equal( children.length, 1, "Main element contains one child" );
assert.equal( children.length, 1, "Main element contains one child" );
assert.hasClasses( children[ 0 ], "ui-progressbar-value" );
equal( children.children( ".ui-progressbar-overlay" ).length, 1,
assert.equal( children.children( ".ui-progressbar-overlay" ).length, 1,
"Value has class ui-progressbar-overlay" );
} );
test( "accessibility", function() {
expect( 11 );
QUnit.test( "accessibility", function( assert ) {
assert.expect( 11 );
var element = $( "#progressbar" ).progressbar();
equal( element.attr( "role" ), "progressbar", "aria role" );
equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" );
equal( element.attr( "aria-valuemax" ), 100, "aria-valuemax" );
equal( element.attr( "aria-valuenow" ), 0, "aria-valuenow initially" );
assert.equal( element.attr( "role" ), "progressbar", "aria role" );
assert.equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" );
assert.equal( element.attr( "aria-valuemax" ), 100, "aria-valuemax" );
assert.equal( element.attr( "aria-valuenow" ), 0, "aria-valuenow initially" );
element.progressbar( "value", 77 );
equal( element.attr( "aria-valuenow" ), 77, "aria-valuenow" );
assert.equal( element.attr( "aria-valuenow" ), 77, "aria-valuenow" );
element.progressbar( "option", "max", 150 );
equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" );
assert.equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" );
element.progressbar( "disable" );
equal( element.attr( "aria-disabled" ), "true", "aria-disabled on" );
assert.equal( element.attr( "aria-disabled" ), "true", "aria-disabled on" );
element.progressbar( "enable" );
equal( element.attr( "aria-disabled" ), "false", "aria-disabled off" );
assert.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" );
equal( element.attr( "aria-valuenow" ), null, "aria-valuenow" );
assert.equal( element.attr( "aria-valuemin" ), 0, "aria-valuemin" );
assert.equal( element.attr( "aria-valuemax" ), 150, "aria-valuemax" );
assert.equal( element.attr( "aria-valuenow" ), null, "aria-valuenow" );
} );
} );

View File

@ -1,49 +1,50 @@
define( [
"qunit",
"jquery",
"ui/widgets/progressbar"
], function( $ ) {
], function( QUnit, $ ) {
module( "progressbar: events" );
QUnit.module( "progressbar: events" );
test( "create", function() {
expect( 1 );
QUnit.test( "create", function( assert ) {
assert.expect( 1 );
$( "#progressbar" ).progressbar( {
value: 5,
create: function() {
equal( $( this ).progressbar( "value" ), 5, "Correct value at create" );
assert.equal( $( this ).progressbar( "value" ), 5, "Correct value at create" );
},
change: function() {
ok( false, "create has triggered change()" );
assert.ok( false, "create has triggered change()" );
}
} );
} );
test( "change", function() {
expect( 2 );
QUnit.test( "change", function( assert ) {
assert.expect( 2 );
var element = $( "#progressbar" ).progressbar();
element.one( "progressbarchange", function() {
equal( element.progressbar( "value" ), 5, "change triggered for middle value" );
assert.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" );
assert.equal( element.progressbar( "value" ), 100, "change triggered for final value" );
} );
element.progressbar( "value", 100 );
} );
test( "complete", function() {
expect( 5 );
QUnit.test( "complete", function( assert ) {
assert.expect( 5 );
var value,
changes = 0,
element = $( "#progressbar" ).progressbar( {
change: function() {
changes++;
equal( element.progressbar( "value" ), value, "change at " + value );
assert.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" );
assert.equal( changes, 3, "complete triggered after change and not on indeterminate" );
assert.equal( element.progressbar( "value" ), 100, "value is 100" );
}
} );

View File

@ -1,42 +1,43 @@
define( [
"qunit",
"jquery",
"ui/widgets/progressbar"
], function( $ ) {
], function( QUnit, $ ) {
module( "progressbar: methods" );
QUnit.module( "progressbar: methods" );
test( "destroy", function( assert ) {
expect( 1 );
QUnit.test( "destroy", function( assert ) {
assert.expect( 1 );
assert.domEqual( "#progressbar", function() {
$( "#progressbar" ).progressbar().progressbar( "destroy" );
} );
} );
test( "disable", function( assert ) {
expect( 3 );
QUnit.test( "disable", function( assert ) {
assert.expect( 3 );
var element = $( "#progressbar" ).progressbar().progressbar( "disable" );
assert.hasClasses( element.progressbar( "widget" ), "ui-state-disabled" );
ok( element.progressbar( "widget" ).attr( "aria-disabled" ), "element gets aria-disabled" );
assert.ok( element.progressbar( "widget" ).attr( "aria-disabled" ), "element gets aria-disabled" );
assert.hasClasses( element.progressbar( "widget" ), "ui-progressbar-disabled" );
} );
test( "value", function() {
expect( 3 );
QUnit.test( "value", function( assert ) {
assert.expect( 3 );
var element = $( "<div>" ).progressbar( { value: 20 } );
equal( element.progressbar( "value" ), 20, "correct value as getter" );
strictEqual( element.progressbar( "value", 30 ), element, "chainable as setter" );
equal( element.progressbar( "option", "value" ), 30, "correct value after setter" );
assert.equal( element.progressbar( "value" ), 20, "correct value as getter" );
assert.strictEqual( element.progressbar( "value", 30 ), element, "chainable as setter" );
assert.equal( element.progressbar( "option", "value" ), 30, "correct value after setter" );
} );
test( "widget", function() {
expect( 2 );
QUnit.test( "widget", function( assert ) {
assert.expect( 2 );
var element = $( "#progressbar" ).progressbar(),
widgetElement = element.progressbar( "widget" );
equal( widgetElement.length, 1, "one element" );
strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
assert.equal( widgetElement.length, 1, "one element" );
assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
} );
} );

View File

@ -1,78 +1,79 @@
define( [
"qunit",
"jquery",
"ui/widgets/progressbar"
], function( $ ) {
], function( QUnit, $ ) {
module( "progressbar: options" );
QUnit.module( "progressbar: options" );
test( "{ value: 0 }, default", function() {
expect( 1 );
QUnit.test( "{ value: 0 }, default", function( assert ) {
assert.expect( 1 );
$( "#progressbar" ).progressbar();
equal( $( "#progressbar" ).progressbar( "value" ), 0 );
assert.equal( $( "#progressbar" ).progressbar( "value" ), 0 );
} );
// Ticket #7231 - valueDiv should be hidden when value is at 0%
test( "value: visibility of valueDiv", function() {
expect( 4 );
QUnit.test( "value: visibility of valueDiv", function( assert ) {
assert.expect( 4 );
var element = $( "#progressbar" ).progressbar( {
value: 0
} );
ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ),
assert.ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ),
"valueDiv hidden when value is initialized at 0" );
element.progressbar( "value", 1 );
ok( element.children( ".ui-progressbar-value" ).is( ":visible" ),
assert.ok( element.children( ".ui-progressbar-value" ).is( ":visible" ),
"valueDiv visible when value is set to 1" );
element.progressbar( "value", 100 );
ok( element.children( ".ui-progressbar-value" ).is( ":visible" ),
assert.ok( element.children( ".ui-progressbar-value" ).is( ":visible" ),
"valueDiv visible when value is set to 100" );
element.progressbar( "value", 0 );
ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ),
assert.ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ),
"valueDiv hidden when value is set to 0" );
} );
test( "{ value: 5 }", function() {
expect( 1 );
QUnit.test( "{ value: 5 }", function( assert ) {
assert.expect( 1 );
$( "#progressbar" ).progressbar( {
value: 5
} );
equal( $( "#progressbar" ).progressbar( "value" ), 5 );
assert.equal( $( "#progressbar" ).progressbar( "value" ), 5 );
} );
test( "{ value: -5 }", function() {
expect( 1 );
QUnit.test( "{ value: -5 }", function( assert ) {
assert.expect( 1 );
$( "#progressbar" ).progressbar( {
value: -5
} );
equal( $( "#progressbar" ).progressbar( "value" ), 0,
assert.equal( $( "#progressbar" ).progressbar( "value" ), 0,
"value constrained at min" );
} );
test( "{ value: 105 }", function() {
expect( 1 );
QUnit.test( "{ value: 105 }", function( assert ) {
assert.expect( 1 );
$( "#progressbar" ).progressbar( {
value: 105
} );
equal( $( "#progressbar" ).progressbar( "value" ), 100,
assert.equal( $( "#progressbar" ).progressbar( "value" ), 100,
"value constrained at max" );
} );
test( "{ value: 10, max: 5 }", function() {
expect( 1 );
QUnit.test( "{ value: 10, max: 5 }", function( assert ) {
assert.expect( 1 );
$( "#progressbar" ).progressbar( {
max: 5,
value: 10
} );
equal( $( "#progressbar" ).progressbar( "value" ), 5,
assert.equal( $( "#progressbar" ).progressbar( "value" ), 5,
"value constrained at max" );
} );
test( "change max below value", function() {
expect( 1 );
QUnit.test( "change max below value", function( assert ) {
assert.expect( 1 );
$( "#progressbar" ).progressbar( {
max: 10,
value: 10
} ).progressbar( "option", "max", 5 );
equal( $( "#progressbar" ).progressbar( "value" ), 5,
assert.equal( $( "#progressbar" ).progressbar( "value" ), 5,
"value constrained at max" );
} );