mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-11 16:16:51 +00:00
4b38d72c2e
The changes from I39f9b994ce5636d70fea2e935a7c87c7d56dcb26 also make most of the broken tests pass again. Change-Id: I165f36235b47dee4bcef115e518bc1e81d2f83a5
101 lines
2.9 KiB
JavaScript
101 lines
2.9 KiB
JavaScript
/* global moment */
|
|
var
|
|
testUtils = require( './testUtils.js' ),
|
|
Parser = require( 'ext.discussionTools.init' ).Parser;
|
|
|
|
QUnit.module( 'mw.dt.Parser', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( '#getTimestampRegexp', function ( assert ) {
|
|
var cases = require( '../cases/timestamp-regex.json' ),
|
|
parser = new Parser( require( '../data-en.json' ) );
|
|
|
|
cases.forEach( function ( caseItem ) {
|
|
assert.strictEqual(
|
|
parser.getTimestampRegexp( 'en', caseItem.format, '\\d', { UTC: 'UTC' } ),
|
|
caseItem.expected,
|
|
caseItem.message
|
|
);
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( '#getTimestampParser', function ( assert ) {
|
|
var cases = require( '../cases/timestamp-parser.json' ),
|
|
parser = new Parser( require( '../data-en.json' ) );
|
|
|
|
cases.forEach( function ( caseItem ) {
|
|
var tsParser = parser.getTimestampParser( 'en', caseItem.format, null, 'UTC', { UTC: 'UTC' } ),
|
|
expectedDate = moment( caseItem.expected );
|
|
|
|
assert.true(
|
|
tsParser( caseItem.data ).date.isSame( expectedDate ),
|
|
caseItem.message
|
|
);
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( '#getTimestampParser (at DST change)', function ( assert ) {
|
|
var cases = require( '../cases/timestamp-parser-dst.json' ),
|
|
parser = new Parser( require( '../data-en.json' ) );
|
|
|
|
cases.forEach( function ( caseItem ) {
|
|
var regexp = parser.getTimestampRegexp( 'en', caseItem.format, '\\d', caseItem.timezoneAbbrs ),
|
|
tsParser = parser.getTimestampParser( 'en', caseItem.format, null, caseItem.timezone, caseItem.timezoneAbbrs ),
|
|
date = tsParser( caseItem.sample.match( regexp ) ).date;
|
|
|
|
assert.true(
|
|
date.isSame( caseItem.expected ),
|
|
caseItem.message
|
|
);
|
|
assert.true(
|
|
date.isSame( caseItem.expectedUtc ),
|
|
caseItem.message
|
|
);
|
|
} );
|
|
} );
|
|
|
|
require( '../cases/comments.json' ).forEach( function ( caseItem ) {
|
|
|
|
var testName = '#getThreads (' + caseItem.name + ')';
|
|
|
|
// Some parser tests are currently broken in JS
|
|
var skipTests = [
|
|
'Signature which is just a selflink'
|
|
];
|
|
if ( skipTests.indexOf( caseItem.name ) !== -1 ) {
|
|
QUnit.skip( testName );
|
|
return;
|
|
}
|
|
|
|
QUnit.test( testName, function ( assert ) {
|
|
var dom = ve.createDocumentFromHtml( require( '../' + caseItem.dom ) ),
|
|
expected = require( caseItem.expected ),
|
|
config = require( caseItem.config ),
|
|
data = require( caseItem.data ),
|
|
title = mw.Title.newFromText( caseItem.title );
|
|
|
|
var container = testUtils.getThreadContainer( dom );
|
|
testUtils.overrideMwConfig( config );
|
|
|
|
var threadItemSet = new Parser( data ).parse( container, title );
|
|
var threads = threadItemSet.getThreads();
|
|
|
|
threads.forEach( function ( thread, i ) {
|
|
testUtils.serializeComments( thread, container );
|
|
|
|
assert.deepEqual(
|
|
JSON.parse( JSON.stringify( thread ) ),
|
|
expected[ i ],
|
|
caseItem.name + ' section ' + i
|
|
);
|
|
} );
|
|
|
|
// Uncomment this to get updated content for the JSON files, for copy/paste:
|
|
// console.log( JSON.stringify( threads, null, 2 ) );
|
|
} );
|
|
} );
|
|
|
|
// TODO:
|
|
// * findCommentsById
|
|
// * findCommentsByName
|
|
// * getThreadItems
|