2020-07-20 14:13:59 +00:00
|
|
|
var
|
|
|
|
testUtils = require( './testUtils.js' ),
|
2020-07-20 21:15:03 +00:00
|
|
|
Parser = require( 'ext.discussionTools.init' ).Parser,
|
2020-07-20 14:13:59 +00:00
|
|
|
CommentItem = require( 'ext.discussionTools.init' ).CommentItem,
|
|
|
|
HeadingItem = require( 'ext.discussionTools.init' ).HeadingItem;
|
|
|
|
|
|
|
|
QUnit.module( 'mw.dt.ThreadItem', testUtils.newEnvironment() );
|
|
|
|
|
|
|
|
QUnit.test( '#getAuthorsBelow', function ( assert ) {
|
|
|
|
var cases = require( '../cases/authors.json' );
|
|
|
|
|
|
|
|
function newFromJSON( json ) {
|
|
|
|
var item;
|
|
|
|
if ( json.type === 'heading' ) {
|
|
|
|
item = new HeadingItem();
|
|
|
|
} else {
|
|
|
|
item = new CommentItem();
|
|
|
|
item.author = json.author;
|
|
|
|
}
|
|
|
|
item.replies = json.replies.map( newFromJSON );
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
cases.forEach( function ( caseItem ) {
|
|
|
|
var threadItem = newFromJSON( caseItem.thread ),
|
|
|
|
authors = threadItem.getAuthorsBelow();
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
authors,
|
|
|
|
caseItem.expected
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
2020-07-20 14:48:41 +00:00
|
|
|
|
|
|
|
QUnit.test( '#getTranscludedFrom', function ( assert ) {
|
|
|
|
var fixture,
|
|
|
|
cases = require( '../cases/transcluded.json' );
|
|
|
|
|
|
|
|
fixture = document.getElementById( 'qunit-fixture' );
|
|
|
|
|
|
|
|
cases.forEach( function ( caseItem ) {
|
2020-07-20 21:15:03 +00:00
|
|
|
var comments, transcludedFrom, parser,
|
2020-07-20 14:48:41 +00:00
|
|
|
$dom = mw.template.get( 'test.DiscussionTools', caseItem.dom ).render(),
|
|
|
|
expected = require( caseItem.expected ),
|
|
|
|
config = require( caseItem.config ),
|
|
|
|
data = require( caseItem.data );
|
|
|
|
|
|
|
|
$( fixture ).empty().append( $dom );
|
|
|
|
mw.libs.ve.unwrapParsoidSections( fixture );
|
|
|
|
|
|
|
|
testUtils.overrideMwConfig( config );
|
|
|
|
testUtils.overrideParserData( data );
|
|
|
|
|
2020-07-20 21:15:03 +00:00
|
|
|
parser = new Parser( fixture );
|
|
|
|
comments = parser.getCommentItems();
|
2020-07-20 14:48:41 +00:00
|
|
|
|
|
|
|
transcludedFrom = {};
|
|
|
|
comments.forEach( function ( comment ) {
|
2020-07-20 21:15:03 +00:00
|
|
|
transcludedFrom[ comment.id ] = comment.getTranscludedFrom();
|
2020-07-20 14:48:41 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
transcludedFrom,
|
|
|
|
expected,
|
|
|
|
caseItem.name
|
|
|
|
);
|
|
|
|
|
|
|
|
// Uncomment this to get updated content for the JSON files, for copy/paste:
|
|
|
|
// console.log( JSON.stringify( transcludedFrom, null, 2 ) );
|
|
|
|
} );
|
|
|
|
} );
|