mediawiki-extensions-Popups/tests/qunit/ext.popups/preview/model.test.js
Sam Smith ab75283392 model: extract -> page
In I6bbff6a5 a preview was assigned the "extract" type if it had an
extract whereas it should've been assigned the "page" type.

Bug: T152004
Change-Id: I5e0cdc8f528647f1e20873753be29c6b85b3a384
2017-02-02 17:06:46 +00:00

79 lines
1.8 KiB
JavaScript

( function ( mw ) {
var createModel = mw.popups.preview.createModel;
QUnit.module( 'ext.popups.preview#createModel' );
QUnit.test( 'it should copy the basic properties', function ( assert ) {
var thumbnail = {},
model = createModel(
'Foo',
'https://en.wikipedia.org/wiki/Foo',
'en',
'ltr',
'Foo bar baz.',
thumbnail
);
assert.strictEqual( model.title, 'Foo' );
assert.strictEqual( model.url, 'https://en.wikipedia.org/wiki/Foo' );
assert.strictEqual( model.languageCode, 'en' );
assert.strictEqual( model.languageDirection, 'ltr' );
assert.strictEqual( model.thumbnail, thumbnail );
} );
QUnit.test( 'it computes the extract property', function ( assert ) {
var cases = [
// removeEllipsis
[ '', undefined ],
[ 'Extract...', 'Extract' ],
[ 'Extract.', 'Extract.' ],
[ '...', undefined ],
// removeParentheticals
[ 'Foo', 'Foo' ],
[ 'Foo (', 'Foo (' ],
[ 'Foo (Bar)', 'Foo' ],
[ 'Foo (Bar))', 'Foo (Bar))' ],
[ 'Foo )(Bar)', 'Foo )(Bar)' ],
[ '(Bar)', undefined ]
];
function createModelWithExtract( extract ) {
return createModel(
'Foo',
'https://en.wikipedia.org/wiki/Foo',
'en',
'ltr',
extract
);
}
$.each( cases, function ( _, testCase ) {
var model = createModelWithExtract( testCase[0] );
assert.strictEqual( model.extract, testCase[1] );
} );
// ---
// It computes the type property...
model = createModelWithExtract( 'Foo' );
assert.strictEqual(
model.type,
mw.popups.preview.TYPE_PAGE,
'A non-generic ("page") preview has an extract.'
);
model = createModelWithExtract( '' );
assert.strictEqual(
model.type,
mw.popups.preview.TYPE_GENERIC,
'A generic preview has an undefined extract.'
);
} );
}( mediaWiki ) );