| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const { ProgressBar } = require( 'mmv' ); |
| 19 |
|
| 20 |
( function () { |
| 21 |
QUnit.module( 'mmv.ui.ProgressBar', QUnit.newMwEnvironment() ); |
| 22 |
|
| 23 |
QUnit.test( 'Constructor sense check', ( assert ) => { |
| 24 |
const progressBar = new ProgressBar( $( '<div>' ) ); |
| 25 |
assert.true( progressBar instanceof ProgressBar, 'ProgressBar created sccessfully' ); |
| 26 |
assert.strictEqual( progressBar.$progress.hasClass( 'empty' ), true, 'ProgressBar starts empty' ); |
| 27 |
} ); |
| 28 |
|
| 29 |
QUnit.test( 'animateTo()', ( assert ) => { |
| 30 |
const $qf = $( '#qunit-fixture' ); |
| 31 |
const $div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf ); |
| 32 |
const progress = new ProgressBar( $div ); |
| 33 |
|
| 34 |
assert.strictEqual( progress.$progress.width(), 250, 'Progress bar is 250 wide' ); |
| 35 |
assert.strictEqual( progress.$progress.hasClass( 'empty' ), true, 'Progress bar is hidden' ); |
| 36 |
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' ); |
| 37 |
|
| 38 |
|
| 39 |
progress.$percent.css( 'transition', 'unset' ); |
| 40 |
progress.animateTo( 50 ); |
| 41 |
|
| 42 |
assert.strictEqual( progress.$progress.hasClass( 'empty' ), false, 'Progress bar is visible' ); |
| 43 |
assert.strictEqual( progress.$percent.width(), 125, 'Progress bar\'s indicator is at half' ); |
| 44 |
|
| 45 |
progress.animateTo( 100 ); |
| 46 |
|
| 47 |
assert.strictEqual( progress.$progress.hasClass( 'empty' ), true, 'Progress bar is hidden' ); |
| 48 |
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is back to 0 and hidden' ); |
| 49 |
} ); |
| 50 |
|
| 51 |
QUnit.test( 'jumpTo()/hide()', ( assert ) => { |
| 52 |
const $qf = $( '#qunit-fixture' ); |
| 53 |
const $div = $( '<div>' ).css( { width: 250, position: 'relative' } ).appendTo( $qf ); |
| 54 |
const progress = new ProgressBar( $div ); |
| 55 |
assert.strictEqual( progress.$progress.width(), 250, 'progress bar should have width of 250px' ); |
| 56 |
|
| 57 |
|
| 58 |
progress.$percent.css( 'transition', 'unset' ); |
| 59 |
assert.strictEqual( progress.$progress.hasClass( 'empty' ), true, 'Progress bar is hidden' ); |
| 60 |
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' ); |
| 61 |
|
| 62 |
progress.jumpTo( 50 ); |
| 63 |
|
| 64 |
assert.strictEqual( progress.$progress.hasClass( 'empty' ), false, 'Progress bar is visible' ); |
| 65 |
assert.strictEqual( progress.$percent.width(), 125, 'Progress bar\'s indicator is at half' ); |
| 66 |
|
| 67 |
progress.hide(); |
| 68 |
|
| 69 |
assert.strictEqual( progress.$progress.hasClass( 'empty' ), true, 'Progress bar is hidden' ); |
| 70 |
assert.strictEqual( progress.$percent.width(), 0, 'Progress bar\'s indicator is at 0' ); |
| 71 |
} ); |
| 72 |
}() ); |