From 24f34088a4745d8d05e8476d9893d37826dbe3e8 Mon Sep 17 00:00:00 2001 From: HarshithDS <harshith.ds@matriotsolutions.com> Date: Thu, 30 Jun 2022 16:11:48 +0530 Subject: [PATCH] TMSS-1847: Fixed angle1 validation --- .../src/components/JSONEditor/JEditor.js | 2 +- .../tmss_webapp/src/routes/Task/edit.test.js | 38 +++++++++---------- .../tmss_webapp/src/utils/unit.converter.js | 4 +- .../tmss_webapp/src/utils/validator.js | 24 ++++++++++++ 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js b/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js index 5eb08e7c20d..e2f8a7fc613 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js @@ -273,7 +273,7 @@ function Jeditor(props) { errors.push({ path: path, property: 'validationType', - message: 'Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees' + message: 'Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees' }); } } else if (schema.validationType === "angle") { diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.test.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.test.js index eacd76f03eb..6991f7bee23 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.test.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.test.js @@ -184,7 +184,7 @@ it("test Combined Observation Task Draft view of IM LBA Survey - 3 Beams edit", fireEvent.change(angel1El, { target: { value: '72h31m49.09s' } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { @@ -192,7 +192,7 @@ it("test Combined Observation Task Draft view of IM LBA Survey - 3 Beams edit", fireEvent.change(angel1El, { target: { value: angle1Value } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); await act( async() => { @@ -306,7 +306,7 @@ it("test Combined Observation Task Draft view of IM LBA LoDSS - 5 Beams edit" , fireEvent.change(angel1El, { target: { value: '72h31m49.09s' } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { @@ -314,7 +314,7 @@ it("test Combined Observation Task Draft view of IM LBA LoDSS - 5 Beams edit" , fireEvent.change(angel1El, { target: { value: angle1Value } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); //Save task await act(async () => { @@ -612,7 +612,7 @@ it("test IM BF Cal&Tgt Task Draft edit", async () => { fireEvent.change(angle1El, { target: { value: '82h31m49.09s' } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { @@ -620,7 +620,7 @@ it("test IM BF Cal&Tgt Task Draft edit", async () => { fireEvent.change(angle1El, { target: { value: averageTSValue } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); const angle2El = content.getByLabelText("specification[station_configuration][SAPs][0][digital_pointing][angle2]"); @@ -763,7 +763,7 @@ it("test Simple Beamforming Observation Task Draft edit", async () => { fireEvent.change(angle1El, { target: { value: '82h31m49.09s' } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { @@ -771,7 +771,7 @@ it("test Simple Beamforming Observation Task Draft edit", async () => { fireEvent.change(angle1El, { target: { value: averageTSValue } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); //Save task @@ -946,14 +946,14 @@ it("test Target Observation (IM HBA LoTSS strategy) edit", async () => { fireEvent.change(angle1El, { target: { value: '' } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { fireEvent.change(angle1El, { target: { value: '72h31m49.09s' } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { @@ -961,7 +961,7 @@ it("test Target Observation (IM HBA LoTSS strategy) edit", async () => { fireEvent.change(angle1El, { target: { value: angle1Value } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); //angle2 @@ -1098,14 +1098,14 @@ it("test Calibrator Observation (IM HBA LoTSS strategy) edit", async () => { await new Promise((r) => setTimeout(r, 500)); }); expect(content.queryByTestId('save-btn')).toBeDisabled(); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); await act( async() => { fireEvent.change(nameInputEl, { target: { value: nameInputElValue }}); fireEvent.change(angle1El, { target: { value: averageTSValue } }); await new Promise((r) => setTimeout(r, 500)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); //angle2 @@ -1371,20 +1371,20 @@ it("test IM+BF Observation (Solar Campaign strategy) edit", async () => { fireEvent.change(angle1El, { target: { value: '' } }); await new Promise((r) => setTimeout(r, 150)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { fireEvent.change(angle1El, { target: { value: '72h31m49.09s' } }); await new Promise((r) => setTimeout(r, 150)); 'how to make this work' }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { fireEvent.change(angle1El, { target: { value: '2h31m49.09s' } }); await new Promise((r) => setTimeout(r, 250)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); //angle2 @@ -1552,20 +1552,20 @@ it("Checking Correctness of Custom fields in JEditor using Simple Beamforming Ob fireEvent.change(angle1El, { target: { value: '' } }); await new Promise((r) => setTimeout(r, 150)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { fireEvent.change(angle1El, { target: { value: '72h31m49.09s' } }); await new Promise((r) => setTimeout(r, 150)); 'how to make this work' }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).toBeVisible(); expect(content.queryByTestId('save-btn')).toBeDisabled(); await act( async() => { fireEvent.change(angle1El, { target: { value: '20d31m49.09s' } }); await new Promise((r) => setTimeout(r, 250)); }); - expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 360:00:00.0000degrees.")).not.toBeVisible(); + expect(content.getByText("Not a valid input. Mimimum: 00:00:00.0000hours or 0 or 00:00:00.0000degrees, Maximum:23:59:59.9999hours or 6.2831 or 359:99:99.9999degrees.")).not.toBeVisible(); expect(content.queryByTestId('save-btn')).not.toBeDisabled(); //angle2 diff --git a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js index cc8ed82ab7c..f1d68410f2a 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js @@ -194,9 +194,9 @@ const UnitConverter = { getAngleInputType(input) { if (input.match(/^((\-?)|(\+?))((\d0?d(0?0m)(0?0(\.\d{1,4})?s))|(([0-9]?\d{2,3})d(([0-5]?\d)m)(([0-5]?\d)(\.\d{1,4})?s)))$/)) { return 'dms'; - } else if (input.match(/^((\-?)|(\+?))((\d0(.0{1,4})?)|([0-8]?\d)(\.\d{1,4})?) ?d(egree)?s?$/)) { + } else if (input.match(/^((\-?)|(\+?))((\d0(.0{1,4})?)|([0-9]?\d{1,3})(\.\d{1,4})?) ?d(egree)?s?$/)) { return 'degrees'; - } else if (input.match(/^((\-?)|(\+?))((\d0?:(00:)(00))|(([0-8]\d):(([0-5]\d):)(([0-5]\d)(\.\d{1,4})?))) ?d(egree)?s?$/)) { + } else if (input.match(/^((\-?)|(\+?))((\d0?:(00:)(00))|(([0-9]\d{1,3}):(([0-5]\d):)(([0-5]\d)(\.\d{1,4})?))) ?d(egree)?s?$/)) { return 'deg_format'; } else if (input.match(/^(\+?)([0-1]?\d|2[0-3])h([0-5]?\d)m([0-5]?\d)(\.\d{1,4})?s$/)) { return 'hms'; diff --git a/SAS/TMSS/frontend/tmss_webapp/src/utils/validator.js b/SAS/TMSS/frontend/tmss_webapp/src/utils/validator.js index 48800daca86..ba750731a99 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/utils/validator.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/validator.js @@ -31,6 +31,18 @@ const Validator = { return false } } + if(angleType === 'degrees') { + let radianValue = UnitConverter.convertToRadians(value.split("d")[0]) + if(radianValue< 0 || radianValue > 6.2831835619){ + return false + } + } + if(angleType === 'deg_format') { + let radianValue = UnitConverter.getAngleOutput(value.replace('d', '').replace('egree', '').replace('s', '').replace(' ', ''), true) + if(radianValue< 0 || radianValue > 6.2831835619){ + return false + } + } return true; } return false; @@ -50,6 +62,18 @@ const Validator = { return false } } + if(angleType === 'degrees') { + let radianValue = UnitConverter.convertToRadians(value.split("d")[0]) + if(radianValue< -1.5707963268 || radianValue > 1.5707963268){ + return false + } + } + if(angleType === 'deg_format') { + let radianValue = UnitConverter.getAngleOutput(value.replace('d', '').replace('egree', '').replace('s', '').replace(' ', ''), true) + if(radianValue< -1.5707963268 || radianValue > 1.5707963268){ + return false + } + } return true; } return false; -- GitLab