2 QUnit
.module( 'mediawiki.track' );
4 QUnit
.test( 'track', 1, function ( assert
) {
6 mw
.trackSubscribe( 'simple', function ( topic
, data
) {
7 sequence
.push( [ topic
, data
] );
9 mw
.track( 'simple', { key
: 1 } );
10 mw
.track( 'simple', { key
: 2 } );
12 assert
.deepEqual( sequence
, [
13 [ 'simple', { key
: 1 } ],
14 [ 'simple', { key
: 2 } ]
15 ], 'Events after subscribing' );
18 QUnit
.test( 'trackSubscribe', 4, function ( assert
) {
21 mw
.track( 'before', { key
: 1 } );
22 mw
.track( 'before', { key
: 2 } );
23 mw
.trackSubscribe( 'before', function ( topic
, data
) {
24 sequence
.push( [ topic
, data
] );
26 mw
.track( 'before', { key
: 3 } );
28 assert
.deepEqual( sequence
, [
29 [ 'before', { key
: 1 } ],
30 [ 'before', { key
: 2 } ],
31 [ 'before', { key
: 3 } ]
32 ], 'Replay events from before subscribing' );
35 mw
.track( 'context', { key
: 0 } );
36 mw
.trackSubscribe( 'context', function ( topic
, data
) {
37 assert
.strictEqual( this.topic
, topic
, 'thisValue has topic' );
38 assert
.strictEqual( this.data
, data
, 'thisValue has data' );
39 assert
.assertTrue( this.timeStamp
>= now
, 'thisValue has sane timestamp' );
43 QUnit
.test( 'trackUnsubscribe', 1, function ( assert
) {
45 function unsubber( topic
, data
) {
46 sequence
.push( [ topic
, data
] );
49 mw
.track( 'unsub', { key
: 1 } );
50 mw
.trackSubscribe( 'unsub', unsubber
);
51 mw
.track( 'unsub', { key
: 2 } );
52 mw
.trackUnsubscribe( unsubber
);
53 mw
.track( 'unsub', { key
: 3 } );
55 assert
.deepEqual( sequence
, [
56 [ 'unsub', { key
: 1 } ],
57 [ 'unsub', { key
: 2 } ]
58 ], 'Stop when unsubscribing' );