2014-05-18 17:10:51 -05:00
|
|
|
/**
|
|
|
|
* This script sets up the DOM, loads and mocks a few commonly
|
|
|
|
* used tools, and creates helper functions that supplement
|
|
|
|
* the actual tests themselves.
|
|
|
|
*/
|
|
|
|
|
|
|
|
jest.autoMockOff();
|
|
|
|
|
|
|
|
fs = require( 'fs' );
|
|
|
|
|
|
|
|
// Mocked later
|
|
|
|
mediaWiki = mw = {};
|
|
|
|
|
|
|
|
// We're always mocking this, what the heck
|
|
|
|
mw.config = {
|
|
|
|
get: jest.genMockFunction()
|
|
|
|
};
|
|
|
|
|
2014-05-20 16:48:51 -05:00
|
|
|
mw.user = {
|
|
|
|
getName: jest.genMockFunction()
|
|
|
|
};
|
|
|
|
|
2014-05-18 17:10:51 -05:00
|
|
|
var basePageHtml = fs.readFileSync( './__tests__/test-frame.html' ).toString();
|
|
|
|
|
|
|
|
requireScript = function ( name ) {
|
|
|
|
return require( './../src/' + name );
|
|
|
|
};
|
|
|
|
|
|
|
|
setPageTitle = function ( title ) {
|
|
|
|
mw.config.get.mockImplementation( function ( requested ) {
|
|
|
|
if ( requested === 'wgPageName' ) {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
resetToBase = function () {
|
|
|
|
// Set the base document content using jsdom
|
|
|
|
document.documentElement.innerHtml = basePageHtml;
|
|
|
|
AFCH = undefined;
|
|
|
|
jQuery = $ = require( 'jquery' );
|
|
|
|
};
|
|
|
|
|
|
|
|
resetToBase();
|
|
|
|
|
|
|
|
resetToAFCApplicablePage = function () {
|
|
|
|
resetToBase();
|
|
|
|
setPageTitle( 'Draft:Foo' );
|
|
|
|
requireScript( 'afch.js' );
|
|
|
|
};
|