Debian Codegraph @

extensions/MultimediaViewer/tests/qunit/mmv/ui/mmv.ui.truncatableTextField.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 { TruncatableTextField } = require( 'mmv' );
19
20 ( function () {
21 QUnit.module( 'mmv.ui.TruncatableTextField', QUnit.newMwEnvironment() );
22
23 /**
24 * Create a textfield that can contain exactly width x height characters
25 *
26 * @param {number} width
27 * @param {number} height
28 * @param {jQuery} $qf fixture element
29 * @param {Object} sandbox sinon instance
30 * @return {TruncatableTextField}
31 */
32 function getField( width, height, $qf ) {
33 const $container = $( '<div>' ).appendTo( $qf );
34 const $element = $( '<span>' );
35 const ttf = new TruncatableTextField( $container, $element, {} );
36
37 $container.css( {
38 fontFamily: 'monospace',
39 lineHeight: 1,
40 width: width + 'ch',
41 height: height + 'em'
42 } );
43
44 return ttf;
45 }
46
47 QUnit.test( 'Normal constructor', ( assert ) => {
48 const $container = $( '#qunit-fixture' );
49 const $element = $( '<div>' ).appendTo( $container ).text( 'This is a unique string.' );
50 const ttf = new TruncatableTextField( $container, $element );
51
52 assert.strictEqual( ttf.$element.text(), 'This is a unique string.', 'The constructor set the element to the right thing.' );
53 assert.strictEqual( ttf.$element.closest( '#qunit-fixture' ).length, 1, 'The constructor put the element into the container.' );
54 } );
55
56 QUnit.test( 'Set method', function ( assert ) {
57 const $qf = $( '#qunit-fixture' );
58 const ttf = getField( 3, 2, $qf );
59
60 ttf.shrink = this.sandbox.stub();
61 ttf.set( 'abc' );
62 assert.strictEqual( ttf.$element.text(), 'abc', 'Text is set accurately.' );
63 } );
64 }() );