r89916 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89915‎ | r89916 | r89917 >
Date:05:20, 12 June 2011
Author:neilk
Status:resolved (Comments)
Tags:
Comment:
tests for pubsub and units.bytes
Modified paths:
  • /trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mw.pubsub.spec.js (added) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mw.units.spec.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html
@@ -20,6 +20,7 @@
2121 <script type="text/javascript" src="../../resources/mw.Api.edit.js"></script>
2222 <script type="text/javascript" src="../../resources/mw.Title.js"></script>
2323 <script type="text/javascript" src="../../resources/mw.units.js"></script>
 24+ <script type="text/javascript" src="../../resources/jquery/jquery.pubsub.js"></script>
2425
2526 <script type="text/javascript" src="spec/mediawiki.language.parser.spec.data.js"></script>
2627
@@ -33,6 +34,7 @@
3435
3536 <script type="text/javascript" src="spec/mw.Title.spec.js"></script>
3637 <script type="text/javascript" src="spec/mw.units.spec.js"></script>
 38+ <script type="text/javascript" src="spec/mw.pubsub.spec.js"></script>
3739
3840 </head>
3941 <body>
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mw.pubsub.spec.js
@@ -0,0 +1,52 @@
 2+( function( mw, $ ) {
 3+ describe( "mw.pubsub", function() {
 4+
 5+ it( "should allow subscription", function() {
 6+ var sub1data = [ 'foo', 'bar' ];
 7+ var result;
 8+ $.subscribe( 'sub1', function( arg ) {
 9+ result = arg;
 10+ } );
 11+ $.publish( 'sub1', sub1data );
 12+ expect( result ).toBe( sub1data );
 13+ } );
 14+
 15+ it( "should allow multiple subscription", function() {
 16+ var sub1data = [ 'foo', 'bar' ];
 17+ var result;
 18+ var result2;
 19+ $.subscribe( 'sub1', function( arg ) {
 20+ result = arg;
 21+ } );
 22+ $.subscribe( 'sub1', function( arg ) {
 23+ result2 = arg;
 24+ } );
 25+ $.publish( 'sub1', sub1data );
 26+ expect( result ).toBe( sub1data );
 27+ expect( result2 ).toBe( sub1data );
 28+ } );
 29+
 30+ it( "should allow timeline subscription with publishing after subscription", function() {
 31+ var sub2data = [ 'quux', 'pif' ];
 32+ var result;
 33+ $.subscribeTimeline( 'sub2', function( arg ) {
 34+ result = arg;
 35+ } );
 36+ $.publishTimeline( 'sub2', sub2data );
 37+ expect( result ).toBe( sub2data );
 38+ } );
 39+
 40+
 41+ it( "should allow timeline subscription with subscription after publishing", function() {
 42+ var sub3data = [ 'paf', 'klortho' ];
 43+ var result;
 44+ $.publishTimeline( 'sub3', sub3data );
 45+ $.subscribeTimeline( 'sub3', function( arg ) {
 46+ result = arg;
 47+ } );
 48+ expect( result ).toBe( sub3data );
 49+ } );
 50+
 51+ } );
 52+
 53+} )( mediaWiki, jQuery );
Property changes on: trunk/extensions/UploadWizard/test/jasmine/spec/mw.pubsub.spec.js
___________________________________________________________________
Added: svn:eol-style
154 + native
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mw.units.spec.js
@@ -16,28 +16,44 @@
1717 expect( mw.units.bytes( 0 ) ).toEqual( '0 bytes' );
1818 } );
1919
20 - it( "should say 7 bytes", function() {
 20+ it( "should say bytes", function() {
2121 expect( mw.units.bytes( 7 ) ).toEqual( '7 bytes' );
2222 } );
2323
24 - it( "should say 900 bytes", function() {
 24+ it( "should say bytes (900)", function() {
2525 expect( mw.units.bytes( 900 ) ).toEqual( '900 bytes' );
2626 } );
2727
28 - it( "should say 1 K", function() {
 28+ it( "should say 1023 = 1023 bytes", function() {
 29+ expect( mw.units.bytes( 1023 ) ).toEqual( '1023 bytes' );
 30+ } );
 31+
 32+ it( "should say 1024 = 1K", function() {
2933 expect( mw.units.bytes( 1024 ) ).toEqual( '1 K' );
3034 } );
3135
32 - it( "should say 2.00 MB", function() {
 36+ it( "should say MB", function() {
3337 expect( mw.units.bytes( 2 * 1024 * 1024 ) ).toEqual( '2.00 MB' );
3438 } );
3539
36 - it( "should say 3.14 GB", function() {
 40+ it( "should say GB", function() {
3741 expect( mw.units.bytes( 3.141592 * 1024 * 1024 * 1024 ) ).toEqual( '3.14 GB' );
3842 } );
3943
 44+ it( "should say TB", function() {
 45+ expect( mw.units.bytes( 3.141592 * 1024 * 1024 * 1024 * 1024 ) ).toEqual( '3.14 TB' );
 46+ } );
4047
 48+ it( "should say TB even when much larger", function() {
 49+ expect( mw.units.bytes( 3.141592 * 1024 * 1024 * 1024 * 1024 * 1024 ) ).toEqual( '3216.99 TB' );
 50+ } );
4151
 52+
 53+ it( "should round up", function() {
 54+ expect( mw.units.bytes( 1.42857 * 1024 * 1024 * 1024 ) ).toEqual( '1.43 GB' );
 55+ } );
 56+
 57+
4258 } );
4359
4460 } )( mediaWiki );

Follow-up revisions

RevisionCommit summaryAuthorDate
r89998revert r89966, also remove terabytes so we can use system core messages, also...neilk19:08, 13 June 2011
r89999renamed "timeline" test cases, which are now called "ready" events. Added tes...neilk19:20, 13 June 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:21, 12 June 2011
+it( "should say 1024 = 1K", function() { 
 expect( mw.units.bytes( 1024 ) ).toEqual( '1 K' );

Kelvins? Should be kB or KB or heck, even KiB :) Comment should have a space between 1 and K. Imho those should be non-breaking spaces even.

#Comment by NeilK (talk | contribs)   19:23, 13 June 2011

now using the system messages, so it says KB

#Comment by Brion VIBBER (talk | contribs)   17:49, 13 June 2011

There's no tests for the pubsub 'ready' variants added in r89913. As noted above, expect also 'KB' rather than 'K' for consistency with 'MB', 'GB', 'TB', etc.

#Comment by NeilK (talk | contribs)   19:22, 13 June 2011

fix

#Comment by NeilK (talk | contribs)   19:23, 13 June 2011

fixed as noted in associated revs.

Status & tagging log