mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-12 08:35:37 +00:00
a74c00ba8c
This allows us to remove our `this` bindings. Change-Id: Ie8c8c38d36af8a033b5181870c39f8981a57b939
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
var
|
|
CommentItem = require( 'ext.discussionTools.init' ).CommentItem,
|
|
HeadingItem = require( 'ext.discussionTools.init' ).HeadingItem;
|
|
|
|
QUnit.module( 'mw.dt.ThreadItem', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( '#getAuthorsBelow/#getThreadItemsBelow', ( 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.displayName = json.displayName;
|
|
}
|
|
item.id = json.id;
|
|
item.replies = json.replies.map( newFromJSON );
|
|
return item;
|
|
}
|
|
|
|
cases.forEach( ( caseItem ) => {
|
|
var threadItem = newFromJSON( caseItem.thread ),
|
|
authors = threadItem.getAuthorsBelow();
|
|
|
|
assert.deepEqual(
|
|
authors,
|
|
caseItem.expectedAuthorsBelow,
|
|
'getAuthorsBelow'
|
|
);
|
|
|
|
assert.deepEqual(
|
|
threadItem.getThreadItemsBelow().map( ( item ) => {
|
|
return item.id;
|
|
} ),
|
|
caseItem.expectedThreadItemIdsBelow
|
|
);
|
|
} );
|
|
} );
|
|
|
|
// TODO:
|
|
// * getHeading (CommentItem+HeadingItem)
|
|
// * getLinkableTitle (HeadingItem)
|
|
// * newFromJSON (ThreadItem)
|