Skip to content

Commit

Permalink
Merge 7fa79a4 into d57b6fe
Browse files Browse the repository at this point in the history
  • Loading branch information
georgios-uber committed Apr 5, 2019
2 parents d57b6fe + 7fa79a4 commit 871c9af
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 77 deletions.
17 changes: 13 additions & 4 deletions modules/layers/test/lib/mode-handlers/duplicate-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
FeatureType,
createFeatureCollection,
getMockFeatureDetails,
mockedGeoJsonProperties
mockedGeoJsonProperties,
mockNonPickedHandle
} from '../test-utils.js';
import {
testModeHandlerHandlePointMove,
Expand Down Expand Up @@ -49,14 +50,24 @@ function testDuplicatingSingleFeature(featureType) {
}

describe('handleStartDragging()', () => {
let handler;

beforeEach(() => {
handler = new DuplicateHandler(featureCollection);
handler._context = {
layerManager: {
pickObject: () => [{ object: mockNonPickedHandle }]
}
};
});

Object.values(FeatureType).forEach(featureType => {
if (typeof featureType === 'string') {
testDuplicatingSingleFeature(featureType);
}
});

test('duplicate multi-selected features (multipolygon and polygon)', () => {
const handler = new DuplicateHandler(featureCollection);
const multiPolygonDetails = getMockFeatureDetails(FeatureType.MULTI_POLYGON);
const polygonDetails = getMockFeatureDetails(FeatureType.POLYGON);
const nonDupedFeatureTypes = Object.values(FeatureType).filter(
Expand All @@ -82,7 +93,6 @@ describe('handleStartDragging()', () => {
});

test('Single duplicated feature retains user supplied geoJson properties', () => {
const handler = new DuplicateHandler(featureCollection);
const { index, clickCoords } = getMockFeatureDetails(FeatureType.POLYGON);
handler.setSelectedFeatureIndexes([index]);
handler._isTranslatable = true;
Expand All @@ -104,7 +114,6 @@ describe('handleStartDragging()', () => {
});

test('Multiple duplicated features retain user supplied geoJson properties (multipolygon and polygon)', () => {
const handler = new DuplicateHandler(featureCollection);
const poly = getMockFeatureDetails(FeatureType.POLYGON);
const multiPoly = getMockFeatureDetails(FeatureType.MULTI_POLYGON);
handler.setSelectedFeatureIndexes([poly.index, multiPoly.index]);
Expand Down
41 changes: 30 additions & 11 deletions modules/layers/test/lib/mode-handlers/mode-handler-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
createPointerMoveEvent,
getMockFeatureDetails,
FeatureType,
mockedGeoJsonProperties
mockedGeoJsonProperties,
mockNonPickedHandle
} from '../test-utils.js';

export function mockHandleStartDragging(
Expand Down Expand Up @@ -62,10 +63,20 @@ export function testModeHandlerHandlePointMove(
isActionEnabledName: string
) {
describe('handlePointerMove()', () => {
let handler;

beforeEach(() => {
handler = new HandlerClass(featureCollection);
handler._context = {
layerManager: {
pickObject: () => [{ object: mockNonPickedHandle }]
}
};
});

Object.values(FeatureType).forEach(featureType => {
if (typeof featureType === 'string') {
test(`${modeName} mode active when mouse is over selected ${featureType} feature`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index } = getMockFeatureDetails(featureType);
handler.setSelectedFeatureIndexes([index]);
mockHandlePointerMove(handler, {
Expand All @@ -78,7 +89,6 @@ export function testModeHandlerHandlePointMove(
});

test(`${modeName} mode active when mouse is over a multi-selected feature`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index } = getMockFeatureDetails(FeatureType.MULTI_LINE_STRING);
const { index: secondIndex } = getMockFeatureDetails(FeatureType.POLYGON);
handler.setSelectedFeatureIndexes([index, secondIndex]);
Expand All @@ -90,7 +100,6 @@ export function testModeHandlerHandlePointMove(
});

test(`${modeName} - no action when mouse is over non selected polygon`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index } = getMockFeatureDetails(FeatureType.POLYGON);
handler.setSelectedFeatureIndexes([index + 1]);
const { editAction, cancelMapPan } = mockHandlePointerMove(handler, {
Expand All @@ -103,7 +112,6 @@ export function testModeHandlerHandlePointMove(
});

test(`${modeName} - no action when mouse isn't over any feature`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index } = getMockFeatureDetails(FeatureType.POLYGON);
handler.setSelectedFeatureIndexes([index]);
const { editAction, cancelMapPan } = mockHandlePointerMove(handler, {
Expand All @@ -115,7 +123,6 @@ export function testModeHandlerHandlePointMove(
});

test(`${modeName} - no action when mouse is not over multi-selected selected feature`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index: nonSelectedIndex } = getMockFeatureDetails(
FeatureType.MULTI_LINE_STRING
);
Expand All @@ -141,8 +148,13 @@ export function testHandleStartDragging(
getGeometryBeforeActionName: string
) {
describe('handleStartDragging()', () => {
let handler;

beforeEach(() => {
handler = new HandlerClass(featureCollection);
});

test(`${modeName} mode - initial geometry is assigned under valid conditions`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index } = getMockFeatureDetails(FeatureType.POINT);
handler.setSelectedFeatureIndexes([index]);
handler[isActionEnabledName] = true;
Expand All @@ -156,7 +168,6 @@ export function testHandleStartDragging(
});

test(`${modeName} mode - initial geometry is not assigned under invalid conditions`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index } = getMockFeatureDetails(FeatureType.POINT);
handler.setSelectedFeatureIndexes([index]);
handler[isActionEnabledName] = false;
Expand All @@ -177,9 +188,19 @@ export function testHandleStopDragging(
featureCollection: FeatureCollection,
featureFilter: (...args: Array<any>) => any = feature => feature
) {
let handler;

beforeEach(() => {
handler = new HandlerClass(featureCollection);
handler._context = {
layerManager: {
pickObject: () => [{ object: mockNonPickedHandle }]
}
};
});

function testHandleStopDraggingForFeatureType(featureType: string) {
test(`${modeName} mode action - single selected ${featureType} feature`, () => {
const handler = new HandlerClass(featureCollection);
const { geoJson, clickCoords, index } = getMockFeatureDetails(featureType);
handler.setSelectedFeatureIndexes([index]);
const moveCoordinates = clickCoords.map(coord => coord + 0.5);
Expand Down Expand Up @@ -213,7 +234,6 @@ export function testHandleStopDragging(
});

test(`${modeName} mode action - geoJson properties are preserved after mode action`, () => {
const handler = new HandlerClass(featureCollection);
const { clickCoords, index } = getMockFeatureDetails(FeatureType.POLYGON);
handler.setSelectedFeatureIndexes([index]);
const moveCoordinates = clickCoords.map(coord => coord + 0.5);
Expand All @@ -231,7 +251,6 @@ export function testHandleStopDragging(
});

test(`${modeName} mode action - multiple selected features (multipolygon and point)`, () => {
const handler = new HandlerClass(featureCollection);
const multiPolygonDetails = getMockFeatureDetails(FeatureType.MULTI_POLYGON);
const pointDetails = getMockFeatureDetails(FeatureType.POINT);
handler.setSelectedFeatureIndexes([multiPolygonDetails.index, pointDetails.index]);
Expand Down
80 changes: 20 additions & 60 deletions modules/layers/test/lib/mode-handlers/mode-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
/* eslint-env jest */

import { ModeHandler } from '../../../src/mode-handlers/mode-handler.js';
import {
createPointFeature,
createLineStringFeature,
createPolygonFeature,
createMultiPointFeature,
createMultiLineStringFeature,
createMultiPolygonFeature
} from '../test-utils.js';

let pointFeature;
let lineStringFeature;
Expand All @@ -11,67 +19,19 @@ let multiLineStringFeature;
let multiPolygonFeature;
let featureCollection;

beforeEach(() => {
pointFeature = {
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [1, 2] }
};

lineStringFeature = {
type: 'Feature',
properties: {},
geometry: { type: 'LineString', coordinates: [[1, 2], [2, 3], [3, 4]] }
};

polygonFeature = {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
// exterior ring
[[-1, -1], [1, -1], [1, 1], [-1, 1], [-1, -1]],
// hole
[[-0.5, -0.5], [-0.5, 0.5], [0.5, 0.5], [0.5, -0.5], [-0.5, -0.5]]
]
}
};
export function mockFeatureCollectionState(polygon: any) {
const handler = new ModeHandler(polygon);
handler.setSelectedFeatureIndexes([1]);
return handler;
}

multiPointFeature = {
type: 'Feature',
properties: {},
geometry: { type: 'MultiPoint', coordinates: [[1, 2], [3, 4]] }
};

multiLineStringFeature = {
type: 'Feature',
properties: {},
geometry: {
type: 'MultiLineString',
coordinates: [[[1, 2], [2, 3], [3, 4]], [[5, 6], [6, 7], [7, 8]]]
}
};

multiPolygonFeature = {
type: 'Feature',
properties: {},
geometry: {
type: 'MultiPolygon',
coordinates: [
[
// exterior ring polygon 1
[[-1, -1], [1, -1], [1, 1], [-1, 1], [-1, -1]],
// hole polygon 1
[[-0.5, -0.5], [-0.5, 0.5], [0.5, 0.5], [0.5, -0.5], [-0.5, -0.5]]
],
[
// exterior ring polygon 2
[[2, -1], [4, -1], [4, 1], [2, 1], [2, -1]]
]
]
}
};
beforeEach(() => {
pointFeature = createPointFeature();
lineStringFeature = createLineStringFeature();
polygonFeature = createPolygonFeature();
multiPointFeature = createMultiPointFeature();
multiLineStringFeature = createMultiLineStringFeature();
multiPolygonFeature = createMultiPolygonFeature();

featureCollection = {
type: 'FeatureCollection',
Expand Down
Loading

0 comments on commit 871c9af

Please sign in to comment.