Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Oct 2, 2015
1 parent 51a4eee commit b6d14e7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 98 deletions.
24 changes: 1 addition & 23 deletions web/client/actions/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ var {
CHANGE_ZOOM_LVL,
LAYER_LOADING,
LAYER_LOAD,
SHOW_SPINNER,
HIDE_SPINNER,
changeMapView,
clickOnMap,
changeMousePointer,
changeZoomLevel,
layerLoading,
layerLoad,
showSpinner,
hideSpinner
layerLoad
} = require('../map');

describe('Test correctness of the map actions', () => {
Expand Down Expand Up @@ -87,22 +83,4 @@ describe('Test correctness of the map actions', () => {
expect(retval.type).toBe(LAYER_LOAD);
expect(retval.layerId).toBe(testVal);
});

it('show some spinner', () => {
const testVal = 'spinner1';
const retval = showSpinner(testVal);

expect(retval).toExist();
expect(retval.type).toBe(SHOW_SPINNER);
expect(retval.spinnerId).toBe(testVal);
});

it('hide some spinner', () => {
const testVal = 'spinner1';
const retval = hideSpinner(testVal);

expect(retval).toExist();
expect(retval.type).toBe(HIDE_SPINNER);
expect(retval.spinnerId).toBe(testVal);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('test the globalspinner component', () => {
});

it('creates the component with layers loading and spinner to show', () => {
const globalspinner = React.render(<GlobalSpinner id="globalspinner" loadingLayers={{layer1: true}}
const globalspinner = React.render(<GlobalSpinner id="globalspinner" loadingLayers={["layer1"]}
spinnersInfo={{globalspinner: true}}/>, document.body);
expect(globalspinner).toExist();
const globalspinnerDiv = React.findDOMNode(globalspinner);
Expand All @@ -40,7 +40,7 @@ describe('test the globalspinner component', () => {
});*/

it('creates the component with layers load', () => {
const globalspinner = React.render(<GlobalSpinner loadingLayers={{layer1: false}}/>, document.body);
const globalspinner = React.render(<GlobalSpinner loadingLayers={[]}/>, document.body);
expect(globalspinner).toExist();
const globalspinnerDiv = React.findDOMNode(globalspinner);
expect(globalspinnerDiv).toNotExist();
Expand Down
6 changes: 6 additions & 0 deletions web/client/components/map/openlayers/Layer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const OpenlayersLayer = React.createClass({
onLayerLoading: React.PropTypes.func,
onLayerLoad: React.PropTypes.func
},
getDefaultProps() {
return {
onLayerLoading: () => {},
onLayerLoad: () => {}
};
},

componentDidMount() {
this.createLayer(this.props.type, this.props.options);
Expand Down
86 changes: 16 additions & 70 deletions web/client/reducers/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,26 @@ describe('Test the mapConfig reducer', () => {
layerId: "layer1"
};

var originalLoadingLayers = {loadingLayers: {layer1: true}};
var originalLoadingLayers = {loadingLayers: ["layer1"]};
var state = mapConfig(null, action);

expect(state.loadingLayers).toEqual({layer1: true});
expect(state.loadingLayers).toEqual(["layer1"]);

state = mapConfig({}, action);
expect(state.loadingLayers).toEqual({layer1: true});
expect(state.loadingLayers).toEqual(["layer1"]);

state = mapConfig(state, action);
expect(state.loadingLayers).toEqual({layer1: true});
expect(state.loadingLayers).toEqual(["layer1"]);

state = mapConfig(originalLoadingLayers, action);
expect(state).toEqual(originalLoadingLayers);
expect(state).toNotBe(originalLoadingLayers);

state = mapConfig({layer1: false}, action);
expect(state.loadingLayers).toEqual({layer1: true});
state = mapConfig({}, action);
expect(state.loadingLayers).toEqual(["layer1"]);

state = mapConfig({loadingLayers: {layer2: true}}, action);
expect(state.loadingLayers).toEqual({layer2: true, layer1: true});
state = mapConfig({loadingLayers: ["layer2"]}, action);
expect(state.loadingLayers).toEqual(["layer2", "layer1"]);
});

it('a layer load, loadingLayers is updated', () => {
Expand All @@ -152,79 +152,25 @@ describe('Test the mapConfig reducer', () => {
layerId: "layer1"
};

var originalLoadingLayers = {loadingLayers: {layer1: false}};
var originalLoadingLayers = {loadingLayers: []};
var state = mapConfig(null, action);

expect(state.loadingLayers).toEqual({layer1: false});
expect(state.loadingLayers).toEqual([]);

state = mapConfig({}, action);
expect(state.loadingLayers).toEqual({layer1: false});
expect(state.loadingLayers).toEqual([]);

state = mapConfig(state, action);
expect(state.loadingLayers).toEqual({layer1: false});
expect(state.loadingLayers).toEqual([]);

state = mapConfig(originalLoadingLayers, action);
expect(state).toEqual(originalLoadingLayers);
expect(state).toNotBe(originalLoadingLayers);

state = mapConfig({layer1: true}, action);
expect(state.loadingLayers).toEqual({layer1: false});

state = mapConfig({loadingLayers: {layer2: true}}, action);
expect(state.loadingLayers).toEqual({layer2: true, layer1: false});
});

it('a spinner must be show', () => {
const action = {
type: 'SHOW_SPINNER',
spinnerId: "spinner1"
};

var originalmapConfig = {spinnersInfo: {spinner1: true}};
var state = mapConfig(null, action);
expect(state.spinnersInfo).toEqual({spinner1: true});

state = mapConfig({}, action);
expect(state.spinnersInfo).toEqual({spinner1: true});

state = mapConfig(state, action);
expect(state.spinnersInfo).toEqual({spinner1: true});

state = mapConfig(originalmapConfig, action);
expect(state).toEqual(originalmapConfig);
expect(state).toNotBe(originalmapConfig);

state = mapConfig({spinner1: false}, action);
expect(state.spinnersInfo).toEqual({spinner1: true});

state = mapConfig({spinnersInfo: {spinner2: true}}, action);
expect(state.spinnersInfo).toEqual({spinner2: true, spinner1: true});
});

it('a spinner must be hiden', () => {
const action = {
type: 'HIDE_SPINNER',
spinnerId: "spinner1"
};

var originalmapConfig = {spinnersInfo: {spinner1: false}};
var state = mapConfig(null, action);
expect(state.spinnersInfo).toEqual({spinner1: false});

state = mapConfig({}, action);
expect(state.spinnersInfo).toEqual({spinner1: false});

state = mapConfig(state, action);
expect(state.spinnersInfo).toEqual({spinner1: false});

state = mapConfig(originalmapConfig, action);
expect(state).toEqual(originalmapConfig);
expect(state).toNotBe(originalmapConfig);

state = mapConfig({spinner1: true}, action);
expect(state.spinnersInfo).toEqual({spinner1: false});
state = mapConfig({loadingLayers: ["layer1"]}, action);
expect(state.loadingLayers).toEqual([]);

state = mapConfig({spinnersInfo: {spinner2: true}}, action);
expect(state.spinnersInfo).toEqual({spinner2: true, spinner1: false});
state = mapConfig({loadingLayers: ["layer2"]}, action);
expect(state.loadingLayers).toEqual(["layer2"]);
});
});
8 changes: 5 additions & 3 deletions web/client/reducers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ function mapConfig(state = null, action) {
mapStateSource: action.mapStateSource
});
case LAYER_LOADING: {
let loadingLayers = (state && state.loadingLayers && state.loadingLayers.splice(0)) || [];
loadingLayers.push(action.layerId);
let loadingLayers = (state && state.loadingLayers && state.loadingLayers.slice(0)) || [];
if (loadingLayers.indexOf(action.layerId) === -1) {
loadingLayers.push(action.layerId);
}
return assign({}, state, {
loadingLayers: loadingLayers
});
}
case LAYER_LOAD: {
let loadingLayers = (state && state.loadingLayers && state.loadingLayers.splice(0)) || [];
let loadingLayers = (state && state.loadingLayers && state.loadingLayers.slice(0)) || [];
loadingLayers = loadingLayers.filter((el) => {
return el !== action.layerId;
});
Expand Down

0 comments on commit b6d14e7

Please sign in to comment.