Rename getPageSummary to fetchPreviewForTitle

It's not exclusively about page summaries any more.

We had a few suggestions in mind:
* get, fetch, request, or issueRequest. But I feel these are all to
  generic and don't describe well what the method does. As a reminder:
  It expects a Title object and returns a promise, which returns a
  PreviewModel object, which contains an HTML "extract".
* fetchPreview? I feel this can still mean to many things.
* fetchPreviewModel? But we don't really need to repeat that it will
  return a model object.

So I went for fetchPreviewForTitle. What do you think?

Bug: T213415
Change-Id: Icb32c63cec82f72453dc1507c9f8b8d461fd4f4c
This commit is contained in:
Thiemo Kreuz 2019-01-23 17:50:19 +01:00
parent 671c39ef4a
commit 57fd85fc68
11 changed files with 26 additions and 26 deletions

Binary file not shown.

Binary file not shown.

View file

@ -110,7 +110,7 @@ export function fetch( gateway, title, el, token ) {
namespaceId = title.namespace; namespaceId = title.namespace;
return ( dispatch ) => { return ( dispatch ) => {
const xhr = gateway.getPageSummary( title ); const xhr = gateway.fetchPreviewForTitle( title );
dispatch( timedAction( { dispatch( timedAction( {
type: types.FETCH_START, type: types.FETCH_START,

View file

@ -10,7 +10,7 @@ const mw = mediaWiki,
* The interface implemented by all preview gateways. * The interface implemented by all preview gateways.
* @typedef Gateway * @typedef Gateway
* @prop {Function(string): JQuery.jqXHR} fetch * @prop {Function(string): JQuery.jqXHR} fetch
* @prop {GetPageSummary} getPageSummary * @prop {FetchPreviewForTitle} fetchPreviewForTitle
* @prop {ConvertPageToModel} convertPageToModel * @prop {ConvertPageToModel} convertPageToModel
*/ */
@ -23,12 +23,12 @@ const mw = mediaWiki,
*/ */
/** /**
* Fetches a preview for a page. * Fetches a preview for a page or reference.
* *
* If the underlying request is successful and contains data about the page, * If the underlying request is successful and contains data for the requested title,
* then the resulting promise will resolve. If not, then it will reject. * then the resulting promise will resolve. If not, then it will reject.
* *
* @typedef {Function(mw.Title): AbortPromise<PreviewModel>} GetPageSummary * @typedef {Function(mw.Title): AbortPromise<PreviewModel>} FetchPreviewForTitle
*/ */
/** /**

View file

@ -66,7 +66,7 @@ export default function createMediaWikiApiGateway( api, config ) {
* @param {mw.Title} title * @param {mw.Title} title
* @returns {AbortPromise<PreviewModel>} * @returns {AbortPromise<PreviewModel>}
*/ */
function getPageSummary( title ) { function fetchPreviewForTitle( title ) {
const xhr = fetch( title.getPrefixedDb() ); const xhr = fetch( title.getPrefixedDb() );
return xhr.then( ( data ) => { return xhr.then( ( data ) => {
const page = extractPageFromResponse( data ); const page = extractPageFromResponse( data );
@ -83,7 +83,7 @@ export default function createMediaWikiApiGateway( api, config ) {
fetch, fetch,
extractPageFromResponse, extractPageFromResponse,
convertPageToModel, convertPageToModel,
getPageSummary, fetchPreviewForTitle,
formatPlainTextExtract formatPlainTextExtract
}; };
} }

View file

@ -15,7 +15,7 @@ export default function createReferenceGateway() {
* @param {mw.Title} title * @param {mw.Title} title
* @returns {AbortPromise<PreviewModel>} * @returns {AbortPromise<PreviewModel>}
*/ */
function getPageSummary( title ) { function fetchPreviewForTitle( title ) {
const id = title.getFragment(); const id = title.getFragment();
return $.Deferred().resolve( { return $.Deferred().resolve( {
@ -33,6 +33,6 @@ export default function createReferenceGateway() {
} }
return { return {
getPageSummary fetchPreviewForTitle
}; };
} }

View file

@ -52,7 +52,7 @@ export default function createRESTBaseGateway( ajax, config, extractParser ) {
* @param {mw.Title} title * @param {mw.Title} title
* @returns {AbortPromise<PreviewModel>} * @returns {AbortPromise<PreviewModel>}
*/ */
function getPageSummary( title ) { function fetchPreviewForTitle( title ) {
const titleText = title.getPrefixedDb(), const titleText = title.getPrefixedDb(),
xhr = fetch( titleText ); xhr = fetch( titleText );
return xhr.then( ( page ) => { return xhr.then( ( page ) => {
@ -82,7 +82,7 @@ export default function createRESTBaseGateway( ajax, config, extractParser ) {
return { return {
fetch, fetch,
convertPageToModel, convertPageToModel,
getPageSummary fetchPreviewForTitle
}; };
} }

View file

@ -258,7 +258,7 @@ QUnit.module( 'ext.popups/actions#fetch', {
this.gatewayDeferred = $.Deferred(); this.gatewayDeferred = $.Deferred();
this.gateway = { this.gateway = {
getPageSummary: this.sandbox.stub().returns( fetchPreviewForTitle: this.sandbox.stub().returns(
this.gatewayDeferred.promise( { abort() {} } ) this.gatewayDeferred.promise( { abort() {} } )
) )
}; };
@ -280,7 +280,7 @@ QUnit.test( 'it should fetch data from the gateway immediately', function ( asse
this.fetch(); this.fetch();
assert.ok( assert.ok(
this.gateway.getPageSummary.calledWith( TEST_TITLE ), this.gateway.fetchPreviewForTitle.calledWith( TEST_TITLE ),
'The gateway was called with the correct arguments.' 'The gateway was called with the correct arguments.'
); );

View file

@ -167,7 +167,7 @@ QUnit.test( 'MediaWiki API gateway handles API failure', function ( assert ) {
}, },
gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).catch( () => { return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) ).catch( () => {
assert.ok( true, 'The gateway threw an error.' ); assert.ok( true, 'The gateway threw an error.' );
} ); } );
} ); } );
@ -180,7 +180,7 @@ QUnit.test( 'MediaWiki API gateway returns the correct data', function ( assert
}, },
gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => { return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => {
assert.deepEqual( assert.deepEqual(
result, result,
MEDIAWIKI_API_RESPONSE_PREVIEW_MODEL, MEDIAWIKI_API_RESPONSE_PREVIEW_MODEL,
@ -222,7 +222,7 @@ QUnit.test( 'MediaWiki API gateway handles missing pages', function ( assert ) {
}, },
gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => { return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => {
assert.deepEqual( assert.deepEqual(
result, result,
model, model,
@ -241,7 +241,7 @@ QUnit.test( 'MediaWiki API gateway is abortable', function ( assert ) {
}, },
gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS ); gateway = createMediaWikiApiGateway( api, DEFAULT_CONSTANTS );
const xhr = gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ); const xhr = gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) );
const chain = xhr.then( () => { const chain = xhr.then( () => {
assert.ok( false, 'It never calls a thenable after rejection' ); assert.ok( false, 'It never calls a thenable after rejection' );

View file

@ -358,7 +358,7 @@ QUnit.test( 'RESTBase gateway handles API failure', function ( assert ) {
.returns( $.Deferred().reject( { status: 500 } ).promise() ), .returns( $.Deferred().reject( { status: 500 } ).promise() ),
gateway = createRESTBaseGateway( api, {} ); gateway = createRESTBaseGateway( api, {} );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).catch( () => { return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) ).catch( () => {
assert.ok( true, 'The gateway threw an error.' ); assert.ok( true, 'The gateway threw an error.' );
} ); } );
} ); } );
@ -368,7 +368,7 @@ QUnit.test( 'RESTBase gateway handles 404 as a failure', function ( assert ) {
.returns( $.Deferred().reject( { status: 404 } ).promise() ), .returns( $.Deferred().reject( { status: 404 } ).promise() ),
gateway = createRESTBaseGateway( api, {} ); gateway = createRESTBaseGateway( api, {} );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).catch( () => { return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) ).catch( () => {
assert.ok( true, 'The gateway threw an error.' ); assert.ok( true, 'The gateway threw an error.' );
} ); } );
} ); } );
@ -380,7 +380,7 @@ QUnit.test( 'RESTBase gateway returns the correct data ', function ( assert ) {
gateway = createRESTBaseGateway( gateway = createRESTBaseGateway(
api, DEFAULT_CONSTANTS, provideParsedExtract ); api, DEFAULT_CONSTANTS, provideParsedExtract );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => { return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) ).then( ( result ) => {
assert.deepEqual( assert.deepEqual(
result, result,
RESTBASE_RESPONSE_PREVIEW_MODEL, RESTBASE_RESPONSE_PREVIEW_MODEL,
@ -407,7 +407,7 @@ QUnit.test( 'RESTBase gateway handles missing extracts', function ( assert ) {
gateway = createRESTBaseGateway( gateway = createRESTBaseGateway(
api, DEFAULT_CONSTANTS, provideParsedExtract ); api, DEFAULT_CONSTANTS, provideParsedExtract );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title with missing extract' ) ) return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title with missing extract' ) )
.then( ( result ) => { .then( ( result ) => {
assert.strictEqual( result.title, 'Test Title with missing extract', 'Title' ); assert.strictEqual( result.title, 'Test Title with missing extract', 'Title' );
assert.strictEqual( result.extract, '!!', 'Extract' ); assert.strictEqual( result.extract, '!!', 'Extract' );
@ -420,7 +420,7 @@ QUnit.test( 'RESTBase gateway handles no content success responses', function (
gateway = createRESTBaseGateway( gateway = createRESTBaseGateway(
api, DEFAULT_CONSTANTS, provideParsedExtract ); api, DEFAULT_CONSTANTS, provideParsedExtract );
return gateway.getPageSummary( createStubTitle( 1, 'Test Title with empty response' ) ) return gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title with empty response' ) )
.then( ( result ) => { .then( ( result ) => {
assert.strictEqual( result.title, 'Test Title with empty response', 'Title' ); assert.strictEqual( result.title, 'Test Title with empty response', 'Title' );
assert.strictEqual( result.extract, '!!', 'Extract' ); assert.strictEqual( result.extract, '!!', 'Extract' );
@ -440,7 +440,7 @@ QUnit.test( 'RESTBase gateway is abortable', function ( assert ) {
gateway = createRESTBaseGateway( gateway = createRESTBaseGateway(
api, DEFAULT_CONSTANTS, provideParsedExtract ); api, DEFAULT_CONSTANTS, provideParsedExtract );
const xhr = gateway.getPageSummary( createStubTitle( 1, 'Test Title' ) ); const xhr = gateway.fetchPreviewForTitle( createStubTitle( 1, 'Test Title' ) );
const chain = xhr.then( () => { const chain = xhr.then( () => {
assert.ok( false, 'It never calls a thenable after rejection' ); assert.ok( false, 'It never calls a thenable after rejection' );

View file

@ -9,7 +9,7 @@ import registerChangeListener from '../../src/changeListener';
const mw = mediaWiki, const mw = mediaWiki,
$ = jQuery, $ = jQuery,
/** /**
* Whether Gateway#getPageSummary is resolved or rejected. * Whether Gateway#fetchPreviewForTitle is resolved or rejected.
* @enum {number} * @enum {number}
*/ */
FETCH_RESOLUTION = { RESOLVE: 0, REJECT: 1 }; FETCH_RESOLUTION = { RESOLVE: 0, REJECT: 1 };
@ -103,7 +103,7 @@ QUnit.module( 'ext.popups preview @integration', {
) => { ) => {
this.resetWait(); this.resetWait();
return this.actions.linkDwell( title, el, ev, { return this.actions.linkDwell( title, el, ev, {
getPageSummary() { fetchPreviewForTitle() {
const method = resolution === FETCH_RESOLUTION.RESOLVE ? const method = resolution === FETCH_RESOLUTION.RESOLVE ?
'resolve' : 'reject'; 'resolve' : 'reject';
const abort = { const abort = {
@ -170,7 +170,7 @@ QUnit.test( 'it boots in INACTIVE state', function ( assert ) {
QUnit.test( 'in INACTIVE state, a link dwell switches it to ACTIVE', function ( assert ) { QUnit.test( 'in INACTIVE state, a link dwell switches it to ACTIVE', function ( assert ) {
const gateway = { const gateway = {
getPageSummary() { fetchPreviewForTitle() {
$.Deferred().promise(); $.Deferred().promise();
} }
}; };