2019-03-11 13:00:20 +00:00
|
|
|
import { createModel, getPreviewType, previewTypes }
|
2018-01-18 18:48:16 +00:00
|
|
|
from '../../../src/preview/model';
|
2019-03-11 13:00:20 +00:00
|
|
|
import { createStubTitle } from '../stubs';
|
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
|
|
|
|
);
|
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
model.title,
|
|
|
|
'Foo',
|
|
|
|
'The title is passed.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
model.url,
|
|
|
|
'https://en.wikipedia.org/wiki/Foo',
|
|
|
|
'The URL is generated.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
model.languageCode,
|
|
|
|
'en',
|
|
|
|
'The language code is passed.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
model.languageDirection,
|
|
|
|
'ltr',
|
|
|
|
'The language direction is passed.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
model.type,
|
|
|
|
previewTypes.TYPE_PAGE,
|
|
|
|
'The preview type is "page preview".'
|
|
|
|
);
|
|
|
|
assert.strictEqual( model.thumbnail, thumbnail, 'The thumbnail is passed' );
|
2017-02-15 15:11:12 +00:00
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'it computes the type property', ( assert ) => {
|
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
|
|
|
);
|
|
|
|
} );
|
2019-03-11 13:00:20 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups.preview#getPreviewType', {
|
|
|
|
beforeEach() {
|
2019-09-17 11:47:25 +00:00
|
|
|
this.config = new Map();
|
2019-03-11 13:00:20 +00:00
|
|
|
this.config.set( 'wgPopupsReferencePreviews', true );
|
2019-04-18 14:41:16 +00:00
|
|
|
this.config.set( 'wgTitle', 'Foo' );
|
|
|
|
this.config.set( 'wgNamespaceNumber', 1 );
|
2019-04-26 10:53:46 +00:00
|
|
|
this.referenceLink = createStubTitle( 1, 'Foo', 'ref-fragment' );
|
2020-04-25 21:32:53 +00:00
|
|
|
this.validEl = $( '<a>' ).appendTo( $( '<span>' ).addClass( 'reference' ) ).get( 0 );
|
2019-03-11 13:00:20 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it uses the reference gateway with wgPopupsReferencePreviews == true and valid element', function ( assert ) {
|
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType( this.validEl, this.config, this.referenceLink ),
|
|
|
|
previewTypes.TYPE_REFERENCE
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it does not suggest page previews on reference links when reference previews are disabled', function ( assert ) {
|
|
|
|
this.config.set( 'wgPopupsReferencePreviews', false );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType( this.validEl, this.config, this.referenceLink ),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it uses the page gateway when on links to a different page', function ( assert ) {
|
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType(
|
|
|
|
this.validEl,
|
|
|
|
this.config,
|
|
|
|
createStubTitle( 1, 'NotFoo' )
|
|
|
|
),
|
|
|
|
previewTypes.TYPE_PAGE
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType(
|
|
|
|
this.validEl,
|
|
|
|
this.config,
|
|
|
|
createStubTitle( 1, 'NotFoo', 'fragment' )
|
|
|
|
),
|
|
|
|
previewTypes.TYPE_PAGE
|
|
|
|
);
|
2019-04-18 14:41:16 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType(
|
|
|
|
this.validEl,
|
|
|
|
this.config,
|
|
|
|
createStubTitle( 2, 'Foo', 'fragment' )
|
|
|
|
),
|
|
|
|
previewTypes.TYPE_PAGE
|
|
|
|
);
|
2019-03-11 13:00:20 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it does not use the reference gateway when there is no fragment', function ( assert ) {
|
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType(
|
|
|
|
this.validEl,
|
|
|
|
this.config,
|
|
|
|
createStubTitle( 1, 'Foo' )
|
|
|
|
),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it does not suggest page previews on reference links not having a parent with reference class', function ( assert ) {
|
2020-04-25 21:32:53 +00:00
|
|
|
const el = $( '<a>' ).appendTo( $( '<span>' ) ).get( 0 );
|
2019-03-11 13:00:20 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType( el, this.config, this.referenceLink ),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
} );
|