From 56bef0c34df002879b105a072bd8d0b5ad11d540 Mon Sep 17 00:00:00 2001 From: John Wu <76966357+jwu-fisker@users.noreply.github.com> Date: Mon, 18 Apr 2022 16:50:51 -0700 Subject: [PATCH] CEC-749 Generate cert UI (#141) * Add Create Certificate page * Tests * Update permission check * Use Azure --- .env.dev | 1 + .env.local | 1 + .env.prd | 1 + .env.stg | 1 + .env.template | 1 + src/components/App/App.test.js | 26 +- .../App/__snapshots__/App.test.js.snap | 1850 ++++++++++++++--- .../Table/__snapshots__/index.test.jsx.snap | 51 + .../__snapshots__/CANFiltersTab.test.jsx.snap | 51 + .../Certificates/Add/CreateForm.jsx | 90 + .../Certificates/Add/DownloadCerts.jsx | 50 + .../Certificates/Add/DownloadCerts.test.jsx | 25 + .../__snapshots__/DownloadCerts.test.jsx.snap | 41 + src/components/Certificates/Add/index.jsx | 85 + .../Contexts/CertificateContext.jsx | 50 + .../__snapshots__/index.test.jsx.snap | 11 + .../Controls/DownloadFileLink/index.jsx | 32 + .../Controls/DownloadFileLink/index.test.jsx | 21 + .../Table/__snapshots__/index.test.jsx.snap | 51 + .../Table/__snapshots__/index.test.jsx.snap | 54 +- .../__snapshots__/CANFiltersTab.test.jsx.snap | 51 + .../__snapshots__/VehiclesTab.test.jsx.snap | 54 +- src/components/Layouts/SideMenu.jsx | 16 +- .../__snapshots__/SideMenu.test.jsx.snap | 64 + src/components/Routes/SiteRoutes.jsx | 27 +- src/services/certificatesAPI.js | 17 + src/utils/roles.js | 11 +- src/utils/testing.js | 5 +- 28 files changed, 2449 insertions(+), 289 deletions(-) create mode 100644 src/components/Certificates/Add/CreateForm.jsx create mode 100644 src/components/Certificates/Add/DownloadCerts.jsx create mode 100644 src/components/Certificates/Add/DownloadCerts.test.jsx create mode 100644 src/components/Certificates/Add/__snapshots__/DownloadCerts.test.jsx.snap create mode 100644 src/components/Certificates/Add/index.jsx create mode 100644 src/components/Contexts/CertificateContext.jsx create mode 100644 src/components/Controls/DownloadFileLink/__snapshots__/index.test.jsx.snap create mode 100644 src/components/Controls/DownloadFileLink/index.jsx create mode 100644 src/components/Controls/DownloadFileLink/index.test.jsx create mode 100644 src/services/certificatesAPI.js diff --git a/.env.dev b/.env.dev index 5c21f22..3a7990a 100644 --- a/.env.dev +++ b/.env.dev @@ -2,3 +2,4 @@ REACT_APP_AUTH_SERVICE_URL=https://dev-gw.cloud.fiskerinc.com/compute_auth REACT_APP_UPLOAD_SERVICE_URL=https://dev-gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://dev-ota-admin.cloud.fiskerinc.com REACT_APP_SUPERSET_URL=http://superset-dev.fisker.internal +REACT_APP_CERT_SERVICE_URL=https://dev-gw.cloud.fiskerinc.com/certificate diff --git a/.env.local b/.env.local index 2d4b6dd..234f2fa 100644 --- a/.env.local +++ b/.env.local @@ -2,3 +2,4 @@ REACT_APP_AUTH_SERVICE_URL=http://localhost/compute_auth REACT_APP_UPLOAD_SERVICE_URL=http://localhost/ota_update REACT_APP_AUTH_CALLBACK_URL=http://localhost:3000 REACT_APP_SUPERSET_URL=http://superset-dev.fisker.internal +REACT_APP_CERT_SERVICE_URL=http://localhost/certificate diff --git a/.env.prd b/.env.prd index d7fa640..d89cfe0 100644 --- a/.env.prd +++ b/.env.prd @@ -2,3 +2,4 @@ REACT_APP_AUTH_SERVICE_URL=https://gw.cloud.fiskerinc.com/compute_auth REACT_APP_UPLOAD_SERVICE_URL=https://gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://ota-admin.cloud.fiskerinc.com REACT_APP_SUPERSET_URL=http://superset.fisker.internal +REACT_APP_CERT_SERVICE_URL=https://gw.cloud.fiskerinc.com/certificate diff --git a/.env.stg b/.env.stg index b6162e6..3903193 100644 --- a/.env.stg +++ b/.env.stg @@ -2,3 +2,4 @@ REACT_APP_AUTH_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/compute_auth REACT_APP_UPLOAD_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://stg-ota-admin.cloud.fiskerinc.com REACT_APP_SUPERSET_URL=http://superset-stg.fisker.internal +REACT_APP_CERT_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/certificate diff --git a/.env.template b/.env.template index 2d4b6dd..234f2fa 100644 --- a/.env.template +++ b/.env.template @@ -2,3 +2,4 @@ REACT_APP_AUTH_SERVICE_URL=http://localhost/compute_auth REACT_APP_UPLOAD_SERVICE_URL=http://localhost/ota_update REACT_APP_AUTH_CALLBACK_URL=http://localhost:3000 REACT_APP_SUPERSET_URL=http://superset-dev.fisker.internal +REACT_APP_CERT_SERVICE_URL=http://localhost/certificate diff --git a/src/components/App/App.test.js b/src/components/App/App.test.js index 2cc4738..9a9157b 100644 --- a/src/components/App/App.test.js +++ b/src/components/App/App.test.js @@ -37,22 +37,35 @@ const check = async (path, selector, compare) => { const sleepAndCheck = async (path, selector, compare) => { const container = await renderRoute(path); - await waitFor(() => { }); + await waitFor(() => {}); expect(container.querySelector(selector).innerHTML).toEqual(compare); expect(container).toMatchSnapshot(); }; describe("App", () => { + const rxMakeStyles = /makeStyles-(\w+)-(\d+)/gi; + beforeAll(() => { // Stablize Table Pagination control ids expect.addSnapshotSerializer({ test: function (val) { - return val && typeof val === "string" && val.indexOf("mui-") >= 0; + return val && typeof val === "string" && val.indexOf("mui-") > -1; }, print: function (val) { let str = val; str = str.replace(/mui-\d*/g, "mui-00000"); + return `"${str}"`; + }, + }); + expect.addSnapshotSerializer({ + test: (val) => { + return val && typeof val === "string" && val.search(rxMakeStyles) > -1; + }, + print: function (val) { + let str = val; + str = str.replace(rxMakeStyles, "makeStyles-$1-0000"); + return `"${str}"`; }, }); @@ -107,6 +120,10 @@ describe("App", () => { ); }); + it("Route /tools/certificates/add unauthenticated", async () => { + await check("/tools/certificates/add", "span.MuiButton-label", "Sign In"); + }); + it("Route /page-not-found unauthenticated", async () => { await check("/page-not-found", "h1", "Page Not Found"); }); @@ -159,4 +176,9 @@ describe("App", () => { setToken(TEST_AUTH_OBJECT); await check("/vehicle-status/FISKER123", "h6", "Vehicle FISKER123 Details"); }); + + it("Route /tools/certificates/add authenticated", async () => { + setToken(TEST_AUTH_OBJECT); + await check("/tools/certificates/add", "h6", "Create Certificate"); + }); }); diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index f041185..097aefb 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -6,10 +6,10 @@ exports[`App Route / authenticated 1`] = ` data-testid="mocked-userprovider" >