| 1 |
QUnit.module( 'ext.echo.dm - UnreadNotificationCounter' ); |
| 2 |
|
| 3 |
QUnit.test.each( '.getCappedNotificationCount()', [ |
| 4 |
{ input: 5, output: 5 }, |
| 5 |
{ input: 20, output: 11 }, |
| 6 |
{ input: 10, output: 10 } |
| 7 |
], ( assert, data ) => { |
| 8 |
const model = new mw.echo.dm.UnreadNotificationCounter( |
| 9 |
null, |
| 10 |
'all', |
| 11 |
10 |
| 12 |
); |
| 13 |
assert.strictEqual( |
| 14 |
model.getCappedNotificationCount( data.input ), |
| 15 |
data.output, |
| 16 |
'count for ' + data.input |
| 17 |
); |
| 18 |
} ); |
| 19 |
|
| 20 |
QUnit.test( '.estimateChange()', ( assert ) => { |
| 21 |
const model = new mw.echo.dm.UnreadNotificationCounter( |
| 22 |
null, |
| 23 |
'all', |
| 24 |
99 |
| 25 |
); |
| 26 |
|
| 27 |
model.setCount( 50 ); |
| 28 |
|
| 29 |
model.estimateChange( -10 ); |
| 30 |
assert.strictEqual( |
| 31 |
model.getCount(), |
| 32 |
40, |
| 33 |
'Estimation within range' |
| 34 |
); |
| 35 |
|
| 36 |
model.estimateChange( 70 ); |
| 37 |
assert.strictEqual( |
| 38 |
model.getCount(), |
| 39 |
100, |
| 40 |
'Estimation brings count to cap' |
| 41 |
); |
| 42 |
|
| 43 |
model.estimateChange( -10 ); |
| 44 |
assert.strictEqual( |
| 45 |
model.getCount(), |
| 46 |
100, |
| 47 |
'Estimation while counter is outside of cap - no change' |
| 48 |
); |
| 49 |
} ); |
| 50 |
|
| 51 |
QUnit.test( '.setCount()', ( assert ) => { |
| 52 |
const results = []; |
| 53 |
const model = new mw.echo.dm.UnreadNotificationCounter( |
| 54 |
null, |
| 55 |
'all', |
| 56 |
99 |
| 57 |
); |
| 58 |
|
| 59 |
|
| 60 |
model.on( 'countChange', ( count ) => { |
| 61 |
results.push( count ); |
| 62 |
} ); |
| 63 |
|
| 64 |
|
| 65 |
model.setCount( 50 ); |
| 66 |
model.setCount( 300, true ); |
| 67 |
model.setCount( -1, true ); |
| 68 |
model.setCount( 200 ); |
| 69 |
model.setCount( 10 ); |
| 70 |
|
| 71 |
assert.deepEqual( |
| 72 |
results, |
| 73 |
[ 50, 100, 10 ], |
| 74 |
'countChange events emitted.' |
| 75 |
); |
| 76 |
} ); |