Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write tests that assert the markers are shown or hidden as in the new example code #52

Merged
merged 15 commits into from
Apr 2, 2019
Merged
21 changes: 18 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ module.exports = function(grunt) {
src: "src/client/js/*.js",
options: {
specs: "spec/javascripts/*spec.js",
vendor: ['node_modules/jquery/dist/jquery.js','dist/Leaflet.BlurredLocationDisplay.js','node_modules/jasmine-jquery/lib/jasmine-jquery.js'],
vendor: [
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/jasmine-jquery/lib/jasmine-jquery.js' ,
'node_modules/jasmine-ajax/lib/mock-ajax.js',
'https://maps.googleapis.com/maps/api/js?libraries=places&language=en&key=AIzaSyDWgc7p4WWFsO3y0MTe50vF4l4NUPcPuwE',
'node_modules/leaflet/dist/leaflet.js',
'node_modules/leaflet-blurred-location/dist/Leaflet.BlurredLocation.js',
'dist/Leaflet.BlurredLocationDisplay.js'
],
styles: [
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
'node_modules/leaflet/dist/leaflet.css'
]
}
},

Expand All @@ -50,9 +63,11 @@ module.exports = function(grunt) {
});

/* Default (development): Watch files and build on change. */
grunt.loadNpmTasks("grunt-contrib-jasmine");
grunt.registerTask("default", ["watch", "jasmine"]);
grunt.registerTask("test", ["jshint", "jasmine"]);
grunt.registerTask('build', [
'browserify:dist'
]);
grunt.registerTask('test', ['jshint', 'jasmine']);
grunt.registerTask('build', ['browserify']);

};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"require": "^2.4.20",
"resig-class": "^1.0.0",
"leaflet-graticule": "git://github.com/jywarren/Leaflet.Graticule.git#patch-1",
"leaflet-blurred-location": "git://github.com/publiclab/leaflet-blurred-location#feature_API_modifications"
"leaflet-blurred-location": "^1.2.7"
},
"dependencies": {
"jquery": "^3.3.1",
"leaflet-blurred-location": "git://github.com/publiclab/leaflet-blurred-location#feature_API_modifications",
"leaflet-blurred-location": "^1.2.7",
"map_module": "git://github.com/publiclab/leaflet-blurred-location.git#master"
}
}
112 changes: 112 additions & 0 deletions spec/javascripts/fixtures/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="en">
<head>

<title>Leaflet.BlurredLocationDisplay</title>

</head>

<body>

<div class="container" >

<h1>Leaflet BlurredLocationDisplay <small>| by <a href="">Public Lab</a></small></h1>

<p>This page shows how different markers are shown according to their precision at different zoom levels .</p>

<hr />

<p>
<h3>1.) At zoom level = 5 , all 7 markers are shown : </h3>
<div style="background-color: #d6dfe0;">
<span style="color: Red"> [23.1 , 77.1] </span>, <br>
<span style="color: Red"> [20.1 , 76.1] </span>, <br>
<span style="color: Green"> [21.111 , 76.111] </span>,<br>
<span style="color: Green">[22.111 , 78.111]</span>,<br>
<span style="color: Black">[23.1234 , 76.1234]</span>,<br>
<span style="color: Yellow"> [24.123456 , 78.123456]</span>,<br>
<span style="color: Yellow"> [25.123456 , 77.123456]</span>
</div>
<div id="map1" class="leaflet-map" style="width: 100%; height: 400px;"></div>
<br><br>
<h3>2.) At zoom level = 6 , 5 markers are shown : </h3>
<div style="background-color: #d6dfe0;">
<span style="color: Green"> [21.111 , 76.111]</span>,<br>
<span style="color: Green"> [22.111 , 78.111]</span>,<br>
<span style="color: Black"> [23.1234 , 76.1234]</span>,<br>
<span style="color: Yellow"> [24.123456 , 78.123456]</span>,<br>
<span style="color: Yellow"> [25.123456 , 77.123456]</span>
</div>
<div id="map2" class="leaflet-map" style="width: 100%; height: 400px;"></div>
<br><br>
<h3>3.) At zoom level = 8 , 3 markers are shown : </h3>
<div style="background-color: #d6dfe0;">
<span style="color: Black"> [23.1234 , 76.1234]</span>,<br>
<span style="color: Yellow"> [24.123456 , 78.123456]</span>,<br>
<span style="color: Yellow"> [25.123456 , 77.123456]</span>
</div>
<div id="map3" class="leaflet-map" style="width: 100%; height: 400px;"></div>

<br />

</div>

<style>
html { background: #f8f8f8; margin-bottom: 100px;}
body { background: none; }
</style>


</body>


<script>

var options1 = {
mapID: 'map1'
}
var options2 = {
mapID: 'map2'
}
var options3 = {
mapID: 'map3'
}


var BlurredLocation1 = new BlurredLocation(options1) ;

var BlurredLocation2 = new BlurredLocation(options2) ;

var BlurredLocation3 = new BlurredLocation(options3) ;

var locations = [[23.1 , 77.1],
[20.1 , 76.1],
[21.111 , 76.111],
[22.111 , 78.111],
[23.1234 , 76.1234],
[24.123456 , 78.123456],
[25.123456 , 77.123456]];

var options_display1 = {
blurredLocation: BlurredLocation1,
locations: locations
};
var options_display2 = {
blurredLocation: BlurredLocation2,
locations: locations
};
var options_display3 = {
blurredLocation: BlurredLocation3,
locations: locations
};

var blurredLocationDisplay1 = new BlurredLocationDisplay(options_display1);
var blurredLocationDisplay2 = new BlurredLocationDisplay(options_display2);
var blurredLocationDisplay3 = new BlurredLocationDisplay(options_display3);

BlurredLocation1.map.setView([23,77] , 5) ;
BlurredLocation2.map.setView([23,77] , 6) ;
BlurredLocation3.map.setView([24.23694700391752, 76.89880371093751] , 8) ;

</script>
</html>
26 changes: 26 additions & 0 deletions spec/javascripts/test_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
describe("Basic testing", function() {
"use strict";

var fixture = loadFixtures('example.html');

it("Basic Test", function () {
expect(true).toBe(true);
});

it("Checks if at zoom level 5 , all 7 markers are shown", function () {
//BlurredLocation1.map.setZoom(5);
expect($("#map1").children()[0].childNodes[3].childNodes.length).toBe(0) ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect($("#map1").children()[0].childNodes[3].childNodes.length).toBe(7) ;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rexagod , yes i did that purposely to tell you guys that in testing , markers are not getting loaded on map 😄 !

});

it("Checks if at zoom level 6 , only 5 markers are shown", function () {
//BlurredLocation2.map.setZoom(6);
expect($("#map2").children()[0].childNodes[3].childNodes.length).toBe(0) ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect($("#map1").children()[0].childNodes[3].childNodes.length).toBe(5) ;

});

it("Checks if at zoom level 8 , only 3 markers are shown", function () {
// BlurredLocation3.map.setZoom(8);
expect($("#map3").children()[0].childNodes[3].childNodes.length).toBe(0) ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect($("#map1").children()[0].childNodes[3].childNodes.length).toBe(3) ;

});

it("maps are loaded", function () {
expect($("#map1")).toBeInDOM() ;
expect($("#map2")).toBeInDOM() ;
expect($("#map3")).toBeInDOM() ;
});

});
2 changes: 1 addition & 1 deletion spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
"spec/**/*.js"
],
"helpers": [
"helpers/**/*.js"
Expand Down