From 7d449e05562c76bb430efc1c36bd715675a84152 Mon Sep 17 00:00:00 2001
From: George Goldberg <george@gberg.me>
Date: Thu, 23 Mar 2017 18:05:36 +0000
Subject: PLT-5755: Infrastructure for Component Testing. (#5814)

This migrates the existing webapp tests to using Jest and Enzyme. The
infrastructure is put in place for React component testing, and a few
simple example component tests are implemented.

This also adds snapshot testing of components, coverage checking for the
webapp (although that is not yet integrated to Coveralls), and the
ability to run npm run test:watch to automatically re-run affected tests
when working on the webapp codebase.
---
 .../tests/utils/utils_get_nearest_point.test.jsx   | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 webapp/tests/utils/utils_get_nearest_point.test.jsx

(limited to 'webapp/tests/utils/utils_get_nearest_point.test.jsx')

diff --git a/webapp/tests/utils/utils_get_nearest_point.test.jsx b/webapp/tests/utils/utils_get_nearest_point.test.jsx
new file mode 100644
index 000000000..101f768bb
--- /dev/null
+++ b/webapp/tests/utils/utils_get_nearest_point.test.jsx
@@ -0,0 +1,31 @@
+import * as CommonUtils from 'utils/commons.jsx';
+
+describe('CommonUtils.getNearestPoint', function() {
+    test('should return nearest point', function() {
+        for (const data of [
+            {
+                points: [{x: 30, y: 40}, {x: 50, y: 50}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}, {x: 10, y: 20}],
+                pivotPoint: {x: 10, y: 20},
+                nearestPoint: {x: 10, y: 20},
+                nearestPointLte: {x: 10, y: 20}
+            },
+            {
+                points: [{x: 50, y: 50}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}, {x: 100, y: 90}, {x: 30, y: 40}],
+                pivotPoint: {x: 10, y: 20},
+                nearestPoint: {x: 30, y: 40},
+                nearestPointLte: {}
+            },
+            {
+                points: [{x: 50, y: 50}, {x: 1, y: 1}, {x: 15, y: 25}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}],
+                pivotPoint: {x: 10, y: 20},
+                nearestPoint: {x: 15, y: 25},
+                nearestPointLte: {x: 1, y: 1}
+            }
+        ]) {
+            const nearestPoint = CommonUtils.getNearestPoint(data.pivotPoint, data.points);
+
+            expect(nearestPoint.x).toEqual(data.nearestPoint.x);
+            expect(nearestPoint.y).toEqual(data.nearestPoint.y);
+        }
+    });
+});
-- 
cgit v1.2.3-1-g7c22

