2022-07-12 22:48:46 +00:00
|
|
|
import { createModel, getPreviewType, previewTypes, registerModel, test,
|
|
|
|
isAnythingEligible } 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
|
|
|
|
);
|
|
|
|
|
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() {
|
2022-07-12 22:48:46 +00:00
|
|
|
this.referenceLink = $( '<a>' )
|
|
|
|
.attr( 'href', '#RefLink' )
|
|
|
|
.appendTo( $( '<span>' ).addClass( 'reference' ) ).get( 0 );
|
|
|
|
this.referenceLinkNoFragment = $( '<a>' )
|
|
|
|
.attr( 'href', '/wiki/Url' )
|
|
|
|
.appendTo( $( '<span>' ).addClass( 'reference' ) ).get( 0 );
|
2020-04-25 21:32:53 +00:00
|
|
|
this.validEl = $( '<a>' ).appendTo( $( '<span>' ).addClass( 'reference' ) ).get( 0 );
|
2022-07-12 22:48:46 +00:00
|
|
|
this.registerRefModel = () => {
|
|
|
|
registerModel(
|
|
|
|
previewTypes.TYPE_REFERENCE,
|
|
|
|
'.reference a[ href*="#" ]'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
afterEach() {
|
|
|
|
test.reset();
|
2019-03-11 13:00:20 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2022-07-12 22:48:46 +00:00
|
|
|
QUnit.test( 'isAnythingEligible returns false by default', function ( assert ) {
|
|
|
|
test.reset();
|
2019-03-11 13:00:20 +00:00
|
|
|
assert.strictEqual(
|
2022-07-12 22:48:46 +00:00
|
|
|
isAnythingEligible(),
|
|
|
|
false
|
2019-03-11 13:00:20 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2022-07-12 22:48:46 +00:00
|
|
|
QUnit.test( 'isAnythingEligible returns true when model is registered', function ( assert ) {
|
|
|
|
this.registerRefModel();
|
2019-03-11 13:00:20 +00:00
|
|
|
assert.strictEqual(
|
2022-07-12 22:48:46 +00:00
|
|
|
isAnythingEligible(),
|
|
|
|
true
|
2019-03-11 13:00:20 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2022-07-12 22:48:46 +00:00
|
|
|
QUnit.test( 'it uses the reference gateway with valid element', function ( assert ) {
|
|
|
|
this.registerRefModel();
|
2019-03-11 13:00:20 +00:00
|
|
|
assert.strictEqual(
|
2022-07-12 22:48:46 +00:00
|
|
|
getPreviewType( this.referenceLink ),
|
|
|
|
previewTypes.TYPE_REFERENCE
|
2019-03-11 13:00:20 +00:00
|
|
|
);
|
2022-07-12 22:48:46 +00:00
|
|
|
} );
|
2019-03-11 13:00:20 +00:00
|
|
|
|
2022-07-12 22:48:46 +00:00
|
|
|
QUnit.test( 'it does not suggest page previews on reference links when reference previews are not registered', function ( assert ) {
|
2019-03-11 13:00:20 +00:00
|
|
|
assert.strictEqual(
|
2023-01-23 18:20:14 +00:00
|
|
|
getPreviewType( this.referenceLink ),
|
2022-07-12 22:48:46 +00:00
|
|
|
null
|
2019-03-11 13:00:20 +00:00
|
|
|
);
|
2022-07-12 22:48:46 +00:00
|
|
|
} );
|
2019-04-18 14:41:16 +00:00
|
|
|
|
2022-07-12 22:48:46 +00:00
|
|
|
QUnit.test( 'it uses the page gateway when on links to a different page', function ( assert ) {
|
|
|
|
registerModel(
|
|
|
|
previewTypes.TYPE_PAGE,
|
|
|
|
'a'
|
|
|
|
);
|
2019-04-18 14:41:16 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType(
|
2022-07-12 22:48:46 +00:00
|
|
|
this.validEl
|
2019-04-18 14:41:16 +00:00
|
|
|
),
|
|
|
|
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 ) {
|
2022-07-12 22:48:46 +00:00
|
|
|
this.registerRefModel();
|
2019-03-11 13:00:20 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getPreviewType(
|
2022-07-12 22:48:46 +00:00
|
|
|
this.referenceLinkNoFragment
|
2019-03-11 13:00:20 +00:00
|
|
|
),
|
|
|
|
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 );
|
2022-07-12 22:48:46 +00:00
|
|
|
this.registerRefModel();
|
2019-03-11 13:00:20 +00:00
|
|
|
assert.strictEqual(
|
2022-07-12 22:48:46 +00:00
|
|
|
getPreviewType( el ),
|
2019-03-11 13:00:20 +00:00
|
|
|
null
|
|
|
|
);
|
|
|
|
} );
|