2018-09-14 05:30:46 +00:00
|
|
|
( function () {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const RelatedPagesGateway = require( '../../resources/ext.relatedArticles.readMore.bootstrap/RelatedPagesGateway.js' ),
|
2017-05-25 18:02:33 +00:00
|
|
|
lotsaRelatedPages = [ 'A', 'B', 'C', 'D', 'E', 'F' ],
|
2015-11-03 23:39:48 +00:00
|
|
|
relatedPages = {
|
|
|
|
query: {
|
2015-11-25 14:34:11 +00:00
|
|
|
pages: [
|
|
|
|
{
|
|
|
|
pageid: 123,
|
2015-11-03 23:39:48 +00:00
|
|
|
title: 'Oh noes',
|
|
|
|
ns: 0,
|
|
|
|
thumbnail: {
|
|
|
|
source: 'http://placehold.it/200x100'
|
|
|
|
}
|
|
|
|
}
|
2015-11-25 14:34:11 +00:00
|
|
|
]
|
2015-11-03 23:39:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
emptyRelatedPages = {
|
|
|
|
query: {
|
2015-11-25 14:34:11 +00:00
|
|
|
pages: []
|
2015-11-03 23:39:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-25 14:34:11 +00:00
|
|
|
QUnit.module( 'ext.relatedArticles.gateway', {
|
2018-11-12 19:13:43 +00:00
|
|
|
beforeEach: function () {
|
2015-11-03 23:39:48 +00:00
|
|
|
this.api = new mw.Api();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
QUnit.test( 'Returns an array with the results when api responds', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const gateway = new RelatedPagesGateway( this.api, 'Foo', null, true );
|
2015-11-03 23:39:48 +00:00
|
|
|
this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
return gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
2018-08-17 10:27:26 +00:00
|
|
|
assert.ok( Array.isArray( results ), 'Results must be an array' );
|
2015-11-03 23:39:48 +00:00
|
|
|
assert.strictEqual( results[ 0 ].title, 'Oh noes' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
QUnit.test( 'Empty related pages is handled fine.', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const gateway = new RelatedPagesGateway( this.api, 'Foo', null, true );
|
2015-11-03 23:39:48 +00:00
|
|
|
this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( emptyRelatedPages ) );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
return gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
2018-08-17 10:27:26 +00:00
|
|
|
assert.ok( Array.isArray( results ), 'Results must be an array' );
|
2015-11-03 23:39:48 +00:00
|
|
|
assert.strictEqual( results.length, 0 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
QUnit.test( 'Empty related pages with no cirrus search is handled fine. No API request.', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const gateway = new RelatedPagesGateway( this.api, 'Foo', [], false ),
|
2015-11-03 23:39:48 +00:00
|
|
|
spy = this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
return gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
2018-08-17 10:27:26 +00:00
|
|
|
assert.ok( Array.isArray( results ), 'Results must be an array' );
|
2018-11-12 19:13:43 +00:00
|
|
|
assert.notOk( spy.called, 'API is not invoked' );
|
2015-11-03 23:39:48 +00:00
|
|
|
assert.strictEqual( results.length, 0 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
QUnit.test( 'Related pages from editor curated content', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const gateway = new RelatedPagesGateway( this.api, 'Foo', [ { title: 1 } ], false );
|
2015-11-03 23:39:48 +00:00
|
|
|
this.sandbox.stub( this.api, 'get' ).returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
return gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
2015-11-03 23:39:48 +00:00
|
|
|
assert.strictEqual( results.length, 1,
|
|
|
|
'API still hit despite cirrus being disabled.' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-05-25 18:02:33 +00:00
|
|
|
QUnit.test( 'When limit is higher than number of cards, no limit is enforced.', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const gateway = new RelatedPagesGateway( this.api, 'Foo', lotsaRelatedPages, true ),
|
2017-10-09 14:37:28 +00:00
|
|
|
// needed to get page images etc..
|
2017-05-25 18:02:33 +00:00
|
|
|
stub = this.sandbox.stub( this.api, 'get' )
|
|
|
|
.returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
|
|
|
|
return gateway.getForCurrentPage( 20 ).then( function () {
|
|
|
|
assert.strictEqual( stub.args[ 0 ][ 0 ].titles.length, lotsaRelatedPages.length );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'When limit is 2, results are restricted.', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const gateway = new RelatedPagesGateway( this.api, 'Foo', lotsaRelatedPages, true ),
|
2017-05-25 18:02:33 +00:00
|
|
|
// needed to get page images etc..
|
|
|
|
stub = this.sandbox.stub( this.api, 'get' )
|
|
|
|
.returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
|
|
|
|
return gateway.getForCurrentPage( 2 ).then( function () {
|
|
|
|
assert.strictEqual( stub.args[ 0 ][ 0 ].titles.length, 2 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'What if editor curated pages is undefined?', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const gateway = new RelatedPagesGateway( this.api, 'Foo', undefined, true );
|
2017-05-25 18:02:33 +00:00
|
|
|
// needed to get page images etc..
|
|
|
|
this.sandbox.stub( this.api, 'get' )
|
|
|
|
.returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
|
|
|
|
return gateway.getForCurrentPage( 1 ).then( function ( results ) {
|
2018-08-17 10:27:26 +00:00
|
|
|
assert.ok( Array.isArray( results ), 'Results must be an array' );
|
2017-05-25 18:02:33 +00:00
|
|
|
assert.strictEqual( results.length, 1, 'API is invoked to source articles.' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
QUnit.test( 'Ignore related pages from editor curated content', function ( assert ) {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const wgRelatedArticles = [
|
2015-11-11 15:30:19 +00:00
|
|
|
'Bar',
|
|
|
|
'Baz',
|
|
|
|
'Qux'
|
|
|
|
],
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
gateway = new RelatedPagesGateway( this.api, 'Foo', wgRelatedArticles, true, true );
|
2015-11-11 15:30:19 +00:00
|
|
|
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const spy = this.sandbox.stub( this.api, 'get' )
|
2015-11-11 15:30:19 +00:00
|
|
|
.returns( $.Deferred().resolve( relatedPages ) );
|
|
|
|
|
2017-04-15 01:12:00 +00:00
|
|
|
return gateway.getForCurrentPage( 1 ).then( function () {
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const parameters = spy.lastCall.args[ 0 ];
|
2015-11-11 15:30:19 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
parameters.generator,
|
|
|
|
'search',
|
|
|
|
'it should hit the CirrusSearch API even though wgRelatedArticles is non-empty'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-09-14 05:30:46 +00:00
|
|
|
}() );
|