mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2025-01-09 20:24:17 +00:00
Merge "[qunit] Use strict and wrap test scope"
This commit is contained in:
commit
20ede4b0f4
|
@ -1,12 +1,15 @@
|
|||
function createStubTitle( fragment = null ) {
|
||||
'use strict';
|
||||
|
||||
( function () {
|
||||
function createStubTitle( fragment = null ) {
|
||||
return {
|
||||
getFragment() {
|
||||
return fragment;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
|
||||
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
|
||||
QUnit.module :
|
||||
QUnit.module.skip )( 'ext.cite.referencePreviews#createReferenceGateway', {
|
||||
beforeEach: function () {
|
||||
|
@ -51,9 +54,9 @@ function createStubTitle( fragment = null ) {
|
|||
this.$sourceElement.parent().remove();
|
||||
this.$references.remove();
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway returns the correct data', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway returns the correct data', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'cite note-1' );
|
||||
|
||||
|
@ -69,9 +72,9 @@ QUnit.test( 'Reference preview gateway returns the correct data', function ( ass
|
|||
}
|
||||
);
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway accepts alternative text node class name', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway accepts alternative text node class name', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'cite note-2' );
|
||||
|
||||
|
@ -87,9 +90,9 @@ QUnit.test( 'Reference preview gateway accepts alternative text node class name'
|
|||
}
|
||||
);
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway accepts duplicated types', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway accepts duplicated types', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'cite note-3' );
|
||||
|
||||
|
@ -105,9 +108,9 @@ QUnit.test( 'Reference preview gateway accepts duplicated types', function ( ass
|
|||
}
|
||||
);
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway ignores conflicting types', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway ignores conflicting types', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'cite note-4' );
|
||||
|
||||
|
@ -123,9 +126,9 @@ QUnit.test( 'Reference preview gateway ignores conflicting types', function ( as
|
|||
}
|
||||
);
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway returns source element id', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway returns source element id', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'cite note-1' );
|
||||
|
||||
|
@ -141,34 +144,43 @@ QUnit.test( 'Reference preview gateway returns source element id', function ( as
|
|||
}
|
||||
);
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway rejects non-existing references', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway rejects non-existing references', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'undefined' );
|
||||
|
||||
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( () => {
|
||||
assert.true( false, 'It should not resolve' );
|
||||
} ).catch( ( result ) => {
|
||||
assert.propEqual( result, { textStatus: 'abort', textContext: 'Footnote not found or empty', xhr: { readyState: 0 } } );
|
||||
assert.propEqual( result, {
|
||||
textStatus: 'abort',
|
||||
textContext: 'Footnote not found or empty',
|
||||
xhr: { readyState: 0 }
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway rejects all-whitespace references', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway rejects all-whitespace references', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'cite note-5' );
|
||||
|
||||
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( () => {
|
||||
assert.true( false, 'It should not resolve' );
|
||||
} ).catch( ( result ) => {
|
||||
assert.propEqual( result, { textStatus: 'abort', textContext: 'Footnote not found or empty', xhr: { readyState: 0 } } );
|
||||
assert.propEqual( result, {
|
||||
textStatus: 'abort',
|
||||
textContext: 'Footnote not found or empty',
|
||||
xhr: { readyState: 0 }
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Reference preview gateway is abortable', function ( assert ) {
|
||||
QUnit.test( 'Reference preview gateway is abortable', function ( assert ) {
|
||||
const gateway = require( 'ext.cite.referencePreviews' ).private.createReferenceGateway(),
|
||||
title = createStubTitle( 'cite note-1' ),
|
||||
promise = gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] );
|
||||
|
||||
assert.strictEqual( typeof promise.abort, 'function' );
|
||||
} );
|
||||
} );
|
||||
}() );
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
function createStubUserSettings( expectEnabled ) {
|
||||
'use strict';
|
||||
|
||||
( function () {
|
||||
function createStubUserSettings( expectEnabled ) {
|
||||
return {
|
||||
isPreviewTypeEnabled() {
|
||||
return expectEnabled !== false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function createStubUser( isAnon, options ) {
|
||||
function createStubUser( isAnon, options ) {
|
||||
return {
|
||||
isNamed() {
|
||||
return !isAnon;
|
||||
|
@ -16,15 +19,15 @@ function createStubUser( isAnon, options ) {
|
|||
},
|
||||
options
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const options = { get: () => '1' };
|
||||
const options = { get: () => '1' };
|
||||
|
||||
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
|
||||
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
|
||||
QUnit.module :
|
||||
QUnit.module.skip )( 'ext.cite.referencePreviews#isReferencePreviewsEnabled' );
|
||||
|
||||
QUnit.test( 'relevant combinations of anonymous flags', ( assert ) => {
|
||||
QUnit.test( 'relevant combinations of anonymous flags', ( assert ) => {
|
||||
[
|
||||
{
|
||||
testCase: 'enabled for an anonymous user',
|
||||
|
@ -52,7 +55,8 @@ QUnit.test( 'relevant combinations of anonymous flags', ( assert ) => {
|
|||
isNamed: () => !data.isAnon && !data.isIPMasked,
|
||||
isAnon: () => data.isAnon,
|
||||
options: {
|
||||
get: () => {}
|
||||
get: () => {
|
||||
}
|
||||
}
|
||||
},
|
||||
isPreviewTypeEnabled = () => {
|
||||
|
@ -76,9 +80,9 @@ QUnit.test( 'relevant combinations of anonymous flags', ( assert ) => {
|
|||
data.testCase
|
||||
);
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'it should display reference previews when conditions are fulfilled', ( assert ) => {
|
||||
QUnit.test( 'it should display reference previews when conditions are fulfilled', ( assert ) => {
|
||||
const user = createStubUser( false, options ),
|
||||
userSettings = createStubUserSettings( false ),
|
||||
config = new Map();
|
||||
|
@ -89,9 +93,9 @@ QUnit.test( 'it should display reference previews when conditions are fulfilled'
|
|||
require( 'ext.cite.referencePreviews' ).private.isReferencePreviewsEnabled( user, userSettings, config ),
|
||||
'If the user is logged in and the user is in the on group, then it\'s enabled.'
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'it should not be enabled when the global is disabling it', ( assert ) => {
|
||||
QUnit.test( 'it should not be enabled when the global is disabling it', ( assert ) => {
|
||||
const user = createStubUser( false ),
|
||||
userSettings = createStubUserSettings( false ),
|
||||
config = new Map();
|
||||
|
@ -103,4 +107,5 @@ QUnit.test( 'it should not be enabled when the global is disabling it', ( assert
|
|||
null,
|
||||
'Reference Previews is disabled.'
|
||||
);
|
||||
} );
|
||||
} );
|
||||
}() );
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
let createReferencePreview;
|
||||
const previewTypes = { TYPE_REFERENCE: 'reference' };
|
||||
'use strict';
|
||||
|
||||
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
|
||||
( function () {
|
||||
let createReferencePreview;
|
||||
const previewTypes = { TYPE_REFERENCE: 'reference' };
|
||||
|
||||
( mw.loader.getModuleNames().indexOf( 'ext.popups.main' ) !== -1 ?
|
||||
QUnit.module :
|
||||
QUnit.module.skip )( 'ext.cite.referencePreviews#renderer', {
|
||||
before() {
|
||||
|
@ -15,9 +18,9 @@ const previewTypes = { TYPE_REFERENCE: 'reference' };
|
|||
} ) );
|
||||
this.sandbox.stub( mw.html, 'escape', ( str ) => str && str.replace( /'/g, ''' ).replace( /</g, '<' ) );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'createReferencePreview(model)', ( assert ) => {
|
||||
QUnit.test( 'createReferencePreview(model)', ( assert ) => {
|
||||
const model = {
|
||||
url: '#custom_id',
|
||||
extract: 'Custom <i>extract</i> with an <a href="/wiki/Internal">internal</a> and an <a href="//wikipedia.de" class="external">external</a> link',
|
||||
|
@ -42,9 +45,9 @@ QUnit.test( 'createReferencePreview(model)', ( assert ) => {
|
|||
1,
|
||||
'only external links open in new tabs'
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'createReferencePreview default title', ( assert ) => {
|
||||
QUnit.test( 'createReferencePreview default title', ( assert ) => {
|
||||
const model = {
|
||||
url: '',
|
||||
extract: '',
|
||||
|
@ -56,9 +59,9 @@ QUnit.test( 'createReferencePreview default title', ( assert ) => {
|
|||
$( preview.el ).find( '.mwe-popups-title' ).text().trim(),
|
||||
'<cite-reference-previews-reference>'
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'createReferencePreview updates fade-out effect on scroll', ( assert ) => {
|
||||
QUnit.test( 'createReferencePreview updates fade-out effect on scroll', ( assert ) => {
|
||||
const model = {
|
||||
url: '',
|
||||
extract: '',
|
||||
|
@ -71,9 +74,9 @@ QUnit.test( 'createReferencePreview updates fade-out effect on scroll', ( assert
|
|||
|
||||
assert.false( $extract.children()[ 0 ].isScrolling );
|
||||
assert.false( $extract.hasClass( 'mwe-popups-fade-out' ) );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'createReferencePreview collapsible/sortable handling', ( assert ) => {
|
||||
QUnit.test( 'createReferencePreview collapsible/sortable handling', ( assert ) => {
|
||||
const model = {
|
||||
url: '',
|
||||
extract: '<table class="mw-collapsible"></table>' +
|
||||
|
@ -89,4 +92,5 @@ QUnit.test( 'createReferencePreview collapsible/sortable handling', ( assert ) =
|
|||
$( preview.el ).find( '.mwe-collapsible-placeholder' ).text(),
|
||||
'<cite-reference-previews-collapsible-placeholder>'
|
||||
);
|
||||
} );
|
||||
} );
|
||||
}() );
|
||||
|
|
Loading…
Reference in a new issue