Enable eslint and fix eslint errors for osm_test.js
This commit is contained in:
parent
e5c5776e65
commit
40c71f28be
6 changed files with 73 additions and 58 deletions
|
@ -43,6 +43,12 @@ You can run the existing test suite with:
|
|||
bundle exec rails test:all
|
||||
```
|
||||
|
||||
You can run javascript tests with:
|
||||
|
||||
```
|
||||
bundle exec teaspoon
|
||||
```
|
||||
|
||||
You can view test coverage statistics by browsing the `coverage` directory.
|
||||
|
||||
The tests are automatically run on Pull Requests and other commits via github
|
||||
|
|
5
Gemfile
5
Gemfile
|
@ -141,9 +141,6 @@ gem "image_processing"
|
|||
# Used to validate widths
|
||||
gem "unicode-display_width"
|
||||
|
||||
gem "teaspoon"
|
||||
gem "teaspoon-mocha", "~> 2.3.3"
|
||||
|
||||
# Gems useful for development
|
||||
group :development do
|
||||
gem "better_errors"
|
||||
|
@ -181,6 +178,8 @@ end
|
|||
|
||||
group :development, :test do
|
||||
gem "annotate"
|
||||
gem "teaspoon"
|
||||
gem "teaspoon-mocha", "~> 2.3.3"
|
||||
|
||||
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
||||
gem "debug", :require => "debug/prelude"
|
||||
|
|
|
@ -574,10 +574,6 @@ GEM
|
|||
stringio (3.1.1)
|
||||
strong_migrations (1.8.0)
|
||||
activerecord (>= 5.2)
|
||||
terminal-table (3.0.2)
|
||||
unicode-display_width (>= 1.1.1, < 3)
|
||||
terser (1.2.4)
|
||||
execjs (>= 0.3.0, < 3)
|
||||
teaspoon (1.2.2)
|
||||
railties (>= 3.2.5)
|
||||
teaspoon-mocha (2.3.3)
|
||||
|
|
|
@ -122,6 +122,18 @@ module.exports = [
|
|||
"yoda": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
// Additional configuration for test files
|
||||
files: ["test/**/*.js"],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.mocha,
|
||||
expect: "readonly",
|
||||
assert: "readonly",
|
||||
should: "readonly"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ["config/eslint.js"],
|
||||
languageOptions: {
|
||||
|
|
|
@ -9,13 +9,6 @@ SET xmloption = content;
|
|||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
-- *not* creating schema, since initdb creates it
|
||||
|
||||
|
||||
--
|
||||
-- Name: btree_gist; Type: EXTENSION; Schema: -; Owner: -
|
||||
--
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable */
|
||||
//= require jquery
|
||||
//= require js-cookie/dist/js.cookie
|
||||
//= require osm
|
||||
|
@ -86,7 +85,7 @@ describe("OSM", function () {
|
|||
|
||||
it("parses lat/lon/zoom from the hash", function () {
|
||||
document.location.hash = "#map=16/57.6247/-3.6845";
|
||||
params = OSM.mapParams("?");
|
||||
const params = OSM.mapParams("?");
|
||||
expect(params).to.have.property("lat", 57.6247);
|
||||
expect(params).to.have.property("lon", -3.6845);
|
||||
expect(params).to.have.property("zoom", 16);
|
||||
|
@ -135,7 +134,7 @@ describe("OSM", function () {
|
|||
params = OSM.mapParams("?");
|
||||
expect(params).to.have.property("layers", "C");
|
||||
|
||||
document.location.hash = "#map=5/57.6247/-3.6845&layers=M"
|
||||
document.location.hash = "#map=5/57.6247/-3.6845&layers=M";
|
||||
params = OSM.mapParams("?");
|
||||
expect(params).to.have.property("layers", "M");
|
||||
});
|
||||
|
@ -157,66 +156,75 @@ describe("OSM", function () {
|
|||
describe(".formatHash", function () {
|
||||
it("formats lat/lon/zoom params", function () {
|
||||
var args = { center: L.latLng(57.6247, -3.6845), zoom: 9 };
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845");
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685");
|
||||
});
|
||||
|
||||
it("respects zoomPrecision", function () {
|
||||
var args = { center: L.latLng(57.6247, -3.6845), zoom: 5 };
|
||||
expect(OSM.formatHash(args)).to.eq("#map=5/57.625/-3.685");
|
||||
expect(OSM.formatHash(args)).to.eq("#map=5/57.62/-3.68");
|
||||
|
||||
|
||||
args = { center: L.latLng(57.6247, -3.6845), zoom: 9 };
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845");
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685");
|
||||
|
||||
|
||||
args = { center: L.latLng(57.6247, -3.6845), zoom: 12 };
|
||||
expect(OSM.formatHash(args)).to.eq("#map=12/57.6247/-3.6845");
|
||||
});
|
||||
|
||||
it("formats layers params", function () {
|
||||
var args = { center: L.latLng(57.6247, -3.6845), zoom: 9, layers: "C" };
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845&layers=C");
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685&layers=C");
|
||||
});
|
||||
|
||||
it("ignores default layers", function () {
|
||||
var args = { center: L.latLng(57.6247, -3.6845), zoom: 9, layers: "M" };
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845");
|
||||
expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe(".zoomPrecision", function () {
|
||||
it("suggests 0 digits for z0-1", function () {
|
||||
expect(OSM.zoomPrecision(0)).to.eq(0);
|
||||
expect(OSM.zoomPrecision(1)).to.eq(0);
|
||||
});
|
||||
|
||||
it("suggests 1 digit for z2", function () {
|
||||
it("suggests 1 digit for z0-2", function () {
|
||||
expect(OSM.zoomPrecision(0)).to.eq(1);
|
||||
expect(OSM.zoomPrecision(1)).to.eq(1);
|
||||
expect(OSM.zoomPrecision(2)).to.eq(1);
|
||||
});
|
||||
|
||||
it("suggests 2 digits for z3-4", function () {
|
||||
it("suggests 2 digits for z3-6", function () {
|
||||
expect(OSM.zoomPrecision(3)).to.eq(2);
|
||||
expect(OSM.zoomPrecision(4)).to.eq(2);
|
||||
expect(OSM.zoomPrecision(5)).to.eq(2);
|
||||
expect(OSM.zoomPrecision(6)).to.eq(2);
|
||||
});
|
||||
|
||||
it("suggests 3 digits for z5-8", function () {
|
||||
expect(OSM.zoomPrecision(5)).to.eq(3);
|
||||
expect(OSM.zoomPrecision(6)).to.eq(3);
|
||||
it("suggests 3 digits for z7-9", function () {
|
||||
expect(OSM.zoomPrecision(7)).to.eq(3);
|
||||
expect(OSM.zoomPrecision(8)).to.eq(3);
|
||||
expect(OSM.zoomPrecision(9)).to.eq(3);
|
||||
});
|
||||
|
||||
it("suggests 4 digits for z9-16", function () {
|
||||
expect(OSM.zoomPrecision(9)).to.eq(4);
|
||||
it("suggests 4 digits for z10-12", function () {
|
||||
expect(OSM.zoomPrecision(10)).to.eq(4);
|
||||
expect(OSM.zoomPrecision(11)).to.eq(4);
|
||||
expect(OSM.zoomPrecision(12)).to.eq(4);
|
||||
expect(OSM.zoomPrecision(13)).to.eq(4);
|
||||
expect(OSM.zoomPrecision(14)).to.eq(4);
|
||||
expect(OSM.zoomPrecision(15)).to.eq(4);
|
||||
expect(OSM.zoomPrecision(16)).to.eq(4);
|
||||
});
|
||||
|
||||
it("suggests 5 digits for z17-20", function () {
|
||||
expect(OSM.zoomPrecision(17)).to.eq(5);
|
||||
expect(OSM.zoomPrecision(18)).to.eq(5);
|
||||
expect(OSM.zoomPrecision(19)).to.eq(5);
|
||||
expect(OSM.zoomPrecision(20)).to.eq(5);
|
||||
it("suggests 5 digits for z13-16", function () {
|
||||
expect(OSM.zoomPrecision(13)).to.eq(5);
|
||||
expect(OSM.zoomPrecision(14)).to.eq(5);
|
||||
expect(OSM.zoomPrecision(15)).to.eq(5);
|
||||
expect(OSM.zoomPrecision(16)).to.eq(5);
|
||||
});
|
||||
|
||||
it("suggests 6 digits for z17-19", function () {
|
||||
expect(OSM.zoomPrecision(17)).to.eq(6);
|
||||
expect(OSM.zoomPrecision(18)).to.eq(6);
|
||||
expect(OSM.zoomPrecision(19)).to.eq(6);
|
||||
});
|
||||
|
||||
it("suggests 7 digits for z20", function () {
|
||||
expect(OSM.zoomPrecision(20)).to.eq(7);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -225,17 +233,18 @@ describe("OSM", function () {
|
|||
$("body").html($("<div id='map'>"));
|
||||
var map = new L.OSM.Map("map", { center: [57.6247, -3.6845], zoom: 9 });
|
||||
map.updateLayers("");
|
||||
expect(OSM.locationCookie(map)).to.eq("-3.6845|57.6247|9|M");
|
||||
expect(OSM.locationCookie(map)).to.eq("-3.685|57.625|9|M");
|
||||
});
|
||||
|
||||
it("respects zoomPrecision", function () {
|
||||
$("body").html($("<div id='map'>"));
|
||||
var map = new L.OSM.Map("map", { center: [57.6247, -3.6845], zoom: 9 });
|
||||
map.updateLayers("");
|
||||
expect(OSM.locationCookie(map)).to.eq("-3.6845|57.6247|9|M");
|
||||
|
||||
map.setZoom(5);
|
||||
expect(OSM.locationCookie(map)).to.eq("-3.685|57.625|5|M");
|
||||
expect(OSM.locationCookie(map)).to.eq("-3.685|57.625|9|M");
|
||||
// map.setZoom() doesn't update the zoom level for some reason
|
||||
// using map._zoom here to update the zoom level manually
|
||||
map._zoom = 5;
|
||||
expect(OSM.locationCookie(map)).to.eq("-3.68|57.62|5|M");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue