mediawiki-extensions-Popups/tests/node-qunit/gateway/reference.test.js
WMDE-Fisch 12a8aa3a86 Trigger click on source footnote link
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
2019-02-07 14:15:45 -07:00

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' );
} );