mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-28 07:33:04 +00:00
46484e8b53
* Declare variables inline, as per the current code conventions. * Convert ad-hoc cases objects into native QUnit.test.each(). This makes for shorter and cleaner code, as well as for more detailed test reporting, and removes the need to manually construct assertion messages based on test case prefix string etc. * Start adopting ES5 Array.forEach in a few places where otherwise ESLint would complain about variable name clashes. * Future proof the test module names, by stripping the global variable namespace that some classes still use, matching packageFiles convention as used for NotificationBadge.js and its tests already, by specifying only the bundle name and the exported class name. Note that the QUnit UI does fuzzy matching so filtering works the same either way, e.g. "echodmfilter" will match "ext.echo.dm - FilterModel". Change-Id: I49858dd2c95d0869f2cd15693f05c38312a9f710
113 lines
2.8 KiB
JavaScript
113 lines
2.8 KiB
JavaScript
QUnit.module( 'ext.echo.dm - BundleNotificationItem' );
|
|
|
|
QUnit.test( 'Constructing the model', function ( assert ) {
|
|
var 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' } )
|
|
];
|
|
var bundle = new mw.echo.dm.BundleNotificationItem(
|
|
100,
|
|
bundledItems,
|
|
{ modelName: 'foo' }
|
|
);
|
|
|
|
assert.strictEqual(
|
|
bundle.getCount(),
|
|
5,
|
|
'Bundled items added to internal list'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
bundle.getName(),
|
|
'foo',
|
|
'Bundle name stored'
|
|
);
|
|
|
|
assert.deepEqual(
|
|
bundle.getAllIds(),
|
|
[ 4, 3, 2, 1, 0 ],
|
|
'All ids present'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
bundle.isRead(),
|
|
false,
|
|
'Bundle with all unread items is unread'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
bundle.hasUnseen(),
|
|
true,
|
|
'Bundle has unseen items'
|
|
);
|
|
|
|
var findItems = bundle.findByIds( [ 1, 4 ] ).map( function ( item ) {
|
|
return item.getId();
|
|
} );
|
|
assert.deepEqual(
|
|
findItems,
|
|
[ 4, 1 ],
|
|
'findByIds fetches correct items in the default sorting order'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'Managing a list of items', function ( assert ) {
|
|
var 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' } )
|
|
];
|
|
var bundle = new mw.echo.dm.BundleNotificationItem(
|
|
100,
|
|
bundledItems,
|
|
{
|
|
name: 'foo'
|
|
}
|
|
);
|
|
|
|
assert.strictEqual(
|
|
bundle.hasUnseen(),
|
|
true,
|
|
'Bundle has unseen'
|
|
);
|
|
|
|
// Mark all items as seen
|
|
bundledItems.forEach( function ( item ) {
|
|
item.toggleSeen( true );
|
|
} );
|
|
|
|
assert.strictEqual(
|
|
bundle.hasUnseen(),
|
|
false,
|
|
'Bundle does not have unseen after all items marked as seen'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
bundle.isRead(),
|
|
false,
|
|
'Bundle is unread'
|
|
);
|
|
// Mark one item as read
|
|
bundledItems[ 0 ].toggleRead( true );
|
|
assert.strictEqual(
|
|
bundle.isRead(),
|
|
false,
|
|
'Bundle is still unread if it has some unread items'
|
|
);
|
|
|
|
// Mark all items as read
|
|
bundledItems.forEach( function ( item ) {
|
|
item.toggleRead( true );
|
|
} );
|
|
assert.strictEqual(
|
|
bundle.isRead(),
|
|
true,
|
|
'Bundle is marked as read if all items are read'
|
|
);
|
|
} );
|