2018-03-07 11:10:53 +00:00
|
|
|
import { createModel, previewTypes }
|
2018-01-18 18:48:16 +00:00
|
|
|
from '../../../src/preview/model';
|
2017-02-15 15:11:12 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups.preview#createModel' );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'it should copy the basic properties', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const thumbnail = {},
|
2017-02-15 15:11:12 +00:00
|
|
|
model = createModel(
|
|
|
|
'Foo',
|
|
|
|
'https://en.wikipedia.org/wiki/Foo',
|
|
|
|
'en',
|
|
|
|
'ltr',
|
|
|
|
'Foo bar baz.',
|
2018-03-07 11:10:53 +00:00
|
|
|
'standard',
|
2017-02-15 15:11:12 +00:00
|
|
|
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' );
|
2018-03-07 11:10:53 +00:00
|
|
|
assert.strictEqual( model.type, previewTypes.TYPE_PAGE );
|
2017-02-15 15:11:12 +00:00
|
|
|
assert.strictEqual( model.thumbnail, thumbnail );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'it computes the type property', ( assert ) => {
|
2017-07-28 17:32:46 +00:00
|
|
|
|
2018-03-07 11:10:53 +00:00
|
|
|
function createModelWith( { extract, type } ) {
|
2017-02-15 15:11:12 +00:00
|
|
|
return createModel(
|
|
|
|
'Foo',
|
|
|
|
'https://en.wikipedia.org/wiki/Foo',
|
|
|
|
'en',
|
|
|
|
'ltr',
|
2018-03-07 11:10:53 +00:00
|
|
|
extract,
|
|
|
|
type
|
2017-02-15 15:11:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-03-07 11:10:53 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
createModelWith( { extract: 'Foo', type: 'standard' } ).type,
|
|
|
|
previewTypes.TYPE_PAGE,
|
|
|
|
'A non-generic ("page") preview has an extract and type "standard" property.'
|
|
|
|
);
|
2017-02-15 15:11:12 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-03-07 11:10:53 +00:00
|
|
|
createModelWith( { extract: 'Foo', type: undefined } ).type,
|
|
|
|
previewTypes.TYPE_PAGE,
|
|
|
|
'A non-generic ("page") preview has an extract with an undefined "type" property.'
|
2017-02-15 15:11:12 +00:00
|
|
|
);
|
|
|
|
|
2018-03-07 11:10:53 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
createModelWith( { extract: undefined, type: undefined } ).type,
|
|
|
|
previewTypes.TYPE_GENERIC,
|
|
|
|
'A generic ("empty") preview has an undefined extract and an undefined "type" property.'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
createModelWith( { extract: undefined, type: 'standard' } ).type,
|
|
|
|
previewTypes.TYPE_GENERIC,
|
|
|
|
'A generic ("empty") preview has an undefined extract regardless of "type".'
|
|
|
|
);
|
2017-02-15 15:11:12 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
2018-03-07 11:10:53 +00:00
|
|
|
createModelWith( { extract: 'Foo', type: 'disambiguation' } ).type,
|
|
|
|
previewTypes.TYPE_DISAMBIGUATION,
|
|
|
|
'A disambiguation preview has an extract and type ("disambiguation") property.'
|
2017-02-15 15:11:12 +00:00
|
|
|
);
|
|
|
|
} );
|