Daniel Werner has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/60809


Change subject: Added QUnit tests for DataType constructor and instances
......................................................................

Added QUnit tests for DataType constructor and instances

Change-Id: I08bbbbf6d52b78e63ca5f22600aaa01aae9657e0
---
M DataTypes/DataTypes.mw.php
A DataTypes/tests/qunit/dataTypes.DataType.tests.js
M DataTypes/tests/qunit/dataTypes.tests.js
3 files changed, 105 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues 
refs/changes/09/60809/1

diff --git a/DataTypes/DataTypes.mw.php b/DataTypes/DataTypes.mw.php
index 1a91095..39d7c68 100644
--- a/DataTypes/DataTypes.mw.php
+++ b/DataTypes/DataTypes.mw.php
@@ -109,7 +109,7 @@
                'remoteExtPath' => 'DataValues/DataTypes/tests/qunit',
        );
 
-       $testModules['qunit']['jquery.dataTypes.tests'] = $moduleTemplate + 
array(
+       $testModules['qunit']['dataTypes.tests'] = $moduleTemplate + array(
                'scripts' => array(
                        'dataTypes.tests.js',
                ),
@@ -118,6 +118,16 @@
                ),
        );
 
+       $testModules['qunit']['dataTypes.DataType.tests'] = $moduleTemplate + 
array(
+               'scripts' => array(
+                       'dataTypes.DataType.tests.js',
+               ),
+               'dependencies' => array(
+                       'dataTypes',
+                       'qunit.parameterize'
+               ),
+       );
+
        return true;
 };
 
diff --git a/DataTypes/tests/qunit/dataTypes.DataType.tests.js 
b/DataTypes/tests/qunit/dataTypes.DataType.tests.js
new file mode 100644
index 0000000..59d3bce
--- /dev/null
+++ b/DataTypes/tests/qunit/dataTypes.DataType.tests.js
@@ -0,0 +1,90 @@
+/**
+ * QUnit tests for DataType construtor and instances.
+ *
+ * @since 0.1
+ * @file
+ * @ingroup DataTypes
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Werner < [email protected] >
+ */
+
+( function( dt, $, QUnit ) {
+       'use strict';
+
+       var DataType = dt.DataType;
+
+       QUnit.module( 'dataTypes.DataType.tests' );
+
+       var instanceDefinitions = [
+               {
+                       title: 'simple DataType',
+                       constructorParams: [ 'foo', 'string' ],
+                       valueType: 'string'
+               }, {
+                       title: 'another simple datatype',
+                       constructorParams: [ 'bar', 'bool' ],
+                       valueType: 'bool'
+               }
+       ];
+
+       function instanceFromDefinition( definition ) {
+               var cp = definition.constructorParams;
+               return new DataType( cp[0], cp[1] );
+       }
+
+       QUnit
+       .cases( instanceDefinitions )
+               .test( 'constructor', function( params, assert ) {
+                       var dataType = instanceFromDefinition( params );
+
+                       assert.ok(
+                               dataType instanceof DataType,
+                               'New data type created and instance of DataType'
+                       );
+               } )
+               .test( 'getId', function( params, assert ) {
+                       var dataType = instanceFromDefinition( params );
+
+                       assert.strictEqual(
+                               dataType.getId(),
+                               params.constructorParams[0],
+                               'getId() returns string ID provided in 
constructor'
+                       );
+               } )
+               .test( 'getDataValueType', function( params, assert ) {
+                       var dataType = instanceFromDefinition( params ),
+                               dvType = dataType.getDataValueType();
+
+                       assert.equal(
+                               typeof dvType,
+                               'string',
+                               'getDataValueType() returns string'
+                       );
+
+                       assert.ok(
+                               dvType !== '',
+                               'string returned by getDataValueType() is not 
empty'
+                       );
+               } );
+
+       QUnit
+       .cases( [
+               {
+                       title: 'no arguments',
+                       constructorParams: []
+               }, {
+                       title: 'missing data value type',
+                       constructorParams: [ 'foo' ]
+               }
+       ] )
+               .test( 'invalid construtor arguments', function( params, assert 
) {
+                       assert.throws(
+                               function() {
+                                       instanceFromDefinition( params );
+                               },
+                               'DataType can not be constructed from invalid 
arguments'
+                       );
+               } );
+
+}( dataTypes, jQuery, QUnit ) );
diff --git a/DataTypes/tests/qunit/dataTypes.tests.js 
b/DataTypes/tests/qunit/dataTypes.tests.js
index c8c7786..7b3d637 100644
--- a/DataTypes/tests/qunit/dataTypes.tests.js
+++ b/DataTypes/tests/qunit/dataTypes.tests.js
@@ -1,6 +1,5 @@
 /**
- * QUnit tests for DataTypes data type store/factory
- * @see https://www.mediawiki.org/wiki/Extension:Wikibase
+ * QUnit tests for DataTypes's dataType store/factory (global dataType object).
  *
  * @since 0.1
  * @file
@@ -10,10 +9,10 @@
  * @author H. Snater < [email protected] >
  */
 
-( function( mw, dt, dv, $, QUnit, undefined ) {
+( function( dt, dv, $, QUnit ) {
        'use strict';
 
-       QUnit.module( 'dataTypes.tests', QUnit.newMwEnvironment() );
+       QUnit.module( 'dataTypes.tests' );
 
        QUnit.test( 'Test initializing a DataType object', function( assert ) {
                // create new data type for testing and register it:
@@ -38,4 +37,4 @@
                );
        } );
 
-}( mediaWiki, dataTypes, dataValues, jQuery, QUnit ) );
+}( dataTypes, dataValues, jQuery, QUnit ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/60809
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I08bbbbf6d52b78e63ca5f22600aaa01aae9657e0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to