mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-28 01:10:04 +00:00
12a8aa3a86
To make sure that we enable the link highlighting in the Cite extension we want to trigger the click handler on the original footnote link. This is done by passing the id of the source element to the model and the renderer. Bug: T213905 Change-Id: I0bd59ac326269f3c0850946851fb79b611dc2a57
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
import { createStubTitle } from '../stubs';
|
|
import createReferenceGateway from '../../../src/gateway/reference';
|
|
|
|
QUnit.module( 'ext.popups/gateway/reference', {
|
|
beforeEach() {
|
|
mediaWiki.msg = ( key ) => `<${key}>`;
|
|
|
|
this.$references = $( '<ul>' ).append(
|
|
$( '<li>' ).attr( 'id', 'cite_note--1' ).append(
|
|
$( '<span>' ).addClass( 'reference-text' ).text( 'Footnote' )
|
|
)
|
|
).appendTo( document.body );
|
|
},
|
|
afterEach() {
|
|
mediaWiki.msg = null;
|
|
|
|
this.$references.remove();
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'Reference preview gateway returns the correct data', function ( assert ) {
|
|
const gateway = createReferenceGateway(),
|
|
title = createStubTitle( 1, 'Foo', 'cite note--1' );
|
|
|
|
return gateway.fetchPreviewForTitle( title ).then( ( result ) => {
|
|
assert.propEqual(
|
|
result,
|
|
{
|
|
url: '#cite_note--1',
|
|
extract: 'Footnote',
|
|
type: 'reference',
|
|
sourceElementId: undefined
|
|
}
|
|
);
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'Reference preview gateway rejects non-existing references', function ( assert ) {
|
|
const gateway = createReferenceGateway(),
|
|
title = createStubTitle( 1, 'Foo', 'undefined' );
|
|
|
|
return gateway.fetchPreviewForTitle( title ).then( () => {
|
|
assert.ok( false, 'It should not resolve' );
|
|
} ).catch( ( reason, result ) => {
|
|
assert.propEqual( result, { textStatus: 'abort', xhr: { readyState: 0 } } );
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'Reference preview gateway is abortable', function ( assert ) {
|
|
const gateway = createReferenceGateway(),
|
|
title = createStubTitle( 1, 'Foo', 'cite note--1' ),
|
|
promise = gateway.fetchPreviewForTitle( title );
|
|
|
|
assert.strictEqual( typeof promise.abort, 'function' );
|
|
} );
|