CEC-2291 Remote Commands (#194)

This commit is contained in:
arpanetus
2022-09-07 23:21:57 +06:00
committed by GitHub
parent 153c6bdcf7
commit aa5a1e20e0
19 changed files with 1187 additions and 148 deletions

View File

@@ -164,10 +164,10 @@ export const VehicleProvider = ({ children }) => {
}
};
const sendCommand = async (vins, command, parameters, token) => {
const sendCommand = async (vins, command, token) => {
try {
setBusy(true);
const result = await api.sendCommand(vins, command, parameters, token);
const result = await api.sendCommand(vins, command, token);
if (result.error)
throw new Error(`Send command error. ${result.message}`);
return result;

View File

@@ -317,6 +317,55 @@ describe("VehicleContext", () => {
checkBaseResults("", "false");
});
});
describe("sendCommand", () => {
beforeEach(async () => {
const TestComp = () => {
const {busy, sendCommand} = useVehicleContext();
const { message, setMessage } = useStatusContext();
const sendC = async (vin, command) => {
try {
await sendCommand(vin, command);
} catch (e) {
setMessage(e.message);
}
};
return (
<>
<div data-testid="error">{message}</div>
<div data-testid="busy">{busy.toString()}</div>
<button data-testid="sendCommandNullVin" onClick={() => sendC(null, {command:"doors_lock"})} />
<button data-testid="sendCommandNonexistentVin" onClick={() => sendC(["11111111111111111"], {command:"doors_lock"})} />
<button
data-testid="sendCommandVin"
onClick={() => sendC("3C4PDCBG0ET127145", {command:"doors_lock"})}
/>
<button
data-testid="sendCommandWrongCommand"
onClick={() => sendC("3C4PDCBG0ET127145", {command:"noSuchCommand"})}
/>
</>
);}
render(
<StatusProvider>
<VehicleProvider>
<TestComp />
</VehicleProvider>
</StatusProvider>
);
});
afterEach(() => {
cleanup();
});
it("initial state", () => {
checkBaseResults("", "false");
});
})
});
const expectedFilters = [