From 05421e1c25252d20757f322139088e5b49f0aeb8 Mon Sep 17 00:00:00 2001 From: Jon D Date: Sat, 5 Nov 2016 20:20:27 +0000 Subject: [PATCH] Start adding tests --- modules/actions/flip.js | 3 ++- test/spec/actions/flip.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/spec/actions/flip.js diff --git a/modules/actions/flip.js b/modules/actions/flip.js index 18d6e517a..cfb83279a 100644 --- a/modules/actions/flip.js +++ b/modules/actions/flip.js @@ -5,8 +5,9 @@ Only operates on "area" ways export function actionFlip(wayId, isVertical, projection) { - return function (graph) { + return function (graph) { const targetWay = graph.entity(wayId); + // If the way is not an area, we will not process it if (!targetWay.isArea()) { // return input graph without changes diff --git a/test/spec/actions/flip.js b/test/spec/actions/flip.js new file mode 100644 index 000000000..26cbdbf38 --- /dev/null +++ b/test/spec/actions/flip.js @@ -0,0 +1,34 @@ +describe('iD.actionFlip', function() { + var projection = d3.geoMercator(); + + it('flips horizontally - does not change graph length', function () { + var graph = iD.Graph([ + iD.Node({id: 'a', loc: [0, 0]}), + iD.Node({id: 'b', loc: [2, 0]}), + iD.Node({id: 'c', loc: [2, 2]}), + iD.Node({id: 'd', loc: [0, 2]}), + iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}}) + ]); + + graph = iD.actionFlip('-', false, projection)(graph); + + expect(graph.entity('-').nodes).to.have.length(5); + }); + + it('flips horizontally - alters x value', function () { + var graph = iD.Graph([ + iD.Node({id: 'a', loc: [0, 0]}), + iD.Node({id: 'b', loc: [2, 0]}), + iD.Node({id: 'c', loc: [2, 2]}), + iD.Node({id: 'd', loc: [0, 2]}), + iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a'], tags: { area: 'yes'}}) + ]); + graph = iD.actionFlip('-', false, projection)(graph); + + expect(graph.entity('a').loc[0]).to.equal(2); // A should be 2,0 now + expect(graph.entity('b').loc[0]).to.equal(0); // B should be 0,0 now + expect(graph.entity('c').loc[0]).to.equal(0); // C should be 0,2 now + expect(graph.entity('d').loc[0]).to.equal(2); // D should be 2,0 now + }); + +});