mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-17 04:43:18 +00:00
95111d2b73
With apologies to anyone who gets a hundred merge conflicts because of this :) We had several different prefix styles (mlb-, mw-mlb-, mw-mmv-, mw-mmv-mmv-, a few unprefixed), which was getting annoying, and will be confusing to wiki editors who are trying to figure out where a given style comes from. Such changes are better done before going live because it breaks all local CSS tweaks on the wiki, so I am renaming things now (also removing some stuff which wasnt used anywhere). Change-Id: I00447a25f0028e234169c6db941bedc99622eb8d
55 lines
2.6 KiB
JavaScript
Executable file
55 lines
2.6 KiB
JavaScript
Executable file
( function ( mw, $ ) {
|
|
QUnit.module( 'mmv.ui.categories', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( 'Sanity test, object creation and UI construction', 2, function ( assert ) {
|
|
var categories = new mw.mmv.ui.Categories( $( '<ul>' ).appendTo( $( '#qunit-fixture' ) ) );
|
|
|
|
assert.ok( categories, 'Image categories UI element is created' );
|
|
assert.strictEqual( categories.$categoryTpl.length, 1, 'Image category template is created' );
|
|
} );
|
|
|
|
QUnit.test( 'Setting data in different combinations works well', 17, function ( assert ) {
|
|
var i,
|
|
j = 0,
|
|
categories = new mw.mmv.ui.Categories( $( '<ul>' ).appendTo( $( '#qunit-fixture' ) ) ),
|
|
categoryNames = [ 'Foo', undefined, null, 'Bar', 'Baz', '', 'Quux' ],
|
|
categoryName;
|
|
|
|
categories.set( 'http://example.net/wiki/$1', categoryNames );
|
|
|
|
assert.strictEqual( $( '.mw-mmv-image-category > span' ).length, 4, 'Only valid categories have an element created for them' );
|
|
|
|
for ( i = 0; i < categoryNames.length; i ++ ) {
|
|
categoryName = categoryNames[ i ];
|
|
|
|
if ( !categoryName || !categoryName.length ) {
|
|
continue;
|
|
}
|
|
|
|
assert.strictEqual( $( '.mw-mmv-image-category > span' ).eq( j ).find( '.comma-container' ).length, j > 0 ? 1 : 0, 'Comma is properly set inside of them' );
|
|
assert.strictEqual( $( '.mw-mmv-image-category > span' ).eq( j ).find( 'a' ).text(), categoryName, 'Category elements have correct text inside of them' );
|
|
assert.strictEqual( $( '.mw-mmv-image-category > span' ).eq( j ).find( 'a' ).prop( 'href' ), 'http://example.net/wiki/Category:' + categoryName, 'Category links are set to the right target' );
|
|
|
|
j++;
|
|
}
|
|
|
|
for ( i = 0; i < 3; i ++ ) {
|
|
assert.ok( !$( '.mw-mmv-image-category > span' ).eq( i ).hasClass( 'extra' ), 'Categories before the fourth are not marked as extra' );
|
|
}
|
|
|
|
assert.ok( $( '.mw-mmv-image-category > span' ).eq( 3 ).hasClass( 'extra' ), 'Categories after the third are marked as extra' );
|
|
} );
|
|
|
|
QUnit.test( 'Emptying data works as expected', 4, function ( assert ) {
|
|
var $list = $( '<ul>' ).appendTo( $( '#qunit-fixture' ) ),
|
|
categories = new mw.mmv.ui.Categories( $list );
|
|
|
|
categories.set( 'http://example.net/wiki/$1', [ 'Foo', 'Bar', 'Baz', 'Quux' ] );
|
|
categories.empty();
|
|
assert.strictEqual( $( '.mw-mmv-image-category > span' ).length, 0, 'All elements are removed from the DOM' );
|
|
assert.strictEqual( $list.text(), '', 'Text is emptied correctly' );
|
|
assert.strictEqual( $list.find( 'li' ).length, 0, 'List elements are all removed' );
|
|
assert.strictEqual( categories.$categories, undefined, 'Category UI element is removed from object' );
|
|
} );
|
|
}( mediaWiki, jQuery ) );
|