From 81aeedc52140f3659cd163ed4f854853f8f1fc98 Mon Sep 17 00:00:00 2001 From: John Wu <76966357+jwu-fisker@users.noreply.github.com> Date: Mon, 18 Apr 2022 16:22:22 -0700 Subject: [PATCH] CEC-1369 Fix display of update error (#139) * CEC-1369 Fix display of update error * Update snapshot --- .../CarUpdateStatusProgress.test.jsx | 23 +- .../CarUpdateStatusProgress/Statuses.js | 38 +++ .../CarUpdateStatusProgress.test.jsx.snap | 221 +----------------- .../CarUpdateStatusProgress/index.jsx | 69 +++--- 4 files changed, 84 insertions(+), 267 deletions(-) create mode 100644 src/components/Controls/CarUpdateStatusProgress/Statuses.js diff --git a/src/components/Controls/CarUpdateStatusProgress/CarUpdateStatusProgress.test.jsx b/src/components/Controls/CarUpdateStatusProgress/CarUpdateStatusProgress.test.jsx index 8bfdbfd..eafe670 100644 --- a/src/components/Controls/CarUpdateStatusProgress/CarUpdateStatusProgress.test.jsx +++ b/src/components/Controls/CarUpdateStatusProgress/CarUpdateStatusProgress.test.jsx @@ -3,6 +3,7 @@ import { render, waitFor } from "@testing-library/react"; import CarUpdateStatusProgress from "../CarUpdateStatusProgress"; import useStyles from "../../useStyles"; +import s from "./Statuses"; const TestWrapper = ({ status }) => { const classes = useStyles(); @@ -21,7 +22,7 @@ describe("CarUpdateStatusProgress", () => { name: "manifest_received", status: { car_update_id: 297, - msg: "manifest_received", + msg: s.ManifestReceived, err: -6, extra_info: "", }, @@ -30,7 +31,7 @@ describe("CarUpdateStatusProgress", () => { name: "manifest_accepted", status: { car_update_id: 297, - msg: "manifest_accepted", + msg: s.ManifestAccepted, err: -7, extra_info: "", }, @@ -39,7 +40,7 @@ describe("CarUpdateStatusProgress", () => { name: "download_started", status: { car_update_id: 297, - msg: "download_started", + msg: s.DownloadStarted, err: -14, extra_info: "", }, @@ -53,7 +54,7 @@ describe("CarUpdateStatusProgress", () => { file_total: 1264672, package_current: 0, package_total: 2529856, - msg: "download_start", + msg: s.DownloadStarted, err: 0, }, }, @@ -66,7 +67,7 @@ describe("CarUpdateStatusProgress", () => { file_total: 1264672, package_current: 1048576, package_total: 2529856, - msg: "downloading", + msg: s.Downloading, err: 0, }, }, @@ -79,7 +80,7 @@ describe("CarUpdateStatusProgress", () => { file_total: 1264672, package_current: 1264672, package_total: 2529856, - msg: "download_complete", + msg: s.DownloadCompleted, err: 0, }, }, @@ -87,7 +88,7 @@ describe("CarUpdateStatusProgress", () => { name: "package_download_complete", status: { car_update_id: 297, - msg: "package_download_complete", + msg: s.PackageDownloadCompleted, err: -15, extra_info: "", }, @@ -101,7 +102,7 @@ describe("CarUpdateStatusProgress", () => { file_total: 100, package_current: 0, package_total: 1000, - msg: "download_error", + msg: s.DownloadFailed, err: 0, }, }, @@ -112,7 +113,7 @@ describe("CarUpdateStatusProgress", () => { ecu: "TEST", installed: 5, total_files: 10, - msg: "installing", + msg: s.Installing, err: 0, }, }, @@ -123,7 +124,7 @@ describe("CarUpdateStatusProgress", () => { ecu: "TEST", installed: 10, total_files: 10, - msg: "install_complete", + msg: s.InstallSucceeded, err: 0, }, }, @@ -134,7 +135,7 @@ describe("CarUpdateStatusProgress", () => { ecu: "TEST", installed: 5, total_files: 10, - msg: "install_error", + msg: s.InstallFailed, err: 0, }, }, diff --git a/src/components/Controls/CarUpdateStatusProgress/Statuses.js b/src/components/Controls/CarUpdateStatusProgress/Statuses.js new file mode 100644 index 0000000..b01c659 --- /dev/null +++ b/src/components/Controls/CarUpdateStatusProgress/Statuses.js @@ -0,0 +1,38 @@ +const Statuses = { + Pending: "pending", + ManifestReceived: "manifest_received", + ManifestAccepted: "manifest_accepted", + ManifestRejected: "manifest_rejected", + PreconditionAwait: "requirements_await", + PreconditionSuceeded: "requirements_succeeded", + ManifestCancelReceived: "manifest_cancel_received", + ManifestCancelAccepted: "manifest_cancel_accepted", + ManifestCancelRejected: "manifest_cancel_rejected", + ManifestValidationSucceeded: "manifest_validation_succeeded", + ManifestValidationFailed: "manifest_validation_failed", + DownloadStarted: "download_started", + Downloading: "downloading", + DownloadCompleted: "download_completed", + DownloadFailed: "download_failed", + InstallApprovalAwait: "install_approval_await", + InstallApprovalReceived: "install_approval_received", + InstallStarted: "install_started", + Installing: "installing", + InstallSucceeded: "install_succeeded", + InstallFailed: "install_failed", + RollbackStarted: "rollback_started", + RollbackSucceeded: "rollback_succeeded", + RollbackFailed: "rollback_failed", + CleanupSucceeded: "cleanup_succeeded", + CleanupFailed: "cleanup_failed", + ManifestError: "manifest_error", + ManifestRollback: "manifest_rollback", + ManifestSucceeded: "manifest_succeeded", + ManifesCanceled: "manifest_canceled", + PackageDownloadStarted: "package_download_start", + PackageDownloadCompleted: "package_download_complete", + PackageInstallStarted: "package_install_start", + PackageInstallCompleted: "package_install_complete", +}; + +export default Statuses; diff --git a/src/components/Controls/CarUpdateStatusProgress/__snapshots__/CarUpdateStatusProgress.test.jsx.snap b/src/components/Controls/CarUpdateStatusProgress/__snapshots__/CarUpdateStatusProgress.test.jsx.snap index d50bf67..4f076ea 100644 --- a/src/components/Controls/CarUpdateStatusProgress/__snapshots__/CarUpdateStatusProgress.test.jsx.snap +++ b/src/components/Controls/CarUpdateStatusProgress/__snapshots__/CarUpdateStatusProgress.test.jsx.snap @@ -119,25 +119,6 @@ exports[`CarUpdateStatusProgress Render download_complete 1`] = ` Install

-
- -

- Clean up -

-
@@ -280,25 +261,6 @@ exports[`CarUpdateStatusProgress Render download_error 1`] = ` Install

-
- -

- Clean up -

-
@@ -441,25 +403,6 @@ exports[`CarUpdateStatusProgress Render download_start ECU 1`] = ` Install

-
- -

- Clean up -

-
@@ -493,12 +436,12 @@ exports[`CarUpdateStatusProgress Render download_started 1`] = ` >

-
- -

- Clean up -

-
@@ -763,25 +687,6 @@ exports[`CarUpdateStatusProgress Render downloading 1`] = ` Install

-
- -

- Clean up -

-
@@ -924,25 +829,6 @@ exports[`CarUpdateStatusProgress Render install_complete ECU 1`] = ` Install

-
- -

- Clean up -

-
@@ -1085,25 +971,6 @@ exports[`CarUpdateStatusProgress Render install_error 1`] = ` Install

-
- -

- Clean up -

-
@@ -1246,25 +1113,6 @@ exports[`CarUpdateStatusProgress Render installing 1`] = ` Install

-
- -

- Clean up -

-
@@ -1407,25 +1255,6 @@ exports[`CarUpdateStatusProgress Render manifest_accepted 1`] = ` Install

-
- -

- Clean up -

-
@@ -1568,25 +1397,6 @@ exports[`CarUpdateStatusProgress Render manifest_received 1`] = ` Install

-
- -

- Clean up -

-
@@ -1729,25 +1539,6 @@ exports[`CarUpdateStatusProgress Render package_download_complete 1`] = ` Install

-
- -

- Clean up -

-
diff --git a/src/components/Controls/CarUpdateStatusProgress/index.jsx b/src/components/Controls/CarUpdateStatusProgress/index.jsx index a655923..78c09ae 100644 --- a/src/components/Controls/CarUpdateStatusProgress/index.jsx +++ b/src/components/Controls/CarUpdateStatusProgress/index.jsx @@ -4,78 +4,65 @@ import Typography from "@material-ui/core/Typography"; import clsx from "clsx"; import CircularProgress from "../CircularProgress"; +import s from "./Statuses"; + +const AwaitStatus = -1; +const ErrorStatus = -100; const PHASES = [ { label: "Pending", - events: ["pending"], + events: [s.Pending], progress: () => 100, }, { label: "Received", - events: ["manifest_accepted", "manifest_received"], + events: [s.ManifestAccepted, s.ManifestReceived, s.ManifestRejected], progress: () => 100, }, { label: "Precondition", - events: ["requirements_succeeded"], + events: [s.PreconditionAwait, s.PreconditionSuceeded], progress: () => 100, }, { label: "Download", events: [ - "downloading", - "download_start", - "download_complete", - "download_error", - "package_download_start", + s.Downloading, + s.DownloadStarted, + s.DownloadCompleted, + s.DownloadFailed, + s.PackageDownloadStarted, ], - progress: (msg, progress) => - [ - "package_download_start", - "downloading", - "download_start", - "download_complete", - ].indexOf(msg) > -1 - ? progress - : -100, + progress: (msg, progress) => { + if (msg === s.DownloadFailed) return ErrorStatus; + return progress; + }, }, { label: "Approved", - events: ["package_download_complete", "install_approval_await"], - progress: () => -1, + events: [s.PackageDownloadCompleted, s.InstallApprovalAwait], + progress: () => AwaitStatus, }, { label: "Install", events: [ - "install_approval_received", - "install_start", - "installing", - "install_complete", - "install_error", + s.InstallApprovalReceived, + s.InstallStarted, + s.Installing, + s.InstallSucceeded, + s.InstallFailed, ], - progress: (msg, progress) => - [ - "install_approval_received", - "install_start", - "installing", - "install_complete", - ].indexOf(msg) > -1 - ? progress - : -100, - }, - { - label: "Clean up", - events: ["package_install_complete", "cleanup_failed"], progress: (msg, progress) => { - if (msg === "package_install_complete") return -1; - return -100; + if (msg === s.InstallFailed) return ErrorStatus; + if (msg === s.PackageInstallCompleted) return 100; + return progress; }, }, { label: "Updated", - events: ["cleanup_success", "manifest_succeeded"], - progress: (msg, progress) => 100, + events: [s.ManifestSucceeded], + progress: (_msg, _progress) => 100, }, ];