From 7d27a0193f8f4259df1226755dbb82185324c497 Mon Sep 17 00:00:00 2001 From: arpanetus Date: Wed, 14 Dec 2022 22:34:11 +0600 Subject: [PATCH 1/2] CEC-2389 Add unit tests for SMS Context and SMS form (#247) --- src/components/Contexts/SMSContext.jsx | 4 + src/components/Contexts/SMSContext.test.jsx | 92 ++++++++++ .../Contexts/__mocks__/SMSContext.jsx | 28 +++ src/components/SMS/Send/SendForm.test.jsx | 19 +++ .../Send/__snapshots__/SendForm.test.jsx.snap | 160 ++++++++++++++++++ .../Send/__snapshots__/index.test.jsx.snap | 3 + src/components/SMS/Send/index.test.jsx | 44 +++++ src/services/__mocks__/smsAPI.js | 19 +++ src/services/smsAPI.js | 8 +- 9 files changed, 373 insertions(+), 4 deletions(-) create mode 100644 src/components/Contexts/SMSContext.test.jsx create mode 100644 src/components/Contexts/__mocks__/SMSContext.jsx create mode 100644 src/components/SMS/Send/SendForm.test.jsx create mode 100644 src/components/SMS/Send/__snapshots__/SendForm.test.jsx.snap create mode 100644 src/components/SMS/Send/__snapshots__/index.test.jsx.snap create mode 100644 src/components/SMS/Send/index.test.jsx create mode 100644 src/services/__mocks__/smsAPI.js diff --git a/src/components/Contexts/SMSContext.jsx b/src/components/Contexts/SMSContext.jsx index c40de21..e2fb4bd 100644 --- a/src/components/Contexts/SMSContext.jsx +++ b/src/components/Contexts/SMSContext.jsx @@ -19,6 +19,10 @@ export class SMS { * @param {SMS} data */ const validateSend = (data) => { + if (data == null) { + throw new Error("No SMS data provided"); + } + if (!data.messageText) throw new Error("message is required"); if (!data.ICCID) throw new Error("ICCID is required"); }; diff --git a/src/components/Contexts/SMSContext.test.jsx b/src/components/Contexts/SMSContext.test.jsx new file mode 100644 index 0000000..92a2130 --- /dev/null +++ b/src/components/Contexts/SMSContext.test.jsx @@ -0,0 +1,92 @@ +jest.mock("../../services/smsAPI"); + +import { + render, + cleanup, + screen, + fireEvent, + waitFor, +} from "@testing-library/react"; +import { SMSProvider, useSMSContext } from "./SMSContext"; +import { StatusProvider, useStatusContext } from "./StatusContext"; + +const checkBaseResults = (error, busy) => { + expect(screen.getByTestId("error").innerHTML).toEqual(error); + expect(screen.getByTestId("busy").innerHTML).toEqual(busy); +} + +describe("SMSContext", () => { + describe("sendSMS", () => { + beforeEach(async () => { + const TestComp = () => { + const {busy, sendSMS} = useSMSContext(); + const {message, setMessage} = useStatusContext(); + const send = async (data) => { + try { + await + sendSMS(data); + } catch (e) { + setMessage(e.message); + } + } + + return ( + <> +
{message}
+
{busy.toString()}
+ + + + +`; diff --git a/src/components/SMS/Send/__snapshots__/index.test.jsx.snap b/src/components/SMS/Send/__snapshots__/index.test.jsx.snap new file mode 100644 index 0000000..d03c0ae --- /dev/null +++ b/src/components/SMS/Send/__snapshots__/index.test.jsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SMS Send Component Render 1`] = `undefined`; diff --git a/src/components/SMS/Send/index.test.jsx b/src/components/SMS/Send/index.test.jsx new file mode 100644 index 0000000..29ce3dd --- /dev/null +++ b/src/components/SMS/Send/index.test.jsx @@ -0,0 +1,44 @@ +import {TEST_AUTH_OBJECT_FISKER, TEST_TOKEN_FISKER} from "../../../utils/testing"; + +jest.mock("../../Contexts/SMSContext"); +jest.mock("../../Contexts/UserContext"); + + +import SMSSend from "./index"; +import {BrowserRouter} from "react-router-dom"; +import {UserProvider, setToken} from "../../Contexts/UserContext"; +import {StatusProvider} from "../../Contexts/StatusContext"; +import addSnapshotSerializer from "../../../utils/snapshot"; +import {render, waitFor} from "@testing-library/react"; + + +const renderSendSMS = async () => { + const {container} = render( + + + + + + + + ); + await waitFor(() => { + /* render */ + }); + + return container; +} + + +describe("SMS Send Component", () => { + beforeAll(() => { + setToken(TEST_AUTH_OBJECT_FISKER); + addSnapshotSerializer(expect); + }); + + it("Render", async () => { + // setToken(TEST_AUTH_OBJECT_FISKER); + const {container} = await renderSendSMS(); + expect(container).toMatchSnapshot(); + }); +}); \ No newline at end of file diff --git a/src/services/__mocks__/smsAPI.js b/src/services/__mocks__/smsAPI.js new file mode 100644 index 0000000..6c9a21a --- /dev/null +++ b/src/services/__mocks__/smsAPI.js @@ -0,0 +1,19 @@ +const smsAPI ={ + send: async(data, token) => { + return { + smsMsgID:438222039, + status:"Pending", + messageText:"Test message", + senderLogin:"tfbenterpriseapiuser", + sentTo:"18707906682", + sentFrom: "Server", + msgType: "MT", + dateSent: "2021-08-17T15:00:00.000Z", + dateModified: "2021-08-17T15:00:00.000Z", + ICCID: "8988300000000000000", + } + } +} + + +export default smsAPI; \ No newline at end of file diff --git a/src/services/smsAPI.js b/src/services/smsAPI.js index d82355d..a01c196 100644 --- a/src/services/smsAPI.js +++ b/src/services/smsAPI.js @@ -6,10 +6,10 @@ const API_ENDPOINT = process.env.REACT_APP_OTA_SERVICE_URL; const smsAPI = { /** - * Sends a SMS to an ICCID - * @param {*} data - * @param {*} token - * @returns + * Sends an SMS to an ICCID + * @param {*} data + * @param {*} token + * @returns */ send: async (data, token) => fetch(`${API_ENDPOINT}/sms`, { From e2aecc9f3bc9586942fd9f290202d078cc937036 Mon Sep 17 00:00:00 2001 From: Paul Adamsen <117673433+pauladamseniii@users.noreply.github.com> Date: Wed, 14 Dec 2022 14:21:31 -0500 Subject: [PATCH 2/2] CEC-3320 - Add other car fields to edit form (#248) * CEC-3320 - Add other car fields to edit form * info_source readonly --- .../App/__snapshots__/App.test.js.snap | 57 +++++ .../Details/__snapshots__/index.test.jsx.snap | 57 +++++ src/components/Cars/Status/Details/index.jsx | 27 +++ .../__snapshots__/DetailsTab.test.jsx.snap | 57 +++++ .../Status/__snapshots__/index.test.jsx.snap | 54 +++++ .../Update/__snapshots__/index.test.jsx.snap | 224 ++++++++++++++++++ src/components/Cars/Update/index.jsx | 115 +++++++++ 7 files changed, 591 insertions(+) diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index 813de41..6d15848 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -7958,6 +7958,63 @@ exports[`App Route /vehicle-status authenticated 1`] = ` : FISKER123

+

+ + ICCID + + : +

+

+ + Model + + : + Ocean +

+

+ + Year + + : + 2021 +

+

+ + Trim + + : + Basic +

+

+ + Country + + : +

+

+ + Powertrain Type + + : +

+

+ + Restraint Type + + : +

+

+ + Body Type + + : +

+

+ + Info Source + + : +

Log Level diff --git a/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap b/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap index bf46c26..f8ee4b8 100644 --- a/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap +++ b/src/components/Cars/Status/Details/__snapshots__/index.test.jsx.snap @@ -30,6 +30,63 @@ exports[`VehicleDetailsTab Render 1`] = ` : TESTVIN1234567890

+

+ + ICCID + + : +

+

+ + Model + + : + Ocean +

+

+ + Year + + : + 2021 +

+

+ + Trim + + : + Basic +

+

+ + Country + + : +

+

+ + Powertrain Type + + : +

+

+ + Restraint Type + + : +

+

+ + Body Type + + : +

+

+ + Info Source + + : +

Log Level diff --git a/src/components/Cars/Status/Details/index.jsx b/src/components/Cars/Status/Details/index.jsx index bfb1c77..3294a80 100644 --- a/src/components/Cars/Status/Details/index.jsx +++ b/src/components/Cars/Status/Details/index.jsx @@ -67,6 +67,33 @@ const MainForm = ({ vin }) => {

VIN: {vin}

+

+ ICCID: {vehicle.iccid} +

+

+ Model: {vehicle.model} +

+

+ Year: {vehicle.year} +

+

+ Trim: {vehicle.trim} +

+

+ Country: {vehicle.country} +

+

+ Powertrain Type: {vehicle.powertrain} +

+

+ Restraint Type: {vehicle.restraint} +

+

+ Body Type: {vehicle.body_type} +

+

+ Info Source: {vehicle.info_source} +

{vehicle.log_level != null && (

Log Level: {vehicle.log_level} diff --git a/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap b/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap index d23af12..08c875a 100644 --- a/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap +++ b/src/components/Cars/Status/__snapshots__/DetailsTab.test.jsx.snap @@ -38,6 +38,63 @@ exports[`DetailsTab Render 1`] = ` : TESTVIN1234567890

+

+ + ICCID + + : +

+

+ + Model + + : + Ocean +

+

+ + Year + + : + 2021 +

+

+ + Trim + + : + Basic +

+

+ + Country + + : +

+

+ + Powertrain Type + + : +

+

+ + Restraint Type + + : +

+

+ + Body Type + + : +

+

+ + Info Source + + : +

Log Level diff --git a/src/components/Cars/Status/__snapshots__/index.test.jsx.snap b/src/components/Cars/Status/__snapshots__/index.test.jsx.snap index 192d0e9..23e1eba 100644 --- a/src/components/Cars/Status/__snapshots__/index.test.jsx.snap +++ b/src/components/Cars/Status/__snapshots__/index.test.jsx.snap @@ -195,6 +195,60 @@ exports[`CarStatus Render 1`] = ` : TESTVIN1234567890

+

+ + ICCID + + : +

+

+ + Model + + : +

+

+ + Year + + : +

+

+ + Trim + + : +

+

+ + Country + + : +

+

+ + Powertrain Type + + : +

+

+ + Restraint Type + + : +

+

+ + Body Type + + : +

+

+ + Info Source + + : +

+
+ +
+ + +
+
@@ -210,6 +247,193 @@ exports[`VehicleUpdate Render 1`] = `
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+