diff --git a/resources/dist/index.js b/resources/dist/index.js index df90eb235..1b9937dbf 100644 Binary files a/resources/dist/index.js and b/resources/dist/index.js differ diff --git a/resources/dist/index.js.map.json b/resources/dist/index.js.map.json index 3e0c94bda..5f82f549e 100644 Binary files a/resources/dist/index.js.map.json and b/resources/dist/index.js.map.json differ diff --git a/src/gateway/index.js b/src/gateway/index.js index 4f22367bd..4172973ed 100644 --- a/src/gateway/index.js +++ b/src/gateway/index.js @@ -43,19 +43,21 @@ const $ = jQuery; * @param {Element} el * @param {mw.Map} config * @param {mw.Title} title - * @return {string} + * @return {string|null} */ export default function selectGatewayType( el, config, title ) { - if ( config.get( 'wgPopupsReferencePreviews' ) ) { - // The other selector can potentially pick up self-links with a class="reference" - // parent, but no fragment - if ( title.getFragment() && - title.getPrefixedDb() === config.get( 'wgPageName' ) && - $( el ).parent().hasClass( 'reference' ) - ) { - return previewTypes.TYPE_REFERENCE; - } + if ( title.getPrefixedDb() !== config.get( 'wgPageName' ) ) { + return previewTypes.TYPE_PAGE; } - return previewTypes.TYPE_PAGE; + // The other selector can potentially pick up self-links with a class="reference" + // parent, but no fragment + if ( title.getFragment() && + config.get( 'wgPopupsReferencePreviews' ) && + $( el ).parent().hasClass( 'reference' ) + ) { + return previewTypes.TYPE_REFERENCE; + } + + return null; } diff --git a/tests/node-qunit/gateway/index.test.js b/tests/node-qunit/gateway/index.test.js index d1257c507..2fef590cf 100644 --- a/tests/node-qunit/gateway/index.test.js +++ b/tests/node-qunit/gateway/index.test.js @@ -7,52 +7,63 @@ QUnit.module( 'gateway/index.js', { this.config = new Map(); /* global Map */ this.config.set( 'wgPopupsReferencePreviews', true ); this.config.set( 'wgPageName', 'Foo' ); - this.fragmentLink = createStubTitle( 1, 'Foo', 'Bar' ); + this.referenceLink = createStubTitle( 1, 'Foo', 'ref-fragment' ); this.validEl = $( '' ).appendTo( $( '' ).addClass( 'reference' ) ); } } ); QUnit.test( 'it uses the reference gateway with wgPopupsReferencePreviews == true and valid element', function ( assert ) { assert.strictEqual( - selectInitialGateway( this.validEl, this.config, this.fragmentLink ), + selectInitialGateway( this.validEl, this.config, this.referenceLink ), previewTypes.TYPE_REFERENCE ); } ); -QUnit.test( 'it uses the page gateway with wgPopupsReferencePreviews == false', function ( assert ) { +QUnit.test( 'it does not suggest page previews on reference links when reference previews are disabled', function ( assert ) { this.config.set( 'wgPopupsReferencePreviews', false ); assert.strictEqual( - selectInitialGateway( this.validEl, this.config, this.fragmentLink ), - previewTypes.TYPE_PAGE + selectInitialGateway( this.validEl, this.config, this.referenceLink ), + null ); } ); QUnit.test( 'it uses the page gateway when on links to a different page', function ( assert ) { - this.config.set( 'wgPageName', 'NotFoo' ); + assert.strictEqual( + selectInitialGateway( + this.validEl, + this.config, + createStubTitle( 1, 'NotFoo' ) + ), + previewTypes.TYPE_PAGE + ); assert.strictEqual( - selectInitialGateway( this.validEl, this.config, this.fragmentLink ), + selectInitialGateway( + this.validEl, + this.config, + createStubTitle( 1, 'NotFoo', 'fragment' ) + ), previewTypes.TYPE_PAGE ); } ); -QUnit.test( 'it uses the page gateway when there is no fragment', function ( assert ) { +QUnit.test( 'it does not use the reference gateway when there is no fragment', function ( assert ) { assert.strictEqual( selectInitialGateway( this.validEl, this.config, createStubTitle( 1, 'Foo' ) ), - previewTypes.TYPE_PAGE + null ); } ); -QUnit.test( 'it uses the page gateway for links not having a parent with reference class', function ( assert ) { +QUnit.test( 'it does not suggest page previews on reference links not having a parent with reference class', function ( assert ) { const el = $( '' ).appendTo( $( '' ) ); assert.strictEqual( - selectInitialGateway( el, this.config, this.fragmentLink ), - previewTypes.TYPE_PAGE + selectInitialGateway( el, this.config, this.referenceLink ), + null ); } );