jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/403684 )
Change subject: Hygiene: add more fetch failure test cases ...................................................................... Hygiene: add more fetch failure test cases Add fetch failure tests for integration and preview state. Bug: T183151 Change-Id: I1a541d96f3a83b99c26a5180ad5ee8626cda97d2 --- M tests/node-qunit/integration.test.js M tests/node-qunit/reducers/preview.test.js 2 files changed, 48 insertions(+), 5 deletions(-) Approvals: Jhernandez: Looks good to me, but someone else must approve jenkins-bot: Verified Jdlrobson: Looks good to me, approved diff --git a/tests/node-qunit/integration.test.js b/tests/node-qunit/integration.test.js index 0be8023..4f3e9a2 100644 --- a/tests/node-qunit/integration.test.js +++ b/tests/node-qunit/integration.test.js @@ -9,7 +9,13 @@ var mw = mediaWiki, $ = jQuery, // Store the real wait to be actually used in tests - wait = WaitModule.default; + wait = WaitModule.default, + + /** + * Whether Gateway#getPageSummary is resolved or rejected. + * @enum {number} + */ + FETCH_RESOLUTION = { RESOLVE: 0, REJECT: 1 }; function identity( x ) { return x; } function constant( x ) { return function () { return x; }; } @@ -96,18 +102,19 @@ { get: identity } ); - this.dwell = function ( title, el, ev, fetchResponse ) { + this.dwell = function ( title, el, ev, fetchResponse, resolution = FETCH_RESOLUTION.RESOLVE ) { that.resetWait(); that.actions.linkDwell( title, el, ev, { getPageSummary: function () { - return $.Deferred().resolve( fetchResponse ).promise(); + var method = resolution === FETCH_RESOLUTION.RESOLVE ? 'resolve' : 'reject'; + return $.Deferred()[ method ]( fetchResponse ).promise(); } }, function () { return 'pagetoken'; } ); return that.waitPromise; }; - this.dwellAndShowPreview = function ( title, el, ev, fetchResponse ) { - that.dwell( title, el, ev, fetchResponse ); + this.dwellAndShowPreview = function ( title, el, ev, fetchResponse, reject = FETCH_RESOLUTION.RESOLVE ) { + that.dwell( title, el, ev, fetchResponse, reject ); that.waitDeferred.resolve(); // Wait for the next tick to resolve pending callbacks. N.B. that the @@ -194,6 +201,17 @@ } ); } ); +QUnit.test( 'in ACTIVE state, fetch fail switches it to DATA', function ( assert ) { + var store = this.store, + el = this.el; + + return this.dwellAndShowPreview( this.title, el, 'event', 42, FETCH_RESOLUTION.REJECT ).then( function () { + var state = store.getState(); + assert.equal( state.preview.activeLink, el ); + assert.equal( state.preview.shouldShow, false, 'Shouldn\'t show when data couldn\'t be fetched' ); + } ); +} ); + QUnit.test( 'in ACTIVE state, abandon start, and then end, switch it to INACTIVE', function ( assert ) { var that = this, el = this.el; diff --git a/tests/node-qunit/reducers/preview.test.js b/tests/node-qunit/reducers/preview.test.js index 2cde0fd..7d1d0bd 100644 --- a/tests/node-qunit/reducers/preview.test.js +++ b/tests/node-qunit/reducers/preview.test.js @@ -1,4 +1,5 @@ import preview from '../../../src/reducers/preview'; +import actionTypes from '../../../src/actionTypes'; QUnit.module( 'ext.popups/reducers#preview', { beforeEach: function () { @@ -213,6 +214,30 @@ } ); +QUnit.test( actionTypes.FETCH_FAILED, function ( assert ) { + var token = '1234567890', + state = { + activeToken: token, + isUserDwelling: true + }, + action = { + type: actionTypes.FETCH_FAILED, + token: token + }; + + assert.expect( 1 ); + + assert.deepEqual( + preview( state, action ), + { + // Previous state. + activeToken: state.activeToken, + isUserDwelling: true + }, + 'It should store the result and not transition states.' + ); +} ); + QUnit.test( 'PREVIEW_DWELL', function ( assert ) { var action = { type: 'PREVIEW_DWELL' -- To view, visit https://gerrit.wikimedia.org/r/403684 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I1a541d96f3a83b99c26a5180ad5ee8626cda97d2 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Popups Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Jhernandez <jhernan...@wikimedia.org> Gerrit-Reviewer: Pmiazga <pmia...@wikimedia.org> Gerrit-Reviewer: Sniedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits