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()}
+
+
+
+ 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`] = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+