Debian Codegraph @

extensions/MultimediaViewer/tests/qunit/mmv/ui/mmv.ui.permission.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 { Permission } = require( 'mmv' );
19
20 ( function () {
21 QUnit.module( 'Permission', QUnit.newMwEnvironment( {
22 beforeEach: function () {
23 // animation would keep running, conflict with other tests
24 this.sandbox.stub( $.fn, 'animate' ).returnsThis();
25 }
26 } ) );
27
28 QUnit.test( 'Constructor sense check', ( assert ) => {
29 const $qf = $( '#qunit-fixture' );
30 const permission = new Permission( $qf );
31
32 assert.true( permission instanceof Permission, 'constructor does not throw error' );
33 } );
34
35 QUnit.test( 'set()', ( assert ) => {
36 const $qf = $( '#qunit-fixture' );
37 const permission = new Permission( $qf );
38 const text = 'Nothing to see here.';
39
40 permission.set( text );
41
42 // FIXME get rid of "view more" - this is temporary
43 assert.strictEqual( permission.$text.children().remove().end().text(),
44 text, 'permission text is set' );
45 assert.strictEqual( permission.$html.text(), text, 'permission html is set' );
46 assert.strictEqual( permission.$text.is( ':visible' ), true, 'permission text is visible' );
47 assert.strictEqual( permission.$html.is( ':visible' ), false, 'permission html is not visible' );
48 assert.strictEqual( permission.$close.is( ':visible' ), false, 'close button is not visible' );
49 } );
50
51 QUnit.test( 'set() with html', ( assert ) => {
52 const $qf = $( '#qunit-fixture' );
53 const permission = new Permission( $qf );
54 const text = '<b>Nothing</b> to see here.';
55
56 permission.set( text );
57
58 assert.strictEqual( permission.$text.find( 'b' ).length, 0, 'permission text has no html' );
59 assert.strictEqual( permission.$html.find( 'b' ).length, 1, 'permission html has html' );
60 } );
61
62 QUnit.test( 'empty()', ( assert ) => {
63 const $qf = $( '#qunit-fixture' );
64 const permission = new Permission( $qf );
65 const text = 'Nothing to see here.';
66
67 permission.set( text );
68 permission.empty();
69
70 assert.strictEqual( permission.$text.is( ':visible' ), false, 'permission text is not visible' );
71 assert.strictEqual( permission.$html.is( ':visible' ), false, 'permission html is not visible' );
72 assert.strictEqual( permission.$close.is( ':visible' ), false, 'close button is not visible' );
73 } );
74
75 QUnit.test( 'grow()', ( assert ) => {
76 const $qf = $( '#qunit-fixture' );
77 const permission = new Permission( $qf );
78 const text = 'Nothing to see here.';
79
80 permission.set( text );
81 permission.grow();
82
83 assert.strictEqual( permission.$text.is( ':visible' ), false, 'permission text is not visible' );
84 assert.strictEqual( permission.$html.is( ':visible' ), true, 'permission html is visible' );
85 assert.strictEqual( permission.$close.is( ':visible' ), true, 'close button is visible' );
86 } );
87
88 QUnit.test( 'shrink()', ( assert ) => {
89 const $qf = $( '#qunit-fixture' );
90 const permission = new Permission( $qf );
91 const text = 'Nothing to see here.';
92
93 permission.set( text );
94 permission.grow();
95 permission.shrink();
96
97 assert.strictEqual( permission.$text.is( ':visible' ), true, 'permission text is visible' );
98 assert.strictEqual( permission.$html.is( ':visible' ), false, 'permission html is not visible' );
99 assert.strictEqual( permission.$close.is( ':visible' ), false, 'close button is not visible' );
100 } );
101
102 QUnit.test( 'isFullSize()', ( assert ) => {
103 const $qf = $( '#qunit-fixture' );
104 const permission = new Permission( $qf );
105 const text = 'Nothing to see here.';
106
107 permission.set( text );
108 assert.strictEqual( permission.isFullSize(), false, 'permission is not full-size' );
109 permission.grow();
110 assert.strictEqual( permission.isFullSize(), true, 'permission is full-size' );
111 permission.shrink();
112 assert.strictEqual( permission.isFullSize(), false, 'permission is not full-size again' );
113 } );
114 }() );