Debian Codegraph @

extensions/MultimediaViewer/tests/qunit/mmv/ui/mmv.ui.progressBar.test.js

raw symbols SCIP
1 /*
2 * This file is part of the MediaWiki extension MediaViewer.
3 *
4 * MediaViewer is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * MediaViewer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
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 // Disable transition, as it messes with qunit test
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 // Disable transition, as it messes with qunit test
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 }() );