2024-06-03 12:26:18 +00:00
|
|
|
QUnit.module( 'ext.echo.dm - NotificationItem', ( hooks ) => {
|
2024-06-03 12:22:48 +00:00
|
|
|
const fakeData = {
|
2022-05-13 18:16:14 +00:00
|
|
|
type: 'alert',
|
|
|
|
read: true,
|
|
|
|
seen: true,
|
|
|
|
timestamp: '2016-09-14T23:21:56Z',
|
|
|
|
content: {
|
|
|
|
header: 'Your edit on <strong>Moai</strong> was reverted.',
|
|
|
|
compactHeader: 'Your edit on <strong>Moai</strong> was reverted.',
|
|
|
|
body: 'undo'
|
2017-01-04 20:09:50 +00:00
|
|
|
},
|
2022-05-13 18:16:14 +00:00
|
|
|
iconType: 'revert',
|
|
|
|
primaryUrl: 'http://dev.wiki.local.wmftest.net:8080/w/index.php?title=Moai&oldid=prev&diff=1978&markasread=2126',
|
|
|
|
secondaryUrls: [
|
|
|
|
{
|
|
|
|
url: 'http://dev.wiki.local.wmftest.net:8080/wiki/User:RandomUser',
|
|
|
|
label: 'RandomUser',
|
|
|
|
icon: 'userAvatar'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: 'http://dev.wiki.local.wmftest.net:8080/wiki/Talk:Moai',
|
|
|
|
label: 'Moai',
|
|
|
|
tooltip: 'Talk:Moai',
|
|
|
|
icon: 'speechBubbles'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2024-06-03 12:22:48 +00:00
|
|
|
const now = 1234567890000;
|
|
|
|
const nowFormatted = '2009-02-13T23:31:30Z';
|
2016-09-16 00:05:04 +00:00
|
|
|
|
2023-06-02 15:09:38 +00:00
|
|
|
hooks.beforeEach( function () {
|
|
|
|
this.sandbox.useFakeTimers( now );
|
|
|
|
} );
|
2016-09-16 00:05:04 +00:00
|
|
|
|
2022-05-13 18:16:14 +00:00
|
|
|
QUnit.test.each( 'Constructing items', {
|
|
|
|
'Empty data': {
|
|
|
|
params: { id: 0, config: {} },
|
|
|
|
methods: 'all',
|
|
|
|
expected: { getId: 0, getAllIds: [ 0 ] }
|
|
|
|
},
|
|
|
|
'Fake data': {
|
|
|
|
params: { id: 999, config: fakeData },
|
|
|
|
methods: 'all',
|
|
|
|
expected: {
|
|
|
|
getId: 999,
|
|
|
|
getAllIds: [ 999 ],
|
|
|
|
getType: 'alert',
|
|
|
|
isRead: true,
|
|
|
|
isSeen: true,
|
|
|
|
getTimestamp: '2016-09-14T23:21:56Z',
|
|
|
|
getContentHeader: 'Your edit on <strong>Moai</strong> was reverted.',
|
|
|
|
getContentBody: 'undo',
|
|
|
|
getIconType: 'revert',
|
|
|
|
getPrimaryUrl: 'http://dev.wiki.local.wmftest.net:8080/w/index.php?title=Moai&oldid=prev&diff=1978&markasread=2126',
|
|
|
|
getSecondaryUrls: [
|
|
|
|
{
|
|
|
|
url: 'http://dev.wiki.local.wmftest.net:8080/wiki/User:RandomUser',
|
|
|
|
label: 'RandomUser',
|
|
|
|
icon: 'userAvatar'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: 'http://dev.wiki.local.wmftest.net:8080/wiki/Talk:Moai',
|
|
|
|
label: 'Moai',
|
|
|
|
tooltip: 'Talk:Moai',
|
|
|
|
icon: 'speechBubbles'
|
|
|
|
}
|
|
|
|
]
|
2016-09-16 00:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-03 12:26:18 +00:00
|
|
|
}, ( assert, data ) => {
|
2024-06-03 12:22:48 +00:00
|
|
|
const defaultValues = {
|
2022-05-13 18:16:14 +00:00
|
|
|
getId: undefined,
|
|
|
|
getContentHeader: '',
|
|
|
|
getContentBody: '',
|
|
|
|
getCategory: '',
|
|
|
|
getType: 'message',
|
|
|
|
isRead: false,
|
|
|
|
isSeen: false,
|
|
|
|
isForeign: false,
|
|
|
|
isBundled: false,
|
|
|
|
getTimestamp: nowFormatted,
|
|
|
|
getPrimaryUrl: undefined,
|
|
|
|
getIconURL: undefined,
|
|
|
|
getIconType: undefined,
|
|
|
|
getSecondaryUrls: [],
|
|
|
|
getModelName: 'local',
|
|
|
|
getAllIds: []
|
|
|
|
};
|
2024-06-03 12:22:48 +00:00
|
|
|
const expected = $.extend( true, {}, defaultValues, data.expected );
|
2022-05-13 18:16:14 +00:00
|
|
|
|
2024-06-03 12:22:48 +00:00
|
|
|
const itemModel = new mw.echo.dm.NotificationItem(
|
2022-05-13 18:16:14 +00:00
|
|
|
data.params.id,
|
|
|
|
data.params.config
|
|
|
|
);
|
|
|
|
|
2024-06-03 12:22:48 +00:00
|
|
|
const methods = ( data.methods === 'all' ? Object.keys( expected ) : data.methods );
|
2024-06-03 12:26:18 +00:00
|
|
|
methods.forEach( ( method ) => {
|
2022-05-13 18:16:14 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
// Run the method
|
|
|
|
itemModel[ method ](),
|
|
|
|
// Expected result
|
|
|
|
expected[ method ],
|
|
|
|
// Message
|
|
|
|
method
|
|
|
|
);
|
|
|
|
} );
|
2016-09-16 00:05:04 +00:00
|
|
|
} );
|
|
|
|
|
2024-06-03 12:26:18 +00:00
|
|
|
QUnit.test( 'Emitting update event', ( assert ) => {
|
2024-06-03 12:22:48 +00:00
|
|
|
const results = [];
|
|
|
|
const itemModel = new mw.echo.dm.NotificationItem( 0, $.extend( true, {}, fakeData, { seen: false, read: false } ) );
|
2016-09-16 00:05:04 +00:00
|
|
|
|
|
|
|
// Listen to update event
|
2024-06-03 12:26:18 +00:00
|
|
|
itemModel.on( 'update', () => {
|
2016-09-16 00:05:04 +00:00
|
|
|
results.push( [
|
|
|
|
itemModel.isRead(),
|
|
|
|
itemModel.isSeen()
|
|
|
|
] );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Trigger events
|
|
|
|
itemModel.toggleSeen( true ); // [ [ false, true ] ]
|
|
|
|
itemModel.toggleSeen( true ); // [ [ false, true ] ] ( No change, event was not emitted )
|
|
|
|
itemModel.toggleRead( true ); // [ [ false, true ], [ true, true ] ]
|
|
|
|
itemModel.toggleRead( true ); // [ [ false, true ], [ true, true ] ] ( No change, event was not emitted )
|
|
|
|
itemModel.toggleRead( false ); // [ [ false, true ], [ true, true ], [ false, true ] ]
|
|
|
|
itemModel.toggleSeen( false ); // [ [ false, true ], [ true, true ], [ false, true ], [ false, false ] ]
|
|
|
|
itemModel.toggleRead( true ); // [ [ false, true ], [ true, true ], [ false, true ], [ false, false ], [ true, false ] ]
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
results,
|
|
|
|
// Expected:
|
|
|
|
[ [ false, true ], [ true, true ], [ false, true ], [ false, false ], [ true, false ] ],
|
|
|
|
'Read and seen changes produced "update" events'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2023-06-02 15:09:38 +00:00
|
|
|
} );
|