Skip to content

Commit

Permalink
Merge pull request geosolutions-it#149 from mircobe87/issue-147-wrong…
Browse files Browse the repository at this point in the history
…Coverage

Fixes geosolutions-it#147, wrong coverage
  • Loading branch information
mbarto committed Sep 24, 2015
2 parents 413300b + 1cc2edd commit e1d5faa
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 28 deletions.
4 changes: 2 additions & 2 deletions karma.conf.single-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ module.exports = function karmaConfig(config) {
],
postLoaders: [
{
test: /\.jsx$/,
exclude: /(__tests__|node_modules|legacy)\//,
test: /\.jsx?$/,
exclude: /(__tests__|node_modules|legacy)\/|webpack\.js|utils\/(openlayers|leaflet)/,
loader: 'istanbul-instrumenter'
}
]
Expand Down
12 changes: 12 additions & 0 deletions web/client/actions/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ describe('Test configuration related actions', () => {
}
});
});

it('loads an broken configuration file', (done) => {
loadMapConfig('base/web/client/test-resources/testConfig.broken.json')((e) => {
try {
expect(e).toExist();
expect(e.type).toBe('MAP_CONFIG_LOAD_ERROR');
done();
} catch(ex) {
done(ex);
}
});
});
});
24 changes: 24 additions & 0 deletions web/client/actions/__tests__/locale-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,28 @@ describe('Test locale related actions', () => {
}
});
});

it('loads an existing translation file', (done) => {
loadLocale('base/web/client/test-resources')((e) => {
try {
expect(e).toExist();
expect(e.type).toBe('CHANGE_LOCALE');
done();
} catch(ex) {
done(ex);
}
});
});

it('loads an existing broken translation file', (done) => {
loadLocale('base/web/client/test-resources', 'it-IT-broken')((e) => {
try {
expect(e).toExist();
expect(e.type).toBe('LOCALE_LOAD_ERROR');
done();
} catch(ex) {
done(ex);
}
});
});
});
7 changes: 7 additions & 0 deletions web/client/components/I18N/__tests__/Localized-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ describe('Test the localization support HOC', () => {
var dom = React.findDOMNode(localized);
expect(dom).toNotExist();
});

