Update namespace aliases for Luri (lrc) from translatewiki
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.track.test.js
1 ( function ( mw ) {
2 QUnit.module( 'mediawiki.track' );
3
4 QUnit.test( 'track', 1, function ( assert ) {
5 var sequence = [];
6 mw.trackSubscribe( 'simple', function ( topic, data ) {
7 sequence.push( [ topic, data ] );
8 } );
9 mw.track( 'simple', { key: 1 } );
10 mw.track( 'simple', { key: 2 } );
11
12 assert.deepEqual( sequence, [
13 [ 'simple', { key: 1 } ],
14 [ 'simple', { key: 2 } ]
15 ], 'Events after subscribing' );
16 } );
17
18 QUnit.test( 'trackSubscribe', 4, function ( assert ) {
19 var now,
20 sequence = [];
21 mw.track( 'before', { key: 1 } );
22 mw.track( 'before', { key: 2 } );
23 mw.trackSubscribe( 'before', function ( topic, data ) {
24 sequence.push( [ topic, data ] );
25 } );
26 mw.track( 'before', { key: 3 } );
27
28 assert.deepEqual( sequence, [
29 [ 'before', { key: 1 } ],
30 [ 'before', { key: 2 } ],
31 [ 'before', { key: 3 } ]
32 ], 'Replay events from before subscribing' );
33
34 now = mw.now();
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' );
40 } );
41 } );
42 }( mediaWiki ) );