mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-30 08:43:43 +00:00
1d6ba985be
Same issue as b68832ace0
in PHP.
Change-Id: Ide6ebc47929b597e6dc23df696d87bb3130ce276
91 lines
2.7 KiB
JavaScript
91 lines
2.7 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 + ')';
|
|
QUnit.test( testName, function ( assert ) {
|
|
var dom = ve.createDocumentFromHtml( require( '../' + caseItem.dom ) ),
|
|
expected = require( caseItem.expected ),
|
|
config = require( caseItem.config ),
|
|
data = require( caseItem.data );
|
|
|
|
testUtils.overrideMwConfig( config );
|
|
|
|
var container = testUtils.getThreadContainer( dom );
|
|
var title = mw.Title.newFromText( caseItem.title );
|
|
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
|