Merge branch 'develop' into release/0.0.3

This commit is contained in:
jwu-fisker
2022-12-20 10:03:35 -08:00
16 changed files with 964 additions and 4 deletions

View File

@@ -7958,6 +7958,63 @@ exports[`App Route /vehicle-status authenticated 1`] = `
:
FISKER123
</p>
<p>
<b>
ICCID
</b>
:
</p>
<p>
<b>
Model
</b>
:
Ocean
</p>
<p>
<b>
Year
</b>
:
2021
</p>
<p>
<b>
Trim
</b>
:
Basic
</p>
<p>
<b>
Country
</b>
:
</p>
<p>
<b>
Powertrain Type
</b>
:
</p>
<p>
<b>
Restraint Type
</b>
:
</p>
<p>
<b>
Body Type
</b>
:
</p>
<p>
<b>
Info Source
</b>
:
</p>
<p>
<b>
Log Level

View File

@@ -30,6 +30,63 @@ exports[`VehicleDetailsTab Render 1`] = `
:
TESTVIN1234567890
</p>
<p>
<b>
ICCID
</b>
:
</p>
<p>
<b>
Model
</b>
:
Ocean
</p>
<p>
<b>
Year
</b>
:
2021
</p>
<p>
<b>
Trim
</b>
:
Basic
</p>
<p>
<b>
Country
</b>
:
</p>
<p>
<b>
Powertrain Type
</b>
:
</p>
<p>
<b>
Restraint Type
</b>
:
</p>
<p>
<b>
Body Type
</b>
:
</p>
<p>
<b>
Info Source
</b>
:
</p>
<p>
<b>
Log Level

View File

@@ -67,6 +67,33 @@ const MainForm = ({ vin }) => {
<p>
<b>VIN</b>: {vin}
</p>
<p>
<b>ICCID</b>: {vehicle.iccid}
</p>
<p>
<b>Model</b>: {vehicle.model}
</p>
<p>
<b>Year</b>: {vehicle.year}
</p>
<p>
<b>Trim</b>: {vehicle.trim}
</p>
<p>
<b>Country</b>: {vehicle.country}
</p>
<p>
<b>Powertrain Type</b>: {vehicle.powertrain}
</p>
<p>
<b>Restraint Type</b>: {vehicle.restraint}
</p>
<p>
<b>Body Type</b>: {vehicle.body_type}
</p>
<p>
<b>Info Source</b>: {vehicle.info_source}
</p>
{vehicle.log_level != null && (
<p>
<b>Log Level</b>: {vehicle.log_level}

View File

@@ -38,6 +38,63 @@ exports[`DetailsTab Render 1`] = `
:
TESTVIN1234567890
</p>
<p>
<b>
ICCID
</b>
:
</p>
<p>
<b>
Model
</b>
:
Ocean
</p>
<p>
<b>
Year
</b>
:
2021
</p>
<p>
<b>
Trim
</b>
:
Basic
</p>
<p>
<b>
Country
</b>
:
</p>
<p>
<b>
Powertrain Type
</b>
:
</p>
<p>
<b>
Restraint Type
</b>
:
</p>
<p>
<b>
Body Type
</b>
:
</p>
<p>
<b>
Info Source
</b>
:
</p>
<p>
<b>
Log Level

View File

@@ -195,6 +195,60 @@ exports[`CarStatus Render 1`] = `
:
TESTVIN1234567890
</p>
<p>
<b>
ICCID
</b>
:
</p>
<p>
<b>
Model
</b>
:
</p>
<p>
<b>
Year
</b>
:
</p>
<p>
<b>
Trim
</b>
:
</p>
<p>
<b>
Country
</b>
:
</p>
<p>
<b>
Powertrain Type
</b>
:
</p>
<p>
<b>
Restraint Type
</b>
:
</p>
<p>
<b>
Body Type
</b>
:
</p>
<p>
<b>
Info Source
</b>
:
</p>
</div>
<div
class="MuiGrid-root makeStyles-textCenterAlign-0 MuiGrid-item MuiGrid-grid-md-12"

View File

@@ -70,6 +70,43 @@ exports[`VehicleUpdate Render 1`] = `
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined"
data-shrink="true"
for="iccid"
id="iccid-label"
>
ICCID
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="iccid"
maxlength="50"
name="iccid"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0 PrivateNotchedOutline-legendNotched-0"
>
<span>
ICCID
</span>
</legend>
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
@@ -210,6 +247,193 @@ exports[`VehicleUpdate Render 1`] = `
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined"
data-shrink="true"
for="country"
id="country-label"
>
Country
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="country"
maxlength="256"
name="country"
shrink="1"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0 PrivateNotchedOutline-legendNotched-0"
>
<span>
Country
</span>
</legend>
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined"
data-shrink="true"
for="powertrain"
id="powertrain-label"
>
Powertrain Type
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="powertrain"
maxlength="256"
name="powertrain"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0 PrivateNotchedOutline-legendNotched-0"
>
<span>
Powertrain Type
</span>
</legend>
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined"
data-shrink="true"
for="restraint"
id="restraint-label"
>
Restraint Type
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="restraint"
maxlength="256"
name="restraint"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0 PrivateNotchedOutline-legendNotched-0"
>
<span>
Restraint Type
</span>
</legend>
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined"
data-shrink="true"
for="body_type"
id="body_type-label"
>
Body Type
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="body_type"
maxlength="256"
name="body_type"
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0 PrivateNotchedOutline-legendNotched-0"
>
<span>
Body Type
</span>
</legend>
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined Mui-disabled Mui-disabled"
data-shrink="true"
for="info_source"
id="info_source-label"
>
Info Source
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root Mui-disabled Mui-disabled MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input Mui-disabled Mui-disabled"
disabled=""
id="info_source"
name="info_source"
readonly=""
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0 PrivateNotchedOutline-legendNotched-0"
>
<span>
Info Source
</span>
</legend>
</fieldset>
</div>
</div>
<label
class="MuiFormLabel-root"
id="demo-row-radio-buttons-group-label"

View File

@@ -32,9 +32,15 @@ const MainForm = () => {
const [redirect, setRedirect] = useState(null);
const classes = useStyles();
const iccidEl = useRef(null);
const modelEl = useRef(null);
const yearEl = useRef(null);
const trimEl = useRef(null);
const countryEl = useRef(null);
const powertrainEl = useRef(null);
const restraintEl = useRef(null);
const bodyTypeEl = useRef(null);
const infoSourceEl = useRef(null);
const [selectedLogLevel, setSelectedLogLevel] = useState("info");
const [canbusEnabled, setCANBusEnabled] = useState(true);
const [dataLoggerEnabled, setDataLoggerEnabled] = useState(false);
@@ -71,9 +77,15 @@ const MainForm = () => {
useEffect(() => {
setSelectedLogLevel(vehicle.log_level ?? selectedLogLevel);
iccidEl.current.value = vehicle.iccid ?? ""
modelEl.current.value = vehicle.model ?? "Ocean"
yearEl.current.value = vehicle.year ?? "2022"
trimEl.current.value = vehicle.trim ?? "Base"
countryEl.current.value = vehicle.country ?? ""
powertrainEl.current.value = vehicle.powertrain ?? ""
restraintEl.current.value = vehicle.restraint ?? ""
bodyTypeEl.current.value = vehicle.body_type ?? ""
infoSourceEl.current.value = vehicle.info_source ?? ""
if (vehicle.canbus) {
setCANBusEnabled(vehicle.canbus.enabled ?? canbusEnabled);
@@ -110,9 +122,14 @@ const MainForm = () => {
const formData = {
vin: vin,
iccid: iccidEl.current.value,
model: modelEl.current.value,
year: parseInt(yearEl.current.value),
trim: trimEl.current.value,
country: countryEl.current.value,
powertrain: powertrainEl.current.value,
restraint: restraintEl.current.value,
body_type: bodyTypeEl.current.value,
log_level: selectedLogLevel,
canbus: {
enabled: canbusEnabled,
@@ -155,6 +172,22 @@ const MainForm = () => {
required
fullWidth
/>
<TextField
id="iccid"
name="iccid"
label="ICCID"
InputLabelProps={{
shrink: true
}}
defaultValue=""
variant="outlined"
margin="normal"
inputProps={{
maxLength: "50",
}}
fullWidth
inputRef={iccidEl}
/>
<TextField
id="model"
name="model"
@@ -200,6 +233,88 @@ const MainForm = () => {
fullWidth
inputRef={trimEl}
/>
<TextField
id="country"
name="country"
label="Country"
InputLabelProps={{
shrink: true
}}
defaultValue=""
variant="outlined"
margin="normal"
inputProps={{
shrink: +true,
maxLength: "256",
}}
fullWidth
inputRef={countryEl}
/>
<TextField
id="powertrain"
name="powertrain"
label="Powertrain Type"
InputLabelProps={{
shrink: true
}}
defaultValue=""
variant="outlined"
margin="normal"
inputProps={{
maxLength: "256",
}}
fullWidth
inputRef={powertrainEl}
/>
<TextField
id="restraint"
name="restraint"
label="Restraint Type"
InputLabelProps={{
shrink: true
}}
defaultValue=""
variant="outlined"
margin="normal"
inputProps={{
maxLength: "256",
}}
fullWidth
inputRef={restraintEl}
/>
<TextField
id="body_type"
name="body_type"
label="Body Type"
InputLabelProps={{
shrink: true
}}
defaultValue=""
variant="outlined"
margin="normal"
inputProps={{
maxLength: "256",
}}
fullWidth
inputRef={bodyTypeEl}
/>
<TextField
id="info_source"
name="info_source"
label="Info Source"
InputLabelProps={{
shrink: true
}}
inputProps={{
readOnly: true
}}
disabled
defaultValue=""
variant="outlined"
margin="normal"
fullWidth
inputRef={infoSourceEl}
/>
<FormLabel id="demo-row-radio-buttons-group-label">Log Level</FormLabel>
<RadioGroup
row

View File

@@ -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");
};

View File

@@ -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 (
<>
<div data-testid="error">{message}</div>
<div data-testid="busy">{busy.toString()}</div>
<button
data-testid="sendSMSNull"
onClick={() => send(null)}
/>
<button
data-testid="sendSMSNoICCID"
onClick={() => send({messageText: "test"})}
/>
<button
data-testid="sendSMSNoMessage"
onClick={() => send({ICCID: "test"})}
/>
<button
data-testid="sendSMS"
onClick={() => send({messageText: "test", ICCID: "test"})}
/>
</>
);
};
render(
<StatusProvider>
<SMSProvider>
<TestComp/>
</SMSProvider>
</StatusProvider>
);
});
afterEach(cleanup);
it("initial state", () => {
checkBaseResults("", "false");
});
it("should return an error if no data is passed", async () => {
fireEvent.click(screen.getByTestId("sendSMSNull"));
await waitFor(() => checkBaseResults("No SMS data provided", "false"));
});
it("should return an error if no ICCID is passed", async () => {
fireEvent.click(screen.getByTestId("sendSMSNoICCID"));
await waitFor(() => checkBaseResults("ICCID is required", "false"));
});
it("should return an error if no message is passed", async () => {
fireEvent.click(screen.getByTestId("sendSMSNoMessage"));
await waitFor(() => checkBaseResults("message is required", "false"));
});
it("should work as expected", async () => {
fireEvent.click(screen.getByTestId("sendSMS"));
await waitFor(() => checkBaseResults("", "true"));
});
});
});

View File

@@ -0,0 +1,28 @@
import React from 'react';
const SMSContext = React.createContext();
let busy = false;
const smsResult = {
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 const SMSProvider = ({ children }) => {
return <div data-testid="mocked-smsprovider">{children}</div>;
}
export const useSMSContext = () => {
return {
busy,
sendSMS: jest.fn(() => smsResult),
};
}

View File

@@ -0,0 +1,19 @@
import React from "react";
import {render, waitFor} from "@testing-library/react";
import SendForm from "./SendForm";
import addSnapshotSerializer from "../../../utils/snapshot";
describe("Send Form Component", () => {
beforeAll(() => {
addSnapshotSerializer(expect);
});
it("Render", async () => {
const {container} = render(<SendForm onSend={()=>{}} busy={false}/>);
await waitFor(() => {
/* render */
});
expect(container).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,160 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Send Form Component Render 1`] = `
<div>
<div
class="makeStyles-paper-0"
>
<form
action="{onSubmit}"
class="makeStyles-form-0"
novalidate=""
>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required"
data-shrink="false"
for="iccid"
id="iccid-label"
>
ICCID
<span
aria-hidden="true"
class="MuiFormLabel-asterisk MuiInputLabel-asterisk"
>
*
</span>
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="iccid"
maxlength="50"
minlength="15"
name="iccid"
required=""
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0"
>
<span>
ICCID
 *
</span>
</legend>
</fieldset>
</div>
</div>
<div
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required"
data-shrink="false"
for="message"
id="message-label"
>
Message
<span
aria-hidden="true"
class="MuiFormLabel-asterisk MuiInputLabel-asterisk"
>
*
</span>
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-fullWidth MuiInputBase-formControl"
>
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
id="message"
maxlength="320"
name="message"
required=""
type="text"
value=""
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-0 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-0"
>
<span>
Message
 *
</span>
</legend>
</fieldset>
</div>
</div>
<label
class="MuiFormControlLabel-root"
>
<span
aria-disabled="false"
class="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-0 MuiCheckbox-root MuiCheckbox-colorPrimary MuiIconButton-colorPrimary"
>
<span
class="MuiIconButton-label"
>
<input
class="PrivateSwitchBase-input-0"
data-indeterminate="false"
type="checkbox"
value="isAwaited"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
/>
</svg>
</span>
<span
class="MuiTouchRipple-root"
/>
</span>
<span
class="MuiTypography-root MuiFormControlLabel-label MuiTypography-body1"
>
Await delivery
</span>
</label>
<button
class="MuiButtonBase-root MuiButton-root MuiButton-contained makeStyles-submit-0 MuiButton-containedPrimary MuiButton-fullWidth"
tabindex="0"
type="submit"
>
<span
class="MuiButton-label"
>
Send
</span>
<span
class="MuiTouchRipple-root"
/>
</button>
</form>
</div>
</div>
`;

View File

@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`SMS Send Component Render 1`] = `undefined`;

View File

@@ -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(
<StatusProvider>
<BrowserRouter>
<UserProvider>
<SMSSend/>
</UserProvider>
</BrowserRouter>
</StatusProvider>
);
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();
});
});

View File

@@ -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;

View File

@@ -6,7 +6,7 @@ const API_ENDPOINT = process.env.REACT_APP_OTA_SERVICE_URL;
const smsAPI = {
/**
* Sends a SMS to an ICCID
* Sends an SMS to an ICCID
* @param {*} data
* @param {*} token
* @returns