mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-12-20 12:00:43 +00:00
0fed50e266
By default, the Read More feature tries to use editor-curated articles before using the CirrusSearch morelike: feature. Add a configuration variable that disables the former behaviour but leave the default in place. Changes: * Add the wgReadMoreOnlyUseCirrusSearch configuration variable, which defaults to false, and pass it in to mw.relatedArticles.RelatedPagesGateway at construction time * Add the onlyUseCirrusSearch parameter to mw.relatedArticles.RelatedPagesGateway, which controls whether to ignore the editorCuratedArticles parameter Bug: T117443 Change-Id: I0dfa67f4a68e8dc17302fef7ebf8d23c0c1d892c
95 lines
2.9 KiB
JavaScript
95 lines
2.9 KiB
JavaScript
( function ( M, $ ) {
|
|
var RelatedPagesGateway = mw.relatedArticles.RelatedPagesGateway,
|
|
relatedPages = {
|
|
query: {
|
|
pages: {
|
|
123: {
|
|
id: 123,
|
|
title: 'Oh noes',
|
|
ns: 0,
|
|
thumbnail: {
|
|
source: 'http://placehold.it/200x100'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
emptyRelatedPages = {
|
|
query: {
|
|
pages: {
|
|
}
|
|
}
|
|
};
|
|
|
|
QUnit.module( 'RelatedArticles readMore - Related pages api', {
|
|
setup: function () {
|
|
this.api = new mw.Api();
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'Returns an array with the results when api responds', 2, function ( assert ) {
|
|
var gateway = new RelatedPagesGateway( this.api, 'Foo', null, true );
|
|
this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
|
assert.ok( $.isArray( results ), 'Results must be an array' );
|
|
assert.strictEqual( results[ 0 ].title, 'Oh noes' );
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'Empty related pages is handled fine.', 2, function ( assert ) {
|
|
var gateway = new RelatedPagesGateway( this.api, 'Foo', null, true );
|
|
this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( emptyRelatedPages ) );
|
|
|
|
gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
|
assert.ok( $.isArray( results ), 'Results must be an array' );
|
|
assert.strictEqual( results.length, 0 );
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'Empty related pages with no cirrus search is handled fine. No API request.', 3, function ( assert ) {
|
|
var gateway = new RelatedPagesGateway( this.api, 'Foo', [], false ),
|
|
spy = this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
|
assert.ok( $.isArray( results ), 'Results must be an array' );
|
|
assert.ok( !spy.called, 'API is not invoked' );
|
|
assert.strictEqual( results.length, 0 );
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'Related pages from editor curated content', 1, function ( assert ) {
|
|
var gateway = new RelatedPagesGateway( this.api, 'Foo', [ { title: 1 } ], false );
|
|
this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
|
assert.strictEqual( results.length, 1,
|
|
'API still hit despite cirrus being disabled.' );
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'Ignore related pages from editor curated content', 1, function ( assert ) {
|
|
var wgRelatedArticles = [
|
|
'Bar',
|
|
'Baz',
|
|
'Qux'
|
|
],
|
|
gateway = new RelatedPagesGateway( this.api, 'Foo', wgRelatedArticles, true, true ),
|
|
spy;
|
|
|
|
spy = this.sandbox.stub( this.api, 'get' )
|
|
.returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
gateway.getForCurrentPage( 1 ).then( function () {
|
|
var parameters = spy.lastCall.args[ 0 ];
|
|
|
|
assert.strictEqual(
|
|
parameters.generator,
|
|
'search',
|
|
'it should hit the CirrusSearch API even though wgRelatedArticles is non-empty'
|
|
);
|
|
} );
|
|
} );
|
|
|
|
}( mw.mobileFrontend, jQuery ) );
|