Inchikutty has uploaded a new change for review.
https://gerrit.wikimedia.org/r/155511
Change subject: [WIP]Add unit tests to mw.GeoMap.js and some fixes
......................................................................
[WIP]Add unit tests to mw.GeoMap.js and some fixes
unit tests, dynamic map on static map hover,sets accept-language to 'en'
on address search and some other fixes.
Bug: 56612
Change-Id: I870cf6769fba2fee4b51b7bd80b136fe0be62e7d
---
M UploadWizardHooks.php
M resources/mw.GeoMap.js
M resources/mw.UploadWizardDetails.js
A tests/qunit/mw.GeoMap.test.js
4 files changed, 37 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/11/155511/1
diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php
index 466cdf8..74530e4 100644
--- a/UploadWizardHooks.php
+++ b/UploadWizardHooks.php
@@ -670,6 +670,7 @@
'tests/qunit/mw.UploadWizard.test.js',
'tests/qunit/mw.UploadWizardLicenseInput.test.js',
'tests/qunit/mw.FlickrChecker.test.js',
+ 'tests/qunit/mw.GeoMap.test.js',
),
'dependencies' => array(
'ext.uploadWizard',
diff --git a/resources/mw.GeoMap.js b/resources/mw.GeoMap.js
index 726a283..20faf65 100644
--- a/resources/mw.GeoMap.js
+++ b/resources/mw.GeoMap.js
@@ -3,6 +3,7 @@
* @class mw.GeoMap
* @requires leaflet
* @param {jQuery} $form
+ * @param UploadWizardUpload upload
*
* Wraps a {@link leaflet} map in UploadWizard using the [Leaflet
API](http://leaflet.cloudmade.com/reference.html).
*
@@ -11,20 +12,20 @@
*/
( function ( mw, $ ) {
-mw.GeoMap = function ( $form ) {
+mw.GeoMap = function ( $form, upload ) {
var geo = this;
geo.$form = $form;
+ geo.index = upload.index;
geo.isGeoMapInitialized = false;
geo.map = null;
geo.address = '';
geo.zoom = 8;
- mw.GeoMap.mapId = ( mw.GeoMap.mapId || 0 ) + 1;
- geo.geoLocation = $( '<div>' ).attr( 'id', 'mwe-loc-map' +
mw.GeoMap.mapId )
+ geo.geoLocation = $( '<div>' ).attr( 'id', 'mwe-loc-map' + geo.index )
.append( $( '<div>' ).addClass( 'mwe-loc-map' ).attr( { id:
'simpleSearch' } )
.append( $( '<input>' ).attr( { type: 'text', size: 41,
id: 'searchInput', placeholder: 'Search a place', name: 'searchPlace' } ),
$( '<input>' ).addClass( 'searchButton' ).attr(
{ type: 'button', id: 'searchButton', name:'searchButton' } ) ) );
- geo.mapDiv = $( '<div>' ).addClass( 'mwe-loc-map' ).attr( 'id',
'mwe-location-map' + mw.GeoMap.mapId );
+ geo.mapDiv = $( '<div>' ).addClass( 'mwe-loc-map' ).attr( 'id',
'mwe-location-map' + geo.index );
var geoMapDiv = $( '<div>' ).addClass( 'mwe-location-map' ).append(
geo.geoLocation, geo.mapDiv );
geo.$form.find( '.mwe-location-label' ).append( geoMapDiv );
@@ -85,16 +86,9 @@
geo.mapDiv.addClass( 'mwe-upwiz-status-progress' );
var link = geo.staticMapLink( latVal, lonVal );
$( '<img>' ).attr( 'src', link ).addClass( 'mwe-loc-map'
).appendTo( geo.mapDiv )
- .click( function () {
+ .on( 'click mouseenter', function () {
geo.mapRemove();
geo.geoMapInit( latVal, lonVal );
- } );
- $( '<div>' ).addClass( 'mwe-loc-link' ).text( 'Click on image
to open leaflet map' ).appendTo( geo.mapDiv ).hide();
- geo.mapDiv.on( 'mouseenter', function () {
- $( this ).find( '.mwe-loc-link' ).show();
- } );
- geo.mapDiv.on( 'mouseleave', function () {
- $( this ).find( '.mwe-loc-link' ).hide();
} );
},
@@ -134,7 +128,7 @@
this.map.remove();
this.map = null;
this.mapDiv.removeClass( 'leaflet-container
leaflet-fade-anim' );
- this.osm[ mw.GeoMap.mapId ] = false;
+ this.osm[ this.index ] = false;
}
else {
this.mapDiv.removeClass( 'mwe-upwiz-status-progress' );
@@ -152,7 +146,7 @@
$list.eq( 0 ).val( latlng.lat.toFixed( 4 ) );
$list.eq( 1 ).val( latlng.lng.toFixed( 4 ) );
$list.trigger( 'uw-copy' );
- this.osm[ mw.GeoMap.mapId ] = true;
+ this.osm[ this.index ] = true;
this.markMapView( latlng );
}
},
@@ -197,7 +191,7 @@
*/
reverseGeocodingUrl: function ( latVal, lonVal ) {
var mapLink = new mw.Uri(
'http://nominatim.openstreetmap.org/reverse?' )
- .extend( { format: 'json', lat: latVal, lon: lonVal,
addressdetails: 1 } );
+ .extend( { format: 'json', lat: latVal, lon: lonVal,
addressdetails: 1, 'accept-language': 'en' } );
return mapLink.toString();
},
diff --git a/resources/mw.UploadWizardDetails.js
b/resources/mw.UploadWizardDetails.js
index 9605e16..60994e8 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -280,7 +280,7 @@
moreDetailsCtrlDiv,
moreDetailsDiv
);
- this.map = new mw.GeoMap( this.$form );
+ this.map = new mw.GeoMap( this.$form, this.upload );
this.submittingDiv = $( '<div>' ).addClass( 'mwe-upwiz-submitting' )
.append(
@@ -1339,7 +1339,7 @@
// while it's actually unknown.
// When none is provided, this will result in
{{Location dec|int|int|}}.
if( Number( lat ) && Number ( lon ) ) {
- if ( mw.GeoMap.prototype.osm[
details.upload.index+1 ] ) {
+ if ( mw.GeoMap.prototype.osm[
details.upload.index ] ) {
wikiText += '{{Location dec|' + lat +
'|' + lon + '|' + 'source=osm' + '}}\n';
}
else {
diff --git a/tests/qunit/mw.GeoMap.test.js b/tests/qunit/mw.GeoMap.test.js
new file mode 100644
index 0000000..3f394a4
--- /dev/null
+++ b/tests/qunit/mw.GeoMap.test.js
@@ -0,0 +1,25 @@
+( function ( mw ) {
+
+ QUnit.module( 'mw.GeoMap', QUnit.newMwEnvironment() );
+
+ /*QUnit.test( 'Object test', 1, function ( assert ) {
+ var wizard, upload, $form, uwMap;
+
+ wizard = new mw.UploadWizard( {} );
+ upload = new mw.UploadWizardUpload( wizard);
+ upload.index = 1;
+ $form = new mw.UploadWizardDetails( wizard);
+ uwMap = new mw.GeoMap( $form, upload );
+ assert.ok( uwMap, 'Map object created !' );
+ } );*/
+
+ QUnit.test( 'staticMapLink()', 1, function ( assert ) {
+ assert.ok( 'staticMapLink( 15, 75 )', 'valid parameters' );
+ } );
+
+ QUnit.test( 'staticMap()', 1, function ( assert ) {
+
+ assert.ok( $( '.mwe-loc-map' ).find( '<img>' ), 'Image
created.' );
+ } );
+
+}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/155511
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I870cf6769fba2fee4b51b7bd80b136fe0be62e7d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: osm2
Gerrit-Owner: Inchikutty <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits