| 1 |
const |
| 2 |
CommentItem = require( 'ext.discussionTools.init' ).CommentItem, |
| 3 |
HeadingItem = require( 'ext.discussionTools.init' ).HeadingItem; |
| 4 |
|
| 5 |
QUnit.module( 'mw.dt.ThreadItem', QUnit.newMwEnvironment() ); |
| 6 |
|
| 7 |
QUnit.test( '#getAuthorsBelow/#getThreadItemsBelow', ( assert ) => { |
| 8 |
const cases = require( '../cases/authors.json' ); |
| 9 |
|
| 10 |
function newFromJSON( json ) { |
| 11 |
let item; |
| 12 |
if ( json.type === 'heading' ) { |
| 13 |
item = new HeadingItem(); |
| 14 |
} else { |
| 15 |
item = new CommentItem(); |
| 16 |
item.author = json.author; |
| 17 |
item.displayName = json.displayName; |
| 18 |
} |
| 19 |
item.id = json.id; |
| 20 |
item.replies = json.replies.map( newFromJSON ); |
| 21 |
return item; |
| 22 |
} |
| 23 |
|
| 24 |
cases.forEach( ( caseItem ) => { |
| 25 |
const threadItem = newFromJSON( caseItem.thread ), |
| 26 |
authors = threadItem.getAuthorsBelow(); |
| 27 |
|
| 28 |
assert.deepEqual( |
| 29 |
authors, |
| 30 |
caseItem.expectedAuthorsBelow, |
| 31 |
'getAuthorsBelow' |
| 32 |
); |
| 33 |
|
| 34 |
assert.deepEqual( |
| 35 |
threadItem.getThreadItemsBelow().map( ( item ) => item.id ), |
| 36 |
caseItem.expectedThreadItemIdsBelow |
| 37 |
); |
| 38 |
} ); |
| 39 |
} ); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|