2022-05-13 18:16:14 +00:00
|
|
|
QUnit.module( 'ext.echo.dm - SeenTimeModel' );
|
|
|
|
|
2024-06-03 12:26:18 +00:00
|
|
|
QUnit.test( '.getTypes()', ( assert ) => {
|
2024-06-03 12:22:48 +00:00
|
|
|
const model = new mw.echo.dm.SeenTimeModel();
|
2022-05-13 18:16:14 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
model.getTypes(),
|
|
|
|
[ 'alert', 'message' ],
|
|
|
|
'Default model has both types'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2024-06-03 12:26:18 +00:00
|
|
|
QUnit.test( '.setSeenTime() reflected', ( assert ) => {
|
2024-06-03 12:22:48 +00:00
|
|
|
let model;
|
2022-05-13 18:16:14 +00:00
|
|
|
|
|
|
|
model = new mw.echo.dm.SeenTimeModel();
|
|
|
|
model.setSeenTime( '20160101010000' );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
model.getSeenTime(),
|
|
|
|
'20160101010000',
|
|
|
|
'Model sets seen time for both types'
|
|
|
|
);
|
|
|
|
|
|
|
|
model = new mw.echo.dm.SeenTimeModel( { types: 'alert' } );
|
|
|
|
model.setSeenTime( '20160101010001' );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
model.getSeenTime(),
|
|
|
|
'20160101010001',
|
|
|
|
'Alerts seen time model returns correct time'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2024-06-03 12:26:18 +00:00
|
|
|
QUnit.test( '.setSeenTime() events', ( assert ) => {
|
2024-06-03 12:22:48 +00:00
|
|
|
const results = [];
|
|
|
|
const model = new mw.echo.dm.SeenTimeModel();
|
2022-05-13 18:16:14 +00:00
|
|
|
|
|
|
|
// Attach a listener
|
2024-06-03 12:26:18 +00:00
|
|
|
model.on( 'update', ( time ) => {
|
2022-05-13 18:16:14 +00:00
|
|
|
results.push( time );
|
2016-09-16 00:05:04 +00:00
|
|
|
} );
|
|
|
|
|
2022-05-13 18:16:14 +00:00
|
|
|
// Trigger events
|
|
|
|
model.setSeenTime( '1' ); // [ '1' ]
|
|
|
|
model.setSeenTime( '2' ); // [ '1', '2' ]
|
|
|
|
model.setSeenTime( '2' ); // (no change, no event) [ '1', '2' ]
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
results,
|
|
|
|
[ '1', '2' ],
|
|
|
|
'events emitted'
|
|
|
|
);
|
|
|
|
} );
|