it('renders a loading error', () => {
var localized = React.render(<Localized loadingError="loadingError" />, document.body);
var dom = React.findDOMNode(localized);
expect(dom).toExist();
expect(dom.className.indexOf("loading-locale-error")).toNotBe(-1);
});
});
6 changes: 6 additions & 0 deletions web/client/components/map/openlayers/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ describe('Openlayers layer', () => {

expect(layer).toExist();
map.getView().setRotation(Math.PI / 2.0);

let viewport = map.getViewport();
viewport.dispatchEvent(new MouseEvent('mousedown'));
viewport.dispatchEvent(new MouseEvent('mousemove'));
viewport.dispatchEvent(new MouseEvent('mouseup'));

let dom = document.getElementById("mapgmaps");
expect(dom).toExist();
expect(dom.style.transform).toBe('rotate(90deg)');
Expand Down
31 changes: 9 additions & 22 deletions web/client/components/map/openlayers/plugins/GoogleLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ var React = require('react');

var layersMap;

var isTouchSupported = 'ontouchstart' in window;
var startEvent = isTouchSupported ? 'touchstart' : 'mousedown';
var moveEvent = isTouchSupported ? 'touchmove' : 'mousemove';
var endEvent = isTouchSupported ? 'touchend' : 'mouseup';

Layers.registerType('google', {
create: (options, map, mapId) => {
let google = window.google;
Expand Down Expand Up @@ -111,7 +116,7 @@ Layers.registerType('google', {
let mousemove = false;

let resizeGoogleLayerIfRotated = function() {
let degrees = /[\+\-]?\d+\.\d+/g;
let degrees = /[\+\-]?\d+\.?\d*/i;
let newTrans = document.getElementById(mapId + 'gmaps').style.transform;
if (newTrans !== oldTrans && newTrans.indexOf('rotate') !== -1) {
let mapContainer = document.getElementById(mapId + 'gmaps');
Expand All @@ -126,37 +131,19 @@ Layers.registerType('google', {
}
};

// desktop --------------------------------------------------------------
viewport.addEventListener('mousedown', () => {
mousedown = true;
});
viewport.addEventListener('mouseup', () => {
if (mousemove && mousedown) {
resizeGoogleLayerIfRotated();
}
oldTrans = document.getElementById(mapId + 'gmaps').style.transform;
mousedown = false;
});
viewport.addEventListener('mousemove', () => {
mousemove = mousedown;
});
// ---------------------------------------------------------------------

// mobile --------------------------------------------------------------
viewport.addEventListener('touchstart', () => {
viewport.addEventListener(startEvent, () => {
mousedown = true;
});
viewport.addEventListener('touchend', () => {
viewport.addEventListener(endEvent, () => {
if (mousemove && mousedown) {
resizeGoogleLayerIfRotated();
}
oldTrans = document.getElementById(mapId + 'gmaps').style.transform;
mousedown = false;
});
viewport.addEventListener('touchmove', () => {
viewport.addEventListener(moveEvent, () => {
mousemove = mousedown;
});
// ---------------------------------------------------------------------

return null;
},
Expand Down
43 changes: 43 additions & 0 deletions web/client/libs/__tests__/ajax-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,47 @@ describe('Tests ajax library', () => {
done(ex);
});
});

it('uses a custom proxy for requests on the same origin with varius query params', (done) => {
axios.get('http://fakeexternaldomain.mapstore2', {
proxyUrl: '/proxy/?url=',
params: {
param1: 'param1',
param2: '',
param3: undefined,
param4: null,
param5: [],
param6: [1, 2, "3", ''],
param7: {},
param8: {
a: 'a'
},
param9: new Date()
}})
.then(() => {
done();
})
.catch((ex) => {
expect(ex.config).toExist();
expect(ex.config.url).toExist();
expect(ex.config.url).toContain('proxy/?url=');
done();
});
});

it('uses a custom proxy for requests on the same origin with string query param', (done) => {
axios.get('http://fakeexternaldomain.mapstore2', {
proxyUrl: '/proxy/?url=',
params: "params"
})
.then(() => {
done();
})
.catch((ex) => {
expect(ex.config).toExist();
expect(ex.config.url).toExist();
expect(ex.config.url).toContain('proxy/?url=');
done();
});
});
});
4 changes: 0 additions & 4 deletions web/client/libs/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function isArguments(val) {
}
function forEach(arg, fn) {
var obj;
// Don't bother if no value provided
if (arg === null || typeof arg === 'undefined') {
return;
}

// Check if arg is array-like
const isArrayLike = isArray(arg) || isArguments(arg);
Expand Down
10 changes: 10 additions & 0 deletions web/client/reducers/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ describe('Test the mapInfo reducer', () => {
expect(state.responses).toExist();
expect(state.responses.length).toBe(0);
});

it('enables map info', () => {
let state = mapInfo({}, {type: 'CHANGE_MAPINFO_STATE', enabled: true});
expect(state).toExist();
expect(state.enabled).toBe(true);

state = mapInfo({}, {type: 'CHANGE_MAPINFO_STATE', enabled: false});
expect(state).toExist();
expect(state.enabled).toBe(false);
});
});
19 changes: 19 additions & 0 deletions web/client/test-resources/data.en-US
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"locale": "it-IT",
"messages": {
"msgId0": "{name} took {numPhotos, plural, =0 {no photos} =1 {one photo} other {# photos}} on {takenDate, date, long}.",
"htmlTest": "{name} {surname}",
"about_title": "About this app...",
"aboutLbl": "About",
"about_p0-0": "MapStore 2 is a framework to build web mapping applications using standard mapping libraries, such as",
"about_p0-1": "and",
"about_p1": "MapStore 2 has several example applications:",
"about_ul0_li0": "MapViewer is a simple viewer of preconfigured maps (optionally stored in a database using GeoStore)",
"about_ul0_li1": "MapPublisher has been developed to create, save and share in a simple and intuitive way maps and mashups created selecting contents by server like OpenStreetMap, Google Maps, MapQuest or specific servers provided by your organization or third party. For more information check the",
"about_h20": "License",
"about_p3": "MapStore 2 is Free and Open Source software, it is based on OpenLayers 3, Leaflet and ReactJS, and is licensed under the Simplified BSD License.",
"about_p5-0": "For more information check",
"about_a0": "this",
"about_p5-1": "page."
}
}
13 changes: 13 additions & 0 deletions web/client/test-resources/data.it-IT-broken
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"locale": "it-IT",
"messages": {
"msgId0": "{name} ha scattato {numPhotos, plural, =0 {nessuna foto} other {# foto}} il {takenDate, date, long}.",
"htmlTest": "{name} {surname}",
"about_title": "Riguardo a questa app...",
"aboutLbl": "Info",
"about_p0-0": "MapStore 2 un framework per realizzare applicazioni di web mapping usando librerie di mapping standard, come",
"about_p0-1": "e",
"about_p1": "MapStore 2 contiene alcune applicazioni di esempio:",
"about_ul0_li0": "MapViewer è un semplice visualizzatore di mappe preconfigurate (opzionalmente memorizzare in un database usando GeoStore)",
"about_ul0_li1": "MapPublisher è stato sviluppato per creare, salvare a condividere in modo semplice ed intuitivo mappe e mashups creati selezionando contenuti da server come OpenStreetMap, Google Maps, MapQuest o da specifici servizi forniti dalla tua organizzazione o da terze parti. Per maggiori informazioni controlla la",
"about_h20": "Licenza",
21 changes: 21 additions & 0 deletions web/client/test-resources/testConfig.broken.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"map": {
"projection": "EPSG:900913",
"units": "m",
"center": {"x": 1250000.000000, "y": 5370000.000000, "crs": "EPSG:900913"},
"zoom":5,
"maxExtent": [
-20037508.34, -20037508.34,
20037508.34, 20037508.34
],
"layers": [
{
"type": "osm",
"title": "Open Street Map",
"name": "mapnik",
"group": "background",
"visibility": true
},{
"type": "wms",
"url":"http://213.215.135.196/reflector/open/service",
"visibility": false,
76 changes: 76 additions & 0 deletions web/client/utils/__tests__/ConfigUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,80 @@ describe('ConfigUtils', () => {
expect(config.map.layers.length).toBe(1);
expect(config.gsSources["gxp-source-508"]).toExist();
});

it('getCenter', () => {
var center = ConfigUtils.getCenter([13, 43]);
expect(center).toExist();
expect(center.y).toBe(43);
expect(center.x).toBe(13);
expect(center.crs).toBe('EPSG:4326');

center = ConfigUtils.getCenter([13, 43], 'EPSG:4326');
expect(center).toExist();
expect(center.y).toBe(43);
expect(center.x).toBe(13);
expect(center.crs).toBe('EPSG:4326');

center = ConfigUtils.getCenter({y: 43, x: 13, crs: 'EPSG:4326'});
expect(center).toExist();
expect(center.y).toBe(43);
expect(center.x).toBe(13);
expect(center.crs).toBe('EPSG:4326');

center = ConfigUtils.getCenter({y: 4786738, x: 1459732, crs: 'EPSG:900913'});
expect(center).toExist();
expect(center.y).toExist();
expect(center.x).toExist();
expect(center.crs).toBe('EPSG:4326');
});

it('getConfigurationOptions', () => {
var retval = ConfigUtils.getConfigurationOptions({});
expect(retval).toExist();
expect(retval.configUrl).toExist();
expect(retval.configUrl).toBe('config.json');

retval = ConfigUtils.getConfigurationOptions({}, 'name', 'extension');
expect(retval).toExist();
expect(retval.configUrl).toExist();
expect(retval.configUrl).toBe('name.extension');

retval = ConfigUtils.getConfigurationOptions({}, 'name');
expect(retval).toExist();
expect(retval.configUrl).toExist();
expect(retval.configUrl).toBe('name.json');

retval = ConfigUtils.getConfigurationOptions({}, undefined, 'extension');
expect(retval).toExist();
expect(retval.configUrl).toExist();
expect(retval.configUrl).toBe('config.extension');

retval = ConfigUtils.getConfigurationOptions({
mapId: 42
});
expect(retval).toExist();
expect(retval.configUrl).toExist();
expect(retval.configUrl).toBe('/mapstore/rest/geostore/data/42');

retval = ConfigUtils.getConfigurationOptions({
mapId: 42
}, undefined, undefined, 'gbase/');
expect(retval).toExist();
expect(retval.configUrl).toExist();
expect(retval.configUrl).toBe('gbase/data/42');
});

it('getUserConfiguration', () => {
const testval = ConfigUtils.getConfigurationOptions({});
const retval = ConfigUtils.getUserConfiguration();
expect(retval).toExist();
expect(retval.configUrl).toBe(testval.configUrl);
expect(retval.legacy).toBe(testval.legacy);
});

it('loadConfiguration', (done) => {
var retval = ConfigUtils.loadConfiguration();
expect(retval).toExist();
done();
});
});
32 changes: 32 additions & 0 deletions web/client/utils/__tests__/LocaleUtils-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

var expect = require('expect');
var url = require('url');
var LocaleUtils = require('../LocaleUtils');

describe('LocaleUtils', () => {
it('getLocale', () => {
var expectedLocal = navigator ? navigator.language || navigator.browserLanguage : "en";
expect(LocaleUtils.getLocale({})).toBe(expectedLocal);

expect(LocaleUtils.getLocale({locale: 'it'})).toBe('it-IT');
expect(LocaleUtils.getLocale({locale: 'en'})).toBe('en-US');

expect(LocaleUtils.getLocale({locale: 'fake'})).toBe('en-US');
});

it('getUserLocale', () => {
var expectedLocal = LocaleUtils.getLocale(url.parse(window.location.href, true).query);
expect(LocaleUtils.getUserLocale()).toBe(expectedLocal);
});

it('getSupportedLocales', () => {
expect(LocaleUtils.getSupportedLocales()).toExist();
});
});

0 comments on commit e1d5faa

Please sign in to comment.