Debian Codegraph @

extensions/Echo/tests/qunit/model/test_mw.echo.dm.UnreadNotificationCounter.js

raw symbols SCIP
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', // type
11 10 // max
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', // type
24 99 // max
25 );
26 // Set initial
27 model.setCount( 50 );
28
29 model.estimateChange( -10 );
30 assert.strictEqual(
31 model.getCount(),
32 40, // 50-10
33 'Estimation within range'
34 );
35
36 model.estimateChange( 70 );
37 assert.strictEqual(
38 model.getCount(),
39 100, // Estimation reached above cap - cap is set
40 'Estimation brings count to cap'
41 );
42
43 model.estimateChange( -10 );
44 assert.strictEqual(
45 model.getCount(),
46 100, // We are already above cap, count will not change
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', // type
56 99 // max
57 );
58
59 // Listen to event
60 model.on( 'countChange', ( count ) => {
61 results.push( count );
62 } );
63
64 // Trigger events
65 model.setCount( 50 ); // [ 50 ]
66 model.setCount( 300, true ); // (estimate, above max, bring to cap) [ 50, 100 ]
67 model.setCount( -1, true ); // (estimate while counter is above cap, no event) [ 50, 100 ]
68 model.setCount( 200 ); // (setting above cap, value is capped, same as current, no event) [ 50,100 ]
69 model.setCount( 10 ); // [ 50, 100, 10 ]
70
71 assert.deepEqual(
72 results,
73 [ 50, 100, 10 ],
74 'countChange events emitted.'
75 );
76 } );