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/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-20 08:30:52 +00:00
|
|
|
const { Embed } = require( 'mmv.ui.reuse.shareembed' );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2023-10-24 09:53:23 +00:00
|
|
|
const $qf = $( '#qunit-fixture' );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
|
|
|
QUnit.module( 'mmv.ui.reuse.Embed', QUnit.newMwEnvironment() );
|
|
|
|
|
2021-12-10 00:43:28 +00:00
|
|
|
QUnit.test( 'Sense test, object creation and UI construction', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2023-05-20 08:30:52 +00:00
|
|
|
assert.true( embed instanceof Embed, 'Embed UI element is created.' );
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.true( embed.$embedTextHtml[ 0 ] instanceof HTMLElement, 'Html snipped text area created.' );
|
|
|
|
assert.true( embed.$embedTextWikitext[ 0 ] instanceof HTMLElement, 'Wikitext snipped text area created.' );
|
|
|
|
assert.true( embed.$embedSizeSwitchWikitext[ 0 ] instanceof HTMLElement, 'Size selection menu for wikitext created.' );
|
|
|
|
assert.true( embed.$embedSizeSwitchHtml[ 0 ] instanceof HTMLElement, 'Size selection menu for html created.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
QUnit.test( 'handleSizeSwitch(): Skip if no item selected.', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
assert.expect( 0 );
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.$embedSizeSwitchHtml.val( undefined );
|
|
|
|
embed.$embedSizeSwitchWikitext.val( undefined );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedHtml = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'No item selected, this should not have been called.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedWikitext = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'No item selected, this should not have been called.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.handleSizeSwitch();
|
2014-03-19 03:05:36 +00:00
|
|
|
} );
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
QUnit.test( 'handleSizeSwitch(): HTML/Wikitext size menu item selected.', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2024-05-04 14:00:17 +00:00
|
|
|
const width = '10';
|
|
|
|
const height = '20';
|
|
|
|
|
|
|
|
const $option = embed.$embedSizeSwitchHtml.children().first();
|
|
|
|
$option.attr( 'data-width', width );
|
|
|
|
$option.attr( 'data-height', height );
|
|
|
|
embed.$embedSizeSwitchHtml.val( $option.val() );
|
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 () {
|
2024-05-04 14:00:17 +00:00
|
|
|
// ignore
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.select = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'Item selected after update.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.handleSizeSwitch();
|
2014-03-19 03:05:36 +00:00
|
|
|
} );
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
QUnit.test( 'handleSizeSwitch(): Wikitext size menu item selected.', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2024-05-04 14:00:17 +00:00
|
|
|
const width = '10';
|
|
|
|
const height = '20';
|
|
|
|
|
|
|
|
const $option = embed.$embedSizeSwitchWikitext.children().first();
|
|
|
|
$option.attr( 'data-width', width );
|
|
|
|
$option.attr( 'data-height', height );
|
|
|
|
embed.$embedSizeSwitchWikitext.val( $option.val() );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.updateEmbedHtml = function () {
|
2024-05-04 14:00:17 +00:00
|
|
|
// ignore
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
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 () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'Item selected after update.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
};
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.handleSizeSwitch();
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'updateEmbedHtml(): Do nothing if set() not called before.', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
|
|
|
const width = 10;
|
|
|
|
const height = 20;
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
assert.expect( 0 );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailHtml = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'formatter.getThumbnailHtml() should not have been called.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.updateEmbedHtml( {}, width, height );
|
2014-03-19 03:05:36 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'updateEmbedHtml():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2024-05-04 14:00:17 +00:00
|
|
|
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
2023-10-24 09:53:23 +00:00
|
|
|
const url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
|
|
|
const thumbUrl = 'https://upload.wikimedia.org/wikipedia/thumb/Foobar.jpg';
|
2024-05-04 14:00:17 +00:00
|
|
|
const imageInfo = { url, title };
|
2023-10-24 09:53:23 +00:00
|
|
|
const repoInfo = {};
|
|
|
|
const caption = '-';
|
|
|
|
const info = {
|
|
|
|
imageInfo: imageInfo,
|
|
|
|
repoInfo: repoInfo,
|
|
|
|
caption: caption
|
|
|
|
};
|
|
|
|
let width = 10;
|
|
|
|
const height = 20;
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.resetCurrentSizeMenuToDefault = () => {};
|
|
|
|
|
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
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'updateEmbedWikitext(): Do nothing if set() not called before.', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
|
|
|
const width = 10;
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
assert.expect( 0 );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.formatter.getThumbnailWikitext = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( 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
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'updateEmbedWikitext():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2024-05-04 14:00:17 +00:00
|
|
|
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
|
|
|
const url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
|
|
|
|
|
|
|
const imageInfo = { url, title };
|
2023-10-24 09:53:23 +00:00
|
|
|
const repoInfo = {};
|
|
|
|
const caption = '-';
|
|
|
|
const info = {
|
|
|
|
imageInfo: imageInfo,
|
|
|
|
repoInfo: repoInfo,
|
|
|
|
caption: caption
|
|
|
|
};
|
|
|
|
const width = 10;
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.resetCurrentSizeMenuToDefault = () => {};
|
|
|
|
|
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
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'getPossibleImageSizesForWikitext()', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
|
|
|
const exampleSizes = [
|
|
|
|
// Big wide image
|
|
|
|
{
|
|
|
|
width: 2048, height: 1536,
|
|
|
|
expected: {
|
|
|
|
small: { width: 300, height: 225 },
|
|
|
|
medium: { width: 400, height: 300 },
|
|
|
|
large: { width: 500, height: 375 },
|
|
|
|
default: { width: null, height: null }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Big tall image
|
|
|
|
{
|
|
|
|
width: 201, height: 1536,
|
|
|
|
expected: {
|
|
|
|
default: { width: null, height: null }
|
2014-04-02 02:22:16 +00:00
|
|
|
}
|
2023-10-24 09:53:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Very small image
|
|
|
|
{
|
|
|
|
width: 15, height: 20,
|
|
|
|
expected: {
|
|
|
|
default: { width: null, height: null }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
for ( let i = 0; i < exampleSizes.length; i++ ) {
|
|
|
|
const cursize = exampleSizes[ i ];
|
|
|
|
const 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.' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'set():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
|
|
|
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
|
|
|
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
|
|
|
const url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
|
|
|
const embedFileInfo = {
|
|
|
|
imageInfo: title,
|
|
|
|
repoInfo: src,
|
|
|
|
caption: url
|
|
|
|
};
|
|
|
|
const width = 15;
|
|
|
|
const height = 20;
|
2014-03-19 02:00:26 +00:00
|
|
|
|
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 () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'resetCurrentSizeMenuToDefault() is called.' );
|
2014-04-02 02:22:16 +00:00
|
|
|
};
|
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 () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'updateEmbedHtml() is called after data is collected.' );
|
2014-03-19 22:35:55 +00:00
|
|
|
};
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.false( $.isPlainObject( embed.embedFileInfo ), 'embedFileInfo not set yet.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
|
|
|
embed.set( { width: width, height: height }, embedFileInfo );
|
|
|
|
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( $.isPlainObject( embed.embedFileInfo ), 'embedFileInfo set.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'empty():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
|
|
|
const width = 15;
|
|
|
|
const height = 20;
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
embed.formatter = {
|
2024-02-13 00:44:51 +00:00
|
|
|
getThumbnailWikitextFromEmbedFileInfo: function () {
|
|
|
|
return 'wikitext';
|
|
|
|
},
|
|
|
|
getThumbnailHtml: function () {
|
|
|
|
return 'html';
|
|
|
|
}
|
2014-03-21 20:29:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
embed.set( {}, {} );
|
|
|
|
embed.updateEmbedHtml( { url: 'x' }, width, height );
|
|
|
|
embed.updateEmbedWikitext( width );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.notStrictEqual( embed.$embedTextHtml.val(), '', 'embedTextHtml is not empty.' );
|
|
|
|
assert.notStrictEqual( embed.$embedTextWikitext.val(), '', 'embedTextWikitext is not empty.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
|
|
|
embed.empty();
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.strictEqual( embed.$embedTextHtml.val(), '', 'embedTextHtml is empty.' );
|
|
|
|
assert.strictEqual( embed.$embedTextWikitext.val(), '', 'embedTextWikitext is empty.' );
|
|
|
|
assert.strictEqual( embed.$embedSizeSwitchHtml.css( 'display' ), 'none', 'Html size menu should be hidden.' );
|
|
|
|
assert.strictEqual( embed.$embedSizeSwitchWikitext.css( 'display' ), 'none', 'Wikitext size menu should be hidden.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'attach()/unattach():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
|
|
|
const title = mw.Title.newFromText( 'File:Foobar.jpg' );
|
|
|
|
const src = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg';
|
|
|
|
const url = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg';
|
|
|
|
const embedFileInfo = {
|
|
|
|
imageInfo: title,
|
|
|
|
repoInfo: src,
|
|
|
|
caption: url
|
|
|
|
};
|
|
|
|
const width = 15;
|
|
|
|
const height = 20;
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.resetCurrentSizeMenuToDefault = () => {};
|
|
|
|
|
2014-03-19 02:00:26 +00:00
|
|
|
embed.set( { width: width, height: height }, embedFileInfo );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleTypeSwitch = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'handleTypeSwitch should not have been called.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleSizeSwitch = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'handleTypeSwitch should not have been called.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Triggering action events before attaching should do nothing
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.$embedSizeSwitchHtml.trigger( 'change' );
|
|
|
|
embed.$embedSizeSwitchWikitext.trigger( 'change' );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleTypeSwitch = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'handleTypeSwitch was called.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleSizeSwitch = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'handleTypeSwitch was called.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
embed.attach();
|
|
|
|
|
|
|
|
// Action events should be handled now
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.$embedSizeSwitchHtml.trigger( 'change' );
|
|
|
|
embed.$embedSizeSwitchWikitext.trigger( 'change' );
|
2014-03-19 02:00:26 +00:00
|
|
|
|
|
|
|
// Test the unattach part
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleTypeSwitch = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'handleTypeSwitch should not have been called.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
};
|
2015-01-23 12:48:27 +00:00
|
|
|
embed.handleSizeSwitch = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'handleTypeSwitch should not have been called.' );
|
2014-03-19 02:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
embed.unattach();
|
|
|
|
|
|
|
|
// Triggering action events now that we are unattached should do nothing
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.$embedSizeSwitchHtml.trigger( 'change' );
|
|
|
|
embed.$embedSizeSwitchWikitext.trigger( 'change' );
|
2014-03-19 02:00:26 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'handleTypeSwitch():', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2014-04-02 02:22:16 +00:00
|
|
|
embed.resetCurrentSizeMenuToDefault = function () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( true, 'resetCurrentSizeMenuToDefault() called.' );
|
2014-04-02 02:22:16 +00:00
|
|
|
};
|
|
|
|
|
2014-03-19 03:05:36 +00:00
|
|
|
// HTML selected
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.handleTypeSwitch( 'html' );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.strictEqual( embed.$embedSizeSwitchWikitext.css( 'display' ), 'none', '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 () {
|
2022-05-20 00:18:43 +00:00
|
|
|
assert.true( false, 'resetCurrentSizeMenuToDefault() should not have been called.' );
|
2014-04-02 02:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Wikitext selected, we are done resetting defaults
|
2024-05-04 14:00:17 +00:00
|
|
|
embed.handleTypeSwitch( 'wikitext' );
|
2014-03-19 03:05:36 +00:00
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.strictEqual( embed.$embedSizeSwitchHtml.css( 'display' ), 'none', 'HTML size menu should be hidden.' );
|
2014-03-19 03:05:36 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'Logged out', function ( assert ) {
|
2023-10-24 09:53:23 +00:00
|
|
|
const oldUserIsAnon = mw.user.isAnon;
|
2014-04-08 14:25:27 +00:00
|
|
|
|
2023-06-27 20:33:13 +00:00
|
|
|
mw.user.isAnon = () => true;
|
2014-04-08 14:25:27 +00:00
|
|
|
|
2023-10-24 09:53:23 +00:00
|
|
|
const embed = new Embed( $qf );
|
2014-04-08 14:25:27 +00:00
|
|
|
|
2019-05-23 14:27:43 +00:00
|
|
|
embed.attach();
|
|
|
|
|
2024-05-04 14:00:17 +00:00
|
|
|
assert.strictEqual( embed.$embedSizeSwitchWikitext.css( 'display' ), 'none', 'Wikitext widget should be hidden.' );
|
|
|
|
assert.strictEqual( embed.$embedSizeSwitchHtml.css( 'display' ), '', 'HTML widget should be visible.' );
|
|
|
|
assert.strictEqual( embed.$embedTextWikitextDiv.css( 'display' ), 'none', 'Wikitext input should be hidden.' );
|
|
|
|
assert.strictEqual( embed.$embedTextHtmlDiv.css( 'display' ), '', 'HTML input should be visible.' );
|
2014-04-08 14:25:27 +00:00
|
|
|
|
|
|
|
mw.user.isAnon = oldUserIsAnon;
|
|
|
|
} );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|