2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-09-16 00:05:04 +00:00
|
|
|
QUnit.module( 'ext.echo.dm - mw.echo.dm.BundleNotificationItem' );
|
|
|
|
|
|
|
|
QUnit.test( 'Constructing the model', function ( assert ) {
|
|
|
|
var bundledItems = [
|
2016-11-18 21:16:43 +00:00
|
|
|
new mw.echo.dm.NotificationItem( 0, { read: false, seen: false, timestamp: '201601010000' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 1, { read: false, seen: false, timestamp: '201601010100' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 2, { read: false, seen: true, timestamp: '201601010200' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 3, { read: false, seen: true, timestamp: '201601010300' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 4, { read: false, seen: true, timestamp: '201601010400' } )
|
|
|
|
],
|
|
|
|
bundle = new mw.echo.dm.BundleNotificationItem(
|
|
|
|
100,
|
|
|
|
bundledItems,
|
|
|
|
{ modelName: 'foo' }
|
|
|
|
);
|
2016-09-16 00:05:04 +00:00
|
|
|
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.getCount(),
|
|
|
|
5,
|
|
|
|
'Bundled items added to internal list'
|
|
|
|
);
|
|
|
|
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.getName(),
|
|
|
|
'foo',
|
|
|
|
'Bundle name stored'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
bundle.getAllIds(),
|
|
|
|
[ 4, 3, 2, 1, 0 ],
|
|
|
|
'All ids present'
|
|
|
|
);
|
|
|
|
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.isRead(),
|
|
|
|
false,
|
|
|
|
'Bundle with all unread items is unread'
|
|
|
|
);
|
|
|
|
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.hasUnseen(),
|
|
|
|
true,
|
|
|
|
'Bundle has unseen items'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
( function () {
|
|
|
|
var findItems = bundle.findByIds( [ 1, 4 ] );
|
|
|
|
return findItems.map( function ( item ) {
|
|
|
|
return item.getId();
|
|
|
|
} );
|
2016-11-18 21:16:43 +00:00
|
|
|
}() ),
|
2016-09-16 00:05:04 +00:00
|
|
|
[ 4, 1 ],
|
|
|
|
'findByIds fetches correct items in the default sorting order'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'Managing a list of items', function ( assert ) {
|
|
|
|
var i,
|
|
|
|
bundledItems = [
|
|
|
|
new mw.echo.dm.NotificationItem( 0, { read: false, seen: false, timestamp: '201601010000' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 1, { read: false, seen: false, timestamp: '201601010100' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 2, { read: false, seen: true, timestamp: '201601010200' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 3, { read: false, seen: true, timestamp: '201601010300' } ),
|
|
|
|
new mw.echo.dm.NotificationItem( 4, { read: false, seen: true, timestamp: '201601010400' } )
|
|
|
|
],
|
|
|
|
bundle = new mw.echo.dm.BundleNotificationItem(
|
|
|
|
100,
|
|
|
|
bundledItems,
|
|
|
|
{
|
|
|
|
name: 'foo'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.hasUnseen(),
|
|
|
|
true,
|
|
|
|
'Bundle has unseen'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Mark all items as seen
|
|
|
|
for ( i = 0; i < bundledItems.length; i++ ) {
|
|
|
|
bundledItems[ i ].toggleSeen( true );
|
|
|
|
}
|
|
|
|
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.hasUnseen(),
|
|
|
|
false,
|
|
|
|
'Bundle does not have unseen after all items marked as seen'
|
|
|
|
);
|
|
|
|
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.isRead(),
|
|
|
|
false,
|
|
|
|
'Bundle is unread'
|
|
|
|
);
|
|
|
|
// Mark one item as read
|
|
|
|
bundledItems[ 0 ].toggleRead( true );
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.isRead(),
|
|
|
|
false,
|
|
|
|
'Bundle is still unread if it has some unread items'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Mark all items as read
|
|
|
|
for ( i = 0; i < bundledItems.length; i++ ) {
|
|
|
|
bundledItems[ i ].toggleRead( true );
|
|
|
|
}
|
2018-09-11 22:46:52 +00:00
|
|
|
assert.strictEqual(
|
2016-09-16 00:05:04 +00:00
|
|
|
bundle.isRead(),
|
|
|
|
true,
|
|
|
|
'Bundle is marked as read if all items are read'
|
|
|
|
);
|
|
|
|
} );
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|