mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-09-23 18:30:54 +00:00
tests: Don't assume synchronous jQuery.Deferred
Bug: T124742 Change-Id: I8289d88fa61447ba31e7b767727775ead411987e
This commit is contained in:
parent
ce0db068d9
commit
1b6c46d7dd
|
@ -26,48 +26,48 @@
|
|||
}
|
||||
} );
|
||||
|
||||
QUnit.test( 'Returns an array with the results when api responds', 2, function ( assert ) {
|
||||
QUnit.test( 'Returns an array with the results when api responds', 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 ) {
|
||||
return 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 ) {
|
||||
QUnit.test( 'Empty related pages is handled fine.', 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 ) {
|
||||
return 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 ) {
|
||||
QUnit.test( 'Empty related pages with no cirrus search is handled fine. No API request.', 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 ) {
|
||||
return 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 ) {
|
||||
QUnit.test( 'Related pages from editor curated content', 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 ) {
|
||||
return 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 ) {
|
||||
QUnit.test( 'Ignore related pages from editor curated content', function ( assert ) {
|
||||
var wgRelatedArticles = [
|
||||
'Bar',
|
||||
'Baz',
|
||||
|
@ -79,7 +79,7 @@
|
|||
spy = this.sandbox.stub( this.api, 'get' )
|
||||
.returns( $.Deferred().resolve( relatedPages ) );
|
||||
|
||||
gateway.getForCurrentPage( 1 ).then( function () {
|
||||
return gateway.getForCurrentPage( 1 ).then( function () {
|
||||
var parameters = spy.lastCall.args[ 0 ];
|
||||
|
||||
assert.strictEqual(
|
||||
|
|
Loading…
Reference in a new issue