Make progress bar qunit tests more robust

Bug: T93540
Change-Id: Id46d3ffd4e9f89a834162b595e36a26e1186c0a5
This commit is contained in:
Gilles Dubuc 2015-03-24 12:12:47 +01:00
parent 86a23beffa
commit a45f7b48f0

View file

@ -26,7 +26,8 @@
QUnit.test( 'animateTo()', 8, function ( assert ) { QUnit.test( 'animateTo()', 8, function ( assert ) {
var $qf = $( '#qunit-fixture' ), var $qf = $( '#qunit-fixture' ),
progress = new mw.mmv.ui.ProgressBar( $qf ); $div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf ),
progress = new mw.mmv.ui.ProgressBar( $div );
assert.ok( progress.$progress.hasClass( 'empty' ), 'Progress bar is hidden' ); assert.ok( progress.$progress.hasClass( 'empty' ), 'Progress bar is hidden' );
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' ); assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' );
@ -37,7 +38,8 @@
} ); } );
progress.animateTo( 50 ); progress.animateTo( 50 );
assert.ok( !progress.$progress.hasClass( 'empty' ), 'Progress bar is visible' ); assert.ok( !progress.$progress.hasClass( 'empty' ), 'Progress bar is visible' );
assert.strictEqual( progress.$percent.width(), $qf.width() / 2, 'Progress bar\'s indicator is at half' );
assert.strictEqual( progress.$percent.width(), 125, 'Progress bar\'s indicator is at half' );
$.fn.animate.restore(); $.fn.animate.restore();
this.sandbox.stub( $.fn, 'animate', function ( target, duration, transition, callback ) { this.sandbox.stub( $.fn, 'animate', function ( target, duration, transition, callback ) {
@ -56,7 +58,8 @@
QUnit.test( 'jumpTo()/hide()', 6, function ( assert ) { QUnit.test( 'jumpTo()/hide()', 6, function ( assert ) {
var $qf = $( '#qunit-fixture' ), var $qf = $( '#qunit-fixture' ),
progress = new mw.mmv.ui.ProgressBar( $qf ); $div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf ),
progress = new mw.mmv.ui.ProgressBar( $div );
assert.ok( progress.$progress.hasClass( 'empty' ), 'Progress bar is hidden' ); assert.ok( progress.$progress.hasClass( 'empty' ), 'Progress bar is hidden' );
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' ); assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' );
@ -64,7 +67,7 @@
progress.jumpTo( 50 ); progress.jumpTo( 50 );
assert.ok( !progress.$progress.hasClass( 'empty' ), 'Progress bar is visible' ); assert.ok( !progress.$progress.hasClass( 'empty' ), 'Progress bar is visible' );
assert.strictEqual( progress.$percent.width(), $qf.width() / 2, 'Progress bar\'s indicator is at half' ); assert.strictEqual( progress.$percent.width(), 125, 'Progress bar\'s indicator is at half' );
progress.hide(); progress.hide();