| 1 |
QUnit.module( 'ext.echo.dm - BundleNotificationItem' ); |
| 2 |
|
| 3 |
QUnit.test( 'Constructing the model', ( assert ) => { |
| 4 |
const bundledItems = [ |
| 5 |
new mw.echo.dm.NotificationItem( 0, { read: false, seen: false, timestamp: '201601010000' } ), |
| 6 |
new mw.echo.dm.NotificationItem( 1, { read: false, seen: false, timestamp: '201601010100' } ), |
| 7 |
new mw.echo.dm.NotificationItem( 2, { read: false, seen: true, timestamp: '201601010200' } ), |
| 8 |
new mw.echo.dm.NotificationItem( 3, { read: false, seen: true, timestamp: '201601010300' } ), |
| 9 |
new mw.echo.dm.NotificationItem( 4, { read: false, seen: true, timestamp: '201601010400' } ) |
| 10 |
]; |
| 11 |
const bundle = new mw.echo.dm.BundleNotificationItem( |
| 12 |
100, |
| 13 |
bundledItems, |
| 14 |
{ modelName: 'foo' } |
| 15 |
); |
| 16 |
|
| 17 |
assert.strictEqual( |
| 18 |
bundle.getCount(), |
| 19 |
5, |
| 20 |
'Bundled items added to internal list' |
| 21 |
); |
| 22 |
|
| 23 |
assert.strictEqual( |
| 24 |
bundle.getName(), |
| 25 |
'foo', |
| 26 |
'Bundle name stored' |
| 27 |
); |
| 28 |
|
| 29 |
assert.deepEqual( |
| 30 |
bundle.getAllIds(), |
| 31 |
[ 4, 3, 2, 1, 0 ], |
| 32 |
'All ids present' |
| 33 |
); |
| 34 |
|
| 35 |
assert.strictEqual( |
| 36 |
bundle.isRead(), |
| 37 |
false, |
| 38 |
'Bundle with all unread items is unread' |
| 39 |
); |
| 40 |
|
| 41 |
assert.strictEqual( |
| 42 |
bundle.hasUnseen(), |
| 43 |
true, |
| 44 |
'Bundle has unseen items' |
| 45 |
); |
| 46 |
|
| 47 |
const findItems = bundle.findByIds( [ 1, 4 ] ).map( ( item ) => item.getId() ); |
| 48 |
assert.deepEqual( |
| 49 |
findItems, |
| 50 |
[ 4, 1 ], |
| 51 |
'findByIds fetches correct items in the default sorting order' |
| 52 |
); |
| 53 |
} ); |
| 54 |
|
| 55 |
QUnit.test( 'Managing a list of items', ( assert ) => { |
| 56 |
const bundledItems = [ |
| 57 |
new mw.echo.dm.NotificationItem( 0, { read: false, seen: false, timestamp: '201601010000' } ), |
| 58 |
new mw.echo.dm.NotificationItem( 1, { read: false, seen: false, timestamp: '201601010100' } ), |
| 59 |
new mw.echo.dm.NotificationItem( 2, { read: false, seen: true, timestamp: '201601010200' } ), |
| 60 |
new mw.echo.dm.NotificationItem( 3, { read: false, seen: true, timestamp: '201601010300' } ), |
| 61 |
new mw.echo.dm.NotificationItem( 4, { read: false, seen: true, timestamp: '201601010400' } ) |
| 62 |
]; |
| 63 |
const bundle = new mw.echo.dm.BundleNotificationItem( |
| 64 |
100, |
| 65 |
bundledItems, |
| 66 |
{ |
| 67 |
name: 'foo' |
| 68 |
} |
| 69 |
); |
| 70 |
|
| 71 |
assert.strictEqual( |
| 72 |
bundle.hasUnseen(), |
| 73 |
true, |
| 74 |
'Bundle has unseen' |
| 75 |
); |
| 76 |
|
| 77 |
|
| 78 |
bundledItems.forEach( ( item ) => { |
| 79 |
item.toggleSeen( true ); |
| 80 |
} ); |
| 81 |
|
| 82 |
assert.strictEqual( |
| 83 |
bundle.hasUnseen(), |
| 84 |
false, |
| 85 |
'Bundle does not have unseen after all items marked as seen' |
| 86 |
); |
| 87 |
|
| 88 |
assert.strictEqual( |
| 89 |
bundle.isRead(), |
| 90 |
false, |
| 91 |
'Bundle is unread' |
| 92 |
); |
| 93 |
|
| 94 |
bundledItems[ 0 ].toggleRead( true ); |
| 95 |
assert.strictEqual( |
| 96 |
bundle.isRead(), |
| 97 |
false, |
| 98 |
'Bundle is still unread if it has some unread items' |
| 99 |
); |
| 100 |
|
| 101 |
|
| 102 |
bundledItems.forEach( ( item ) => { |
| 103 |
item.toggleRead( true ); |
| 104 |
} ); |
| 105 |
assert.strictEqual( |
| 106 |
bundle.isRead(), |
| 107 |
true, |
| 108 |
'Bundle is marked as read if all items are read' |
| 109 |
); |
| 110 |
} ); |