mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-28 09:20:31 +00:00
e6081106f1
Why: Because they are the approved standard by TC39 and Ecma for JavaScript modules. Changes: * Wrap mw-node-qunit in run.js to register babel to transpile modules for node v6 * Change all sources in src/ to use ES modules * Change constants.js to be able to run without jQuery.bracketedDevicePixelRatio given ES modules are hoisted to the top by spec so we can't patch globals before importing it * Change all tests in tests/node-qunit/ to use ES modules * Drop usage of mock-require given ES modules are easy to stub with sinon Additional changes: * Rename tests/node-qunit/renderer.js to renderer.test.js to follow the convention of all the other files * Make npm run test:node run only .test.js test files so that it doesn't run the stubs.js or run.js file. Bug: T171951 Change-Id: I17a0b76041d5e2fd18e2d54950d9d7c0db99a941
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
import { createModel, TYPE_PAGE, TYPE_GENERIC } from '../../../src/preview/model';
|
|
|
|
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 type property', function ( assert ) {
|
|
var model;
|
|
|
|
function createModelWithExtract( extract ) {
|
|
return createModel(
|
|
'Foo',
|
|
'https://en.wikipedia.org/wiki/Foo',
|
|
'en',
|
|
'ltr',
|
|
extract
|
|
);
|
|
}
|
|
|
|
model = createModelWithExtract( 'Foo' );
|
|
|
|
assert.strictEqual(
|
|
model.type,
|
|
TYPE_PAGE,
|
|
'A non-generic ("page") preview has an extract.'
|
|
);
|
|
|
|
model = createModelWithExtract( '' );
|
|
|
|
assert.strictEqual(
|
|
model.type,
|
|
TYPE_GENERIC,
|
|
'A generic preview has an undefined extract.'
|
|
);
|
|
} );
|