2014-01-22 01:21:22 +00:00
|
|
|
( function ( mw, $ ) {
|
2014-01-23 21:44:26 +00:00
|
|
|
QUnit.module( 'mmv.ui.description', QUnit.newMwEnvironment() );
|
2014-01-22 01:21:22 +00:00
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'Sanity test, object creation and UI construction', function ( assert ) {
|
2014-01-22 01:21:22 +00:00
|
|
|
var description = new mw.mmv.ui.Description( $( '#qunit-fixture' ) );
|
|
|
|
|
|
|
|
assert.ok( description, 'Image description UI element is created' );
|
|
|
|
assert.strictEqual( description.$imageDescDiv.length, 1, 'Image description div is created' );
|
|
|
|
assert.strictEqual( description.$imageDesc.length, 1, 'Image description element is created' );
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'Setting data in different combinations works well', function ( assert ) {
|
2014-01-22 01:21:22 +00:00
|
|
|
var description = new mw.mmv.ui.Description( $( '#qunit-fixture' ) );
|
|
|
|
|
2014-10-29 14:46:30 +00:00
|
|
|
description.set( null, null );
|
|
|
|
assert.ok( description.$imageDescDiv.hasClass( 'empty' ),
|
|
|
|
'Image description div is marked empty when neither description nor caption is available' );
|
2014-01-22 01:21:22 +00:00
|
|
|
|
2014-10-29 14:46:30 +00:00
|
|
|
description.set( null, 'foo' );
|
|
|
|
assert.ok( description.$imageDescDiv.hasClass( 'empty' ),
|
|
|
|
'Image description div is marked empty when there is no description' );
|
|
|
|
|
|
|
|
description.set( 'blah', null );
|
|
|
|
assert.ok( description.$imageDescDiv.hasClass( 'empty' ),
|
|
|
|
'Image description div is marked empty when there is no caption (description will be shown in title)' );
|
2014-01-22 01:21:22 +00:00
|
|
|
|
|
|
|
description.set( 'foo', 'bar' );
|
2014-10-29 14:46:30 +00:00
|
|
|
assert.ok( !description.$imageDescDiv.hasClass( 'empty' ),
|
|
|
|
'Image description div is not marked empty when both description and caption are available' );
|
|
|
|
assert.strictEqual( description.$imageDesc.text(), 'foo',
|
|
|
|
'Image description text is set correctly, caption is ignored' );
|
2014-01-22 01:21:22 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'Emptying data works as expected', function ( assert ) {
|
2014-01-22 01:21:22 +00:00
|
|
|
var description = new mw.mmv.ui.Description( $( '#qunit-fixture' ) );
|
|
|
|
|
|
|
|
description.set( 'foo', 'bar' );
|
|
|
|
description.empty();
|
|
|
|
assert.strictEqual( description.$imageDescDiv.hasClass( 'empty' ), true, 'Image description div is marked empty when emptied' );
|
|
|
|
assert.strictEqual( description.$imageDesc.text(), '', 'Image description text is emptied correctly' );
|
|
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|