2014-03-19 02:00:26 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
( function ( mw, $ ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var $qf = $( '#qunit-fixture' );
|
|
|
|
|
|
|
|
QUnit.module( 'mmv.ui.reuse.Embed', QUnit.newMwEnvironment() );
|
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
QUnit.test( 'Sanity test, object creation and UI construction', 13, function ( assert ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf );
|
|
|
|
|
|
|
|
assert.ok( embed, 'Embed UI element is created.' );
|
|
|
|
assert.strictEqual( embed.$pane.length, 1, 'Pane div is created.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( embed.embedTextHtml, 'Html snipped text area created.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( embed.embedTextWikitext, 'Wikitext snipped text area created.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( embed.embedSwitch, 'Snipped selection buttons created.' );
|
2014-03-21 20:29:55 +00:00
|
|
|
assert.ok( embed.embedSizeSwitchWikitext, 'Size selection menu for wikitext created.' );
|
|
|
|
assert.ok( embed.embedSizeSwitchHtml, 'Size selection menu for html created.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.strictEqual( embed.$currentMainEmbedText.length, 1, 'Size selection menu for html created.' );
|
2014-04-02 02:22:16 +00:00
|
|
|
assert.strictEqual( embed.isSizeMenuDefaultReset, false, 'Reset flag intialized correctly.' );
|
|
|
|
assert.ok( embed.defaultHtmlItem, 'Default item for html size selection intialized.' );
|
|
|
|
assert.ok( embed.defaultWikitextItem, 'Default item for wikitext size selection intialized.' );
|
|
|
|
assert.ok( embed.currentSizeMenu, 'Current size menu intialized.' );
|
|
|
|
assert.ok( embed.currentDefaultItem, 'Current default item intialized.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-19 03:05:36 +00:00
|
|
|
QUnit.test( 'changeSize(): Skip if no item selected.', 0, function ( assert ) {
|
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
width = 10,
|
|
|
|
height = 20;
|
|
|
|
|
|
|
|
// deselect items
|
|
|
|
embed.embedSwitch.selectItem();
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedHtml = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( false, 'No item selected, this should not have been called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedWikitext = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( false, 'No item selected, this should not have been called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
embed.changeSize( width, height );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'changeSize(): HTML size menu item selected.', 4, function ( assert ) {
|
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
width = 10,
|
|
|
|
height = 20;
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.embedSwitch.getSelectedItem = function () {
|
|
|
|
return { getData: function () { return 'html'; } };
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedHtml = function ( thumb, w, h ) {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.strictEqual( thumb.url, undefined, 'Empty thumbnail passed.' );
|
|
|
|
assert.strictEqual( w, width, 'Correct width passed.' );
|
|
|
|
assert.strictEqual( h, height, 'Correct height passed.' );
|
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedWikitext = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( false, 'Dealing with HTML menu, this should not have been called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.select = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( true, 'Item selected after update.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
embed.changeSize( width, height );
|
|
|
|
} );
|
|
|
|
|
2014-03-19 02:00:26 +00:00
|
|
|
QUnit.test( 'changeSize(): Wikitext size menu item selected.', 2, function ( assert ) {
|
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
width = 10,
|
|
|
|
height = 20;
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.embedSwitch.getSelectedItem = function () {
|
|
|
|
return { getData: function () { return 'wikitext'; } };
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedHtml = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( false, 'Dealing with wikitext menu, this should not have been called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedWikitext = function ( w ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.strictEqual( w, width, 'Correct width passed.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.select = function () {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( true, 'Item selected after update.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
embed.changeSize( width, height );
|
|
|
|
} );
|
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
QUnit.test( 'updateEmbedHtml(): Do nothing if set() not called before.', 0, function ( assert ) {
|
2014-03-19 03:05:36 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
width = 10,
|
|
|
|
height = 20;
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailHtml = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( false, 'formatter.getThumbnailHtml() should not have been called.' );
|
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedHtml( {}, width, height );
|
2014-03-19 03:05:36 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
QUnit.test( 'updateEmbedHtml():', 6, function ( assert ) {
|
2014-03-19 03:05:36 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
2014-03-21 20:29:55 +00:00
|
|
|
url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
|
|
|
thumbUrl = 'https://upload.wikimedia.org/wikipedia/thumb/Foobar.jpg',
|
|
|
|
imageInfo = { url: url },
|
|
|
|
repoInfo = {},
|
|
|
|
caption = '-',
|
|
|
|
info = new mw.mmv.model.EmbedFileInfo( imageInfo, repoInfo, caption ),
|
|
|
|
width = 10,
|
|
|
|
height = 20;
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.set( imageInfo, repoInfo, caption );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
|
|
|
// Small image, no thumbnail info is passed
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailHtml = function ( i, u, w, h ) {
|
2014-03-21 20:29:55 +00:00
|
|
|
assert.deepEqual( i, info, 'Info passed correctly.' );
|
|
|
|
assert.strictEqual( u, url, 'Image URL passed correctly.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.strictEqual( w, width, 'Correct width passed.' );
|
|
|
|
assert.strictEqual( h, height, 'Correct height passed.' );
|
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedHtml( {}, width, height );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
|
|
|
// Small image, thumbnail info present
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailHtml = function ( i, u ) {
|
2014-03-21 20:29:55 +00:00
|
|
|
assert.strictEqual( u, thumbUrl, 'Image src passed correctly.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedHtml( { url: thumbUrl }, width, height );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
|
|
|
// Big image, thumbnail info present
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailHtml = function ( i, u ) {
|
2014-03-21 20:29:55 +00:00
|
|
|
assert.strictEqual( u, url, 'Image src passed correctly.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
|
|
|
width = 1300;
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedHtml( { url: thumbUrl }, width, height );
|
2014-03-19 03:05:36 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
QUnit.test( 'updateEmbedWikitext(): Do nothing if set() not called before.', 0, function ( assert ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
width = 10;
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailWikitext = function () {
|
|
|
|
assert.ok( false, 'formatter.getThumbnailWikitext() should not have been called.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedWikitext( width );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
QUnit.test( 'updateEmbedWikitext():', 2, function ( assert ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
2014-03-21 20:29:55 +00:00
|
|
|
imageInfo = {},
|
|
|
|
repoInfo = {},
|
|
|
|
caption = '-',
|
|
|
|
info = new mw.mmv.model.EmbedFileInfo( imageInfo, repoInfo, caption ),
|
|
|
|
width = 10;
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.set( imageInfo, repoInfo, caption );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailWikitextFromEmbedFileInfo = function ( i, w ) {
|
|
|
|
assert.deepEqual( i, info, 'EmbedFileInfo passed correctly.' );
|
|
|
|
assert.strictEqual( w, width, 'Width passed correctly.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedWikitext( width );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-31 16:08:02 +00:00
|
|
|
QUnit.test( 'getPossibleImageSizesForWikitext()', 3, function ( assert ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
exampleSizes = [
|
|
|
|
// Big wide image
|
|
|
|
{
|
|
|
|
width: 2048, height: 1536,
|
|
|
|
expected: {
|
2014-03-31 16:08:02 +00:00
|
|
|
small: { width: 300, height: 225 },
|
|
|
|
medium: { width: 400, height: 300 },
|
2014-04-02 02:22:16 +00:00
|
|
|
large: { width: 500, height: 375 },
|
|
|
|
'default': { width: null, height: null }
|
2014-03-19 02:00:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Big tall image
|
|
|
|
{
|
|
|
|
width: 201, height: 1536,
|
2014-04-02 02:22:16 +00:00
|
|
|
expected: {
|
|
|
|
'default': { width: null, height: null }
|
|
|
|
}
|
2014-03-19 02:00:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Very small image
|
|
|
|
{
|
|
|
|
width: 15, height: 20,
|
2014-04-02 02:22:16 +00:00
|
|
|
expected: {
|
|
|
|
'default': { width: null, height: null }
|
|
|
|
}
|
2014-03-19 02:00:26 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
i, cursize, opts;
|
|
|
|
for ( i = 0; i < exampleSizes.length; i++ ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
cursize = exampleSizes[ i ];
|
2014-03-31 16:08:02 +00:00
|
|
|
opts = embed.getPossibleImageSizesForWikitext( cursize.width, cursize.height );
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.deepEqual( opts, cursize.expected, 'We got the expected results out of the size calculation function.' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
QUnit.test( 'set():', 8, function ( assert ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
|
|
|
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
|
|
|
url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
|
|
|
embedFileInfo = new mw.mmv.model.EmbedFileInfo( title, src, url ),
|
|
|
|
width = 15,
|
|
|
|
height = 20;
|
|
|
|
|
2014-03-19 22:35:55 +00:00
|
|
|
QUnit.stop();
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.utils.updateMenuOptions = function ( sizes, options ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.strictEqual( options.length, 4, 'Options passed correctly.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.resetCurrentSizeMenuToDefault = function () {
|
2014-04-02 02:22:16 +00:00
|
|
|
assert.ok( true, 'resetCurrentSizeMenuToDefault() is called.' );
|
|
|
|
};
|
2014-03-31 16:08:02 +00:00
|
|
|
embed.utils.getThumbnailUrlPromise = function () {
|
2014-03-19 22:35:55 +00:00
|
|
|
return $.Deferred().resolve().promise();
|
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedHtml = function () {
|
|
|
|
assert.ok( true, 'updateEmbedHtml() is called after data is collected.' );
|
2014-03-19 22:35:55 +00:00
|
|
|
};
|
|
|
|
embed.select = function () {
|
|
|
|
assert.ok( true, 'select() is called after data is collected.' );
|
|
|
|
QUnit.start();
|
|
|
|
};
|
2014-03-19 02:00:26 +00:00
|
|
|
|
|
|
|
assert.ok( !embed.embedFileInfo, 'embedFileInfo not set yet.' );
|
|
|
|
|
|
|
|
embed.set( { width: width, height: height }, embedFileInfo );
|
|
|
|
|
|
|
|
assert.ok( embed.embedFileInfo, 'embedFileInfo correctly set.' );
|
2014-04-02 02:22:16 +00:00
|
|
|
assert.strictEqual( embed.isSizeMenuDefaultReset, false, 'Reset flag cleared.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-19 03:05:36 +00:00
|
|
|
QUnit.test( 'empty():', 6, function ( assert ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
width = 15,
|
|
|
|
height = 20;
|
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.formatter = {
|
|
|
|
getThumbnailWikitextFromEmbedFileInfo: function () { return 'wikitext'; },
|
|
|
|
getThumbnailHtml: function () { return 'html'; }
|
|
|
|
};
|
|
|
|
|
|
|
|
embed.set( {}, {} );
|
|
|
|
embed.updateEmbedHtml( { url: 'x' }, width, height );
|
|
|
|
embed.updateEmbedWikitext( width );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.notStrictEqual( embed.embedTextHtml.getValue(), '', 'embedTextHtml is not empty.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.notStrictEqual( embed.embedTextWikitext.getValue(), '', 'embedTextWikitext is not empty.' );
|
|
|
|
|
|
|
|
embed.empty();
|
|
|
|
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.strictEqual( embed.embedTextHtml.getValue(), '', 'embedTextHtml is empty.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.strictEqual( embed.embedTextWikitext.getValue(), '', 'embedTextWikitext is empty.' );
|
2015-01-23 12:48:27 +00:00
|
|
|
assert.ok( !embed.embedSizeSwitchHtml.getMenu().isVisible(), 'Html size menu should be hidden.' );
|
|
|
|
assert.ok( !embed.embedSizeSwitchWikitext.getMenu().isVisible(), 'Wikitext size menu should be hidden.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2014-03-19 03:05:36 +00:00
|
|
|
QUnit.test( 'attach()/unattach():', 5, function ( assert ) {
|
2014-03-19 02:00:26 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf ),
|
|
|
|
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
|
|
|
src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
|
|
|
url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
|
|
|
embedFileInfo = new mw.mmv.model.EmbedFileInfo( title, src, url ),
|
|
|
|
width = 15,
|
|
|
|
height = 20;
|
|
|
|
|
|
|
|
embed.set( { width: width, height: height }, embedFileInfo );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.selectAllOnEvent = function () {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( false, 'selectAllOnEvent should not have been called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleTypeSwitch = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( false, 'handleTypeSwitch should not have been called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleSizeSwitch = function () {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( false, 'handleTypeSwitch should not have been called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Triggering action events before attaching should do nothing
|
2014-05-15 19:16:22 +00:00
|
|
|
// use of focus() would run into jQuery bug #14740 and similar issues
|
2014-05-21 21:41:39 +00:00
|
|
|
embed.embedTextHtml.$element.find( 'textarea' ).triggerHandler( 'focus' );
|
|
|
|
embed.embedTextWikitext.$element.find( 'textarea' ).triggerHandler( 'focus' );
|
2014-03-19 03:05:36 +00:00
|
|
|
embed.embedSwitch.emit( 'select' );
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.embedSizeSwitchHtml.getMenu().emit(
|
2014-04-08 23:01:02 +00:00
|
|
|
'choose', embed.embedSizeSwitchHtml.getMenu().getSelectedItem() );
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.embedSizeSwitchWikitext.getMenu().emit(
|
2014-04-08 23:01:02 +00:00
|
|
|
'choose', embed.embedSizeSwitchWikitext.getMenu().getSelectedItem() );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.selectAllOnEvent = function () {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( true, 'selectAllOnEvent was called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleTypeSwitch = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( true, 'handleTypeSwitch was called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleSizeSwitch = function () {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( true, 'handleTypeSwitch was called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
embed.attach();
|
|
|
|
|
|
|
|
// Action events should be handled now
|
2014-05-21 21:41:39 +00:00
|
|
|
embed.embedTextHtml.$element.find( 'textarea' ).triggerHandler( 'focus' );
|
|
|
|
embed.embedTextWikitext.$element.find( 'textarea' ).triggerHandler( 'focus' );
|
2014-03-19 03:05:36 +00:00
|
|
|
embed.embedSwitch.emit( 'select' );
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.embedSizeSwitchHtml.getMenu().emit(
|
2014-04-08 23:01:02 +00:00
|
|
|
'choose', embed.embedSizeSwitchHtml.getMenu().getSelectedItem() );
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.embedSizeSwitchWikitext.getMenu().emit(
|
2014-04-08 23:01:02 +00:00
|
|
|
'choose', embed.embedSizeSwitchWikitext.getMenu().getSelectedItem() );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
|
|
|
// Test the unattach part
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.selectAllOnEvent = function () {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( false, 'selectAllOnEvent should not have been called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleTypeSwitch = function () {
|
2014-03-19 03:05:36 +00:00
|
|
|
assert.ok( false, 'handleTypeSwitch should not have been called.' );
|
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleSizeSwitch = function () {
|
2014-03-19 02:00:26 +00:00
|
|
|
assert.ok( false, 'handleTypeSwitch should not have been called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
embed.unattach();
|
|
|
|
|
|
|
|
// Triggering action events now that we are unattached should do nothing
|
2014-05-21 21:41:39 +00:00
|
|
|
embed.embedTextHtml.$element.find( 'textarea' ).triggerHandler( 'focus' );
|
|
|
|
embed.embedTextWikitext.$element.find( 'textarea' ).triggerHandler( 'focus' );
|
2014-03-19 03:05:36 +00:00
|
|
|
embed.embedSwitch.emit( 'select' );
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.embedSizeSwitchHtml.getMenu().emit(
|
2014-04-08 23:01:02 +00:00
|
|
|
'choose', embed.embedSizeSwitchHtml.getMenu().getSelectedItem() );
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.embedSizeSwitchWikitext.getMenu().emit(
|
2014-04-08 23:01:02 +00:00
|
|
|
'choose', embed.embedSizeSwitchWikitext.getMenu().getSelectedItem() );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
QUnit.test( 'handleTypeSwitch():', 6, function ( assert ) {
|
2014-03-19 03:05:36 +00:00
|
|
|
var embed = new mw.mmv.ui.reuse.Embed( $qf );
|
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
assert.strictEqual( embed.isSizeMenuDefaultReset, false, 'Reset flag intialized correctly.' );
|
|
|
|
|
|
|
|
embed.resetCurrentSizeMenuToDefault = function () {
|
|
|
|
assert.ok( true, 'resetCurrentSizeMenuToDefault() called.' );
|
|
|
|
};
|
|
|
|
|
2014-03-19 03:05:36 +00:00
|
|
|
// HTML selected
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleTypeSwitch( { getData: function () { return 'html'; } } );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
assert.strictEqual( embed.isSizeMenuDefaultReset, true, 'Reset flag updated correctly.' );
|
2015-01-23 12:48:27 +00:00
|
|
|
assert.ok( !embed.embedSizeSwitchWikitext.getMenu().isVisible(), 'Wikitext size menu should be hidden.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
embed.resetCurrentSizeMenuToDefault = function () {
|
|
|
|
assert.ok( false, 'resetCurrentSizeMenuToDefault() should not have been called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Wikitext selected, we are done resetting defaults
|
|
|
|
embed.handleTypeSwitch( { getData: function () { return 'wikitext'; } } );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
assert.strictEqual( embed.isSizeMenuDefaultReset, true, 'Reset flag updated correctly.' );
|
2015-01-23 12:48:27 +00:00
|
|
|
assert.ok( !embed.embedSizeSwitchHtml.getMenu().isVisible(), 'HTML size menu should be hidden.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
} );
|
|
|
|
|
2014-04-08 14:25:27 +00:00
|
|
|
QUnit.test( 'Logged out', 4, function ( assert ) {
|
|
|
|
var embed,
|
|
|
|
oldUserIsAnon = mw.user.isAnon;
|
|
|
|
|
|
|
|
mw.user.isAnon = function () { return true; };
|
|
|
|
|
|
|
|
embed = new mw.mmv.ui.reuse.Embed( $qf );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
assert.ok( !embed.embedSizeSwitchWikitext.$element.hasClass( 'active' ), 'Wikitext widget should be hidden.' );
|
2014-04-08 14:25:27 +00:00
|
|
|
assert.ok( embed.embedSizeSwitchHtml.$element.hasClass( 'active' ), 'HTML widget should be visible.' );
|
2015-01-23 12:48:27 +00:00
|
|
|
assert.ok( !embed.embedTextWikitext.$element.hasClass( 'active' ), 'Wikitext input should be hidden.' );
|
2014-04-08 14:25:27 +00:00
|
|
|
assert.ok( embed.embedTextHtml.$element.hasClass( 'active' ), 'HTML input should be visible.' );
|
|
|
|
|
|
|
|
mw.user.isAnon = oldUserIsAnon;
|
|
|
|
} );
|
|
|
|
|
2014-03-19 02:00:26 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|