mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-12-10 23:36:37 +00:00
deafff7046
Also add integration tests to make sure URL generation works OK Bug: 63908 Bug: 64910 Bug: 66147 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/570 Change-Id: I448f42e294102a633f74c305dd0a226e7dbe955d
152 lines
7.2 KiB
JavaScript
152 lines
7.2 KiB
JavaScript
( function ( mw, $ ) {
|
|
QUnit.module( 'mmv.ui.fileUsage', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( 'File usage panel with no usage', 1, function( assert ) {
|
|
var fileUsage = new mw.mmv.ui.FileUsage( $( '#qunit-fixture' ) ),
|
|
file = new mw.Title( 'File:Foo' ),
|
|
localUsage = new mw.mmv.model.FileUsage( file, 'local', [] ),
|
|
globalUsage = new mw.mmv.model.FileUsage( file, 'global', [] );
|
|
|
|
fileUsage.init();
|
|
fileUsage.set( localUsage, globalUsage );
|
|
|
|
assert.ok( fileUsage.$box.hasClass( 'empty' ) );
|
|
} );
|
|
|
|
QUnit.test( 'File usage panel with local usage', 8, function( assert ) {
|
|
var $list,
|
|
fileUsage = new mw.mmv.ui.FileUsage( $( '#qunit-fixture' ) ),
|
|
file = new mw.Title( 'File:Foo' ),
|
|
localUsage = new mw.mmv.model.FileUsage( file, 'local', [
|
|
new mw.Title( 'Bar' ),
|
|
new mw.Title( 'Baz' )
|
|
] ),
|
|
globalUsage = new mw.mmv.model.FileUsage( file, 'global', [] );
|
|
|
|
fileUsage.init();
|
|
fileUsage.set( localUsage, globalUsage );
|
|
|
|
assert.ok( ! fileUsage.$box.hasClass( 'empty' ), 'The container is not empty' );
|
|
|
|
$list = $( '#qunit-fixture li:not([class])' );
|
|
assert.strictEqual( $list.length, 2 );
|
|
assert.strictEqual( $list.eq( 0 ).text(), 'Bar' );
|
|
assert.strictEqual( $list.eq( 1 ).text(), 'Baz' );
|
|
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section' ).length, 1, 'There is a local section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section' ).length, 0, 'There is no global section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section .mw-mmv-fileusage-view-all' ).length, 0, 'The local section has no "view all uses" link' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section .mw-mmv-fileusage-view-all' ).length, 0, 'The global section has no "view all uses" link' );
|
|
} );
|
|
|
|
QUnit.test( 'File usage panel with local usage and overflow', 6, function( assert ) {
|
|
var $list,
|
|
fileUsage = new mw.mmv.ui.FileUsage( $( '#qunit-fixture' ) ),
|
|
file = new mw.Title( 'File:Foo' ),
|
|
localUsage = new mw.mmv.model.FileUsage( file, 'local', [
|
|
new mw.Title( 'Bar' ),
|
|
new mw.Title( 'Baz' ),
|
|
new mw.Title( 'Boom' ),
|
|
new mw.Title( 'Boing' )
|
|
] ),
|
|
globalUsage = new mw.mmv.model.FileUsage( file, 'global', [] );
|
|
|
|
fileUsage.init();
|
|
fileUsage.set( localUsage, globalUsage );
|
|
|
|
assert.ok( ! fileUsage.$box.hasClass( 'empty' ), 'The container is not empty' );
|
|
|
|
$list = $( '#qunit-fixture li:not([class])' );
|
|
assert.strictEqual( $list.length, fileUsage.MAX_LOCAL );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section' ).length, 1, 'There is a local section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section' ).length, 0, 'There is no global section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section .mw-mmv-fileusage-view-all' ).length, 1, 'The local section has its "view all uses" link' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section .mw-mmv-fileusage-view-all' ).length, 0, 'The global section has no "view all uses" link' );
|
|
} );
|
|
|
|
QUnit.test( 'File usage panel with global usage', 10, function( assert ) {
|
|
var $list,
|
|
fileUsage = new mw.mmv.ui.FileUsage( $( '#qunit-fixture' ) ),
|
|
file = new mw.Title( 'File:Foo' ),
|
|
localUsage = new mw.mmv.model.FileUsage( file, 'local', [] ),
|
|
globalUsage = new mw.mmv.model.FileUsage( file, 'global', [
|
|
new mw.mmv.model.IwTitle( 0, 'Bar', 'x.com', 'http://x.com/wiki/Bar' ),
|
|
new mw.mmv.model.IwTitle( 0, 'Baz', 'y.com', 'http://x.com/wiki/Baz' )
|
|
] );
|
|
|
|
fileUsage.init();
|
|
fileUsage.set( localUsage, globalUsage );
|
|
|
|
assert.ok( ! fileUsage.$box.hasClass( 'empty' ), 'The container is not empty' );
|
|
|
|
$list = $( '#qunit-fixture li:not([class])' );
|
|
assert.strictEqual( $list.length, 2 );
|
|
assert.strictEqual( $list.eq( 0 ).find( 'a' ).text(), 'Bar' );
|
|
assert.strictEqual( $list.eq( 1 ).find( 'a' ).text(), 'Baz' );
|
|
assert.strictEqual( $list.eq( 0 ).find( 'aside' ).text(), 'x.com' );
|
|
assert.strictEqual( $list.eq( 1 ).find( 'aside' ).text(), 'y.com' );
|
|
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section' ).length, 0, 'There is no local section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section' ).length, 1, 'There is a global section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section .mw-mmv-fileusage-view-all' ).length, 0, 'The local section has no "view all uses" link' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section .mw-mmv-fileusage-view-all' ).length, 0, 'The global section has no "view all uses" link' );
|
|
} );
|
|
|
|
QUnit.test( 'File usage panel with lots of uses', 7, function( assert ) {
|
|
var $list,
|
|
totalCount = 100,
|
|
fileUsage = new mw.mmv.ui.FileUsage( $( '#qunit-fixture' ) ),
|
|
file = new mw.Title( 'File:Foo' ),
|
|
localUsage = new mw.mmv.model.FileUsage( file, 'local', [
|
|
new mw.Title( 'Bar' ),
|
|
new mw.Title( 'Baz' ),
|
|
new mw.Title( 'Boom' ),
|
|
new mw.Title( 'Boing' )
|
|
], totalCount, true ),
|
|
globalUsage = new mw.mmv.model.FileUsage( file, 'global', [
|
|
new mw.mmv.model.IwTitle( 0, 'Bar', 'x.com', 'http://x.com/wiki/Bar' ),
|
|
new mw.mmv.model.IwTitle( 0, 'Baz', 'x.com', 'http://x.com/wiki/Baz' ),
|
|
new mw.mmv.model.IwTitle( 0, 'Bar', 'y.com', 'http://y.com/wiki/Bar' ),
|
|
new mw.mmv.model.IwTitle( 0, 'Baz', 'y.com', 'http://y.com/wiki/Baz' )
|
|
] );
|
|
|
|
fileUsage.init();
|
|
fileUsage.set( localUsage, globalUsage );
|
|
|
|
assert.ok( ! fileUsage.$box.hasClass( 'empty' ), 'The container is not empty' );
|
|
|
|
$list = $( '#qunit-fixture li:not([class])' );
|
|
assert.strictEqual( $list.length, fileUsage.MAX_LOCAL + fileUsage.MAX_GLOBAL, 'Total amount of results is correctly capped' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section' ).length, 1, 'There is a local section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section' ).length, 1, 'There is a global section' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-local-section .mw-mmv-fileusage-view-all' ).length, 1, 'The local section has its "view all uses" link' );
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-global-section .mw-mmv-fileusage-view-all' ).length, 1, 'The global section has its "view all uses" link' );
|
|
assert.ok( $( '#qunit-fixture h3' ).text().match( totalCount ), 'The "Used in" counter has the right total' );
|
|
} );
|
|
|
|
QUnit.test( 'The interface is emptied properly when necessary', 4, function( assert ) {
|
|
var $list,
|
|
fileUsage = new mw.mmv.ui.FileUsage( $( '#qunit-fixture' ) ),
|
|
file = new mw.Title( 'File:Foo' ),
|
|
localUsage = new mw.mmv.model.FileUsage( file, 'local', [
|
|
new mw.Title( 'Bar' ),
|
|
new mw.Title( 'Baz' )
|
|
] ),
|
|
globalUsage = new mw.mmv.model.FileUsage( file, 'global', [] );
|
|
|
|
fileUsage.init();
|
|
fileUsage.set( localUsage, globalUsage );
|
|
|
|
assert.ok( ! fileUsage.$box.hasClass( 'empty' ), 'The container is not empty' );
|
|
|
|
fileUsage.empty();
|
|
|
|
assert.ok( fileUsage.$box.hasClass( 'empty' ), 'The container is empty' );
|
|
|
|
$list = $( '#qunit-fixture li:not([class])' );
|
|
assert.strictEqual( $list.length, 0, 'The list is empty' );
|
|
|
|
assert.strictEqual( $( '#qunit-fixture .mw-mmv-fileusage-container h3' ).text(), '', 'The "Used in" counter is empty' );
|
|
} );
|
|
}( mediaWiki, jQuery ) );
|