Henning Snater has uploaded a new change for review.

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


Change subject: [coordinate.js] Basic Coordinate object QUnit tests
......................................................................

[coordinate.js] Basic Coordinate object QUnit tests

Change-Id: Ib8c4b4ec14aef7cfe233635537e2026669c610fa
---
M DataValues/DataValues.tests.qunit.php
M DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
A DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
3 files changed, 180 insertions(+), 22 deletions(-)


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

diff --git a/DataValues/DataValues.tests.qunit.php 
b/DataValues/DataValues.tests.qunit.php
index 104de3a..16cc411 100644
--- a/DataValues/DataValues.tests.qunit.php
+++ b/DataValues/DataValues.tests.qunit.php
@@ -84,6 +84,7 @@
                        'scripts' => array(
                                
'resources/coordinate.js/tests/coordinate.tests.js',
                                
'resources/coordinate.js/tests/coordinate.parser.tests.js',
+                               
'resources/coordinate.js/tests/coordinate.Coordinate.tests.js',
                        ),
                        'dependencies' => array(
                                'coordinate.js',
diff --git a/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js 
b/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
index 4d4f7a5..689ccd9 100644
--- a/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
+++ b/DataValues/resources/coordinate.js/src/coordinate.Coordinate.js
@@ -139,24 +139,6 @@
                },
 
                /**
-                * Returns the latitude in degree.
-                *
-                * @return {Object}
-                */
-               latitudeDegree: function() {
-                       return coordinate.toDegree( this._latitude, 
this._precision );
-               },
-
-               /**
-                * Returns the longitude in degree.
-                *
-                * @return {Object}
-                */
-               longitudeDegree: function() {
-                       return coordinate.toDegree( this._longitude, 
this._precision );
-               },
-
-               /**
                 * Returns the decimal latitude.
                 *
                 * @return {Object}
@@ -175,12 +157,21 @@
                },
 
                /**
-                * Returns the coordinate as text in degree.
+                * Returns the latitude in degree.
                 *
-                * @return {string}
+                * @return {Object}
                 */
-               degreeText: function() {
-                       return coordinate.degreeText( this._latitude, 
this._longitude, this._precision );
+               latitudeDegree: function() {
+                       return coordinate.toDegree( this._latitude, 
this._precision );
+               },
+
+               /**
+                * Returns the longitude in degree.
+                *
+                * @return {Object}
+                */
+               longitudeDegree: function() {
+                       return coordinate.toDegree( this._longitude, 
this._precision );
                },
 
                /**
@@ -190,7 +181,17 @@
                 */
                decimalText: function() {
                        return coordinate.decimalText( this._latitude, 
this._longitude, this._precision );
+               },
+
+               /**
+                * Returns the coordinate as text in degree.
+                *
+                * @return {string}
+                */
+               degreeText: function() {
+                       return coordinate.degreeText( this._latitude, 
this._longitude, this._precision );
                }
+
        };
 
        return Coordinate;
diff --git 
a/DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js 
b/DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
new file mode 100644
index 0000000..183fa60
--- /dev/null
+++ b/DataValues/resources/coordinate.js/tests/coordinate.Coordinate.tests.js
@@ -0,0 +1,156 @@
+/**
+ * @since 0.1
+ * @file
+ * @ingroup coordinate.js
+ *
+ * @licence GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ */
+( function( QUnit, $, coordinate ) {
+       'use strict';
+
+       QUnit.module( 'coordinate.Coordinate.js' );
+
+       QUnit.test( 'Basic check', function( assert ) {
+               var c;
+
+               assert.throws(
+                       function() { var c = new coordinate.Coordinate( 'some 
string' ); },
+                       'Trying to instantiate with an invalid value throws an 
error.'
+               );
+
+               c = new coordinate.Coordinate( '1 1' );
+
+               // Since most methods are just plain getters, just doing plain 
verification:
+
+               assert.equal(
+                       c.getRawInput(),
+                       '1 1',
+                       'Verified getRawInput()'
+               );
+
+               assert.equal(
+                       c.getLatitude(),
+                       1,
+                       'Verified getLatitude()'
+               );
+
+               assert.equal(
+                       c.getLongitude(),
+                       1,
+                       'Verified getLongitude()'
+               );
+
+               assert.equal(
+                       c.getPrecision(),
+                       1,
+                       'Verified getPrecision()'
+               );
+
+               assert.equal(
+                       typeof c.getPrecisionText(),
+                       'string',
+                       'Verified getPrecisionText()'
+               );
+
+               assert.equal(
+                       typeof c.getPrecisionTextEarth(),
+                       'string',
+                       'Verified getPrecisionTextEarth()'
+               );
+
+               assert.equal(
+                       c.latitudeDecimal(),
+                       1,
+                       'Verified latitudeDecimal()'
+               );
+
+               assert.equal(
+                       c.longitudeDecimal(),
+                       1,
+                       'Verified longitudeDecimal()'
+               );
+
+               assert.deepEqual(
+                       c.latitudeDegree(),
+                       { degree: 1, minute: 0, second: 0 },
+                       'Verified latitudeDegree()'
+               );
+
+               assert.deepEqual(
+                       c.longitudeDegree(),
+                       { degree: 1, minute: 0, second: 0 },
+                       'Verified longitudeDegree()'
+               );
+
+               assert.equal(
+                       typeof c.decimalText(),
+                       'string',
+                       'Verified decimalText()'
+               );
+
+               assert.equal(
+                       typeof c.degreeText(),
+                       'string',
+                       'Verified degreeText()'
+               );
+
+       } );
+
+       QUnit.test( 'Precision handling', function( assert ) {
+               var c = new coordinate.Coordinate( '1 1.25' );
+
+               assert.equal(
+                       c.getPrecision(),
+                       0.01,
+                       'Increased precision'
+               );
+
+               c.decreasePrecision();
+               c.decreasePrecision();
+
+               assert.equal(
+                       c.getPrecision(),
+                       0.1,
+                       'Decreased precision'
+               );
+
+               assert.equal(
+                       c.longitudeDecimal(),
+                       1.3,
+                       'Verified applied precision'
+               );
+
+               c.increasePrecision();
+               c.increasePrecision();
+
+               assert.equal(
+                       c.getPrecision(),
+                       0.01,
+                       'Increased precision'
+               );
+
+               assert.equal(
+                       c.longitudeDecimal(),
+                       1.25,
+                       'Verified applied precision'
+               );
+
+               c.setPrecision( 1 );
+
+               assert.equal(
+                       c.getPrecision(),
+                       1,
+                       'Set precision'
+               );
+
+               assert.equal(
+                       c.longitudeDecimal(),
+                       1,
+                       'Verified applied precision'
+               );
+
+       } );
+
+
+}( QUnit, jQuery, coordinate ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8c4b4ec14aef7cfe233635537e2026669c610fa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>

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

Reply via email to