mediawiki-extensions-Discus.../tests/qunit/ThreadItem.test.js
Ed Sanders dc8b4e8d4f Highlight all comments since the oldest in a thread bundle
For topic subscriptions, further restrict this to comments
in the same thread.

Bug: T302014
Change-Id: Ifba218871122901031a891034e709b886fc406da
2022-02-28 21:58:10 +00:00

44 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', 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.id = json.id;
item.replies = json.replies.map( newFromJSON );
return item;
}
cases.forEach( function ( caseItem ) {
var threadItem = newFromJSON( caseItem.thread ),
authors = threadItem.getAuthorsBelow();
assert.deepEqual(
authors,
caseItem.expectedAuthorsBelow,
'getAuthorsBelow'
);
assert.deepEqual(
threadItem.getThreadItemsBelow().map( function ( item ) { return item.id; } ),
caseItem.expectedThreadItemIdsBelow
);
} );
} );
// TODO:
// * getHeading (CommentItem+HeadingItem)
// * getLinkableTitle (HeadingItem)
// * newFromJSON (ThreadItem)