| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const { TruncatableTextField } = require( 'mmv' ); |
| 19 |
|
| 20 |
( function () { |
| 21 |
QUnit.module( 'mmv.ui.TruncatableTextField', QUnit.newMwEnvironment() ); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
}() ); |