Skip to content

Commit

Permalink
Merge branch 'master' into test-submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae authored Oct 20, 2024
2 parents 566ce39 + a76e7f2 commit 0441f60
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 36 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"no-shadow": "off",
"no-undef": "warn",
"no-underscore-dangle": "off",
"no-unused-vars": "warn",
"prefer-const": "warn",
"security/detect-non-literal-regexp": "off",
"security/detect-unsafe-regex": "off",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@

if ( isAccept ) {
// Remove {{Draft categories}}
text = text.replace( /\{\{Draft categories\s*\|((?:\s*\[\[:?Category:[ \S]+?\]\]\s*)*)\s*\}\}/gi, '$1' );
text = text.replace( /\{\{(?:Draft categories|Draftcat)\s*\|((?:\s*\[\[:?Category:[ \S]+?\]\]\s*)*)\s*\}\}/gi, '$1' );

// Remove {{Draft article}} (and {{Draft}}).
// Not removed if the |text= parameter is present, which could contain
Expand Down
64 changes: 30 additions & 34 deletions tests/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,39 @@

/* eslint-env jest, node */

jest.autoMockOff();
const resetToBase = function () {
const fileSystem = require( 'fs' );
const basePageHtml = fileSystem.readFileSync( './tests/test-frame.html' ).toString();
// Set the base document content using jsdom
document.documentElement.innerHtml = basePageHtml;
AFCH = undefined;
$ = require( 'jquery' );
jQuery = $;
};

fs = require( 'fs' );
const setPageTitle = function ( title ) {
mw.config.get.mockImplementation( ( requested ) => {
if ( requested === 'wgPageName' ) {
return title;
} else if ( requested === 'wgNamespaceNumber' ) {
if ( title.indexOf( 'Draft:' ) === 0 ) {
return 118;
}
}
} );
};

resetToAFCApplicablePage = function () {
resetToBase();
setPageTitle( 'Draft:Foo' );
require( './../src/afch.js' );
};

jest.autoMockOff();

// Mocked later
mediaWiki = mw = {};
mw = {};
mediaWiki = {};

// We're always mocking this, what the heck
mw.config = {
Expand All @@ -32,35 +59,4 @@ mw.loader = {
}
};

const basePageHtml = fs.readFileSync( './tests/test-frame.html' ).toString();

requireScript = function ( name ) {
return require( './../src/' + name );
};

setPageTitle = function ( title ) {
mw.config.get.mockImplementation( ( requested ) => {
if ( requested === 'wgPageName' ) {
return title;
} else if ( requested === 'wgNamespaceNumber' ) {
if ( title.indexOf( 'Draft:' ) === 0 ) {
return 118;
}
}
} );
};

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' );
};
2 changes: 1 addition & 1 deletion tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require( './scaffold.js' );

resetToAFCApplicablePage();

requireScript( 'modules/core.js' );
require( './../src/modules/core.js' );

// It's always good to start simple :)
describe( 'AFCH', () => {
Expand Down

0 comments on commit 0441f60

Please sign in to comment.