From 85cf389ad46a14a91a71e701ee40c788c1d0349a Mon Sep 17 00:00:00 2001
From: Johanna Szepanski <johanna.szepanski@softhouse.se>
Date: Mon, 19 Aug 2024 08:17:43 +0200
Subject: [PATCH] Updated stories and added different states to host details
 story

---
 src/components/IOC/IOCDetails/IOCDetails.js   |  2 +-
 .../host/HostStatus/HostStatusData.js         |  5 +-
 src/mocks/fixtures/HostAlerts.json            | 58 +++++++++----------
 src/mocks/fixtures/HostStatus.json            | 25 +++-----
 src/mocks/fixtures/Hosts.json                 | 19 ++----
 .../common/host/HostTable.stories.js          |  3 +
 .../views/Host/HostDetailsView.stories.js     | 34 +++++++++--
 7 files changed, 71 insertions(+), 75 deletions(-)

diff --git a/src/components/IOC/IOCDetails/IOCDetails.js b/src/components/IOC/IOCDetails/IOCDetails.js
index 459b35d3..fad6a18f 100644
--- a/src/components/IOC/IOCDetails/IOCDetails.js
+++ b/src/components/IOC/IOCDetails/IOCDetails.js
@@ -6,7 +6,7 @@ import {
   useAPIMethod,
   AlertBannerList
 } from "@ess-ics/ce-ui-common";
-import { IOCStatus } from "../IOCTable/IOCStatus";
+import { IOCStatus } from "../IOCStatus";
 import AccessControl from "../../auth/AccessControl";
 
 export function diff(o1, o2) {
diff --git a/src/components/host/HostStatus/HostStatusData.js b/src/components/host/HostStatus/HostStatusData.js
index 644df699..ce72ed31 100644
--- a/src/components/host/HostStatus/HostStatusData.js
+++ b/src/components/host/HostStatus/HostStatusData.js
@@ -1,14 +1,13 @@
 import { SEVERITY, STATUS } from "../../common/Status";
 
 export const HOST_STATUS = {
-  available: "available",
-  unreachable: "unreachable"
+  available: "AVAILABLE",
+  unreachable: "UNREACHABLE"
 };
 
 export const getHostStatus = (state, alert) => {
   let { status } = state;
   const alertSeverity = alert?.alertSeverity?.toLowerCase();
-  status = status.toLowerCase();
 
   if (
     status === HOST_STATUS.available &&
diff --git a/src/mocks/fixtures/HostAlerts.json b/src/mocks/fixtures/HostAlerts.json
index df0bae54..7aabbf8f 100644
--- a/src/mocks/fixtures/HostAlerts.json
+++ b/src/mocks/fixtures/HostAlerts.json
@@ -1,6 +1,6 @@
 [
   {
-    "hostId": "MjE5MV9mYWxzZQ=",
+    "hostId": "MjE5MV9mYWxzZQ",
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -11,7 +11,7 @@
     ]
   },
   {
-    "hostId": "MjIwNV9mYWxzZQ=",
+    "hostId": "MjIwNV9mYWxzZQ",
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -22,41 +22,35 @@
     ]
   },
   {
-    "hostId": "MjE3Nl9mYWxzZQ",
-    "alertSeverity": "INFO",
+    "hostId": "MzcwNF9mYWxzZQ",
+    "alertSeverity": "WARNING",
     "alerts": [
       {
-        "type": "INFO",
-        "message": "There are no IOCs deployed to host",
+        "type": "WARNING",
+        "message": "This is a warning message",
         "link": null
       }
     ]
   },
   {
-    "hostId": "MzcwNF9mYWxzZQ",
-    "alertSeverity": "INFO",
+    "hostId": "NDkzN190cnVl",
+    "alertSeverity": "ERROR",
     "alerts": [
       {
-        "type": "INFO",
-        "message": "There are no IOCs deployed to host",
+        "type": "ERROR",
+        "message": "This is an error message",
         "link": null
-      }
-    ]
-  },
-
-  {
-    "hostId": "MzcwM19mYWxzZQ",
-    "alertSeverity": "INFO",
-    "alerts": [
+      },
       {
-        "type": "INFO",
-        "message": "There are no IOCs deployed to host",
+        "type": "WARNING",
+        "message": "This is a warning message",
         "link": null
       }
     ]
   },
+
   {
-    "hostId": "NDkzN190cnVl",
+    "hostId": "MjEwOF9mYWxzZQ",
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -67,7 +61,7 @@
     ]
   },
   {
-    "hostId": "MjEwOF9mYWxzZQ",
+    "hostId": "MjE5M19mYWxzZQ",
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -79,17 +73,17 @@
   },
   {
     "hostId": "NDk5MV90cnVl",
-    "alertSeverity": "INFO",
+    "alertSeverity": "WARNING",
     "alerts": [
       {
-        "type": "INFO",
-        "message": "There are no IOCs deployed to host",
+        "type": "WARNING",
+        "message": "This is a warning message",
         "link": null
       }
     ]
   },
   {
-    "hostId": "MjE5M19mYWxzZQ",
+    "hostId": "NDcwNF90cnVl",
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -101,22 +95,22 @@
   },
   {
     "hostId": "NTU4MF90cnVl",
-    "alertSeverity": "INFO",
+    "alertSeverity": "ERROR",
     "alerts": [
       {
-        "type": "INFO",
-        "message": "There are no IOCs deployed to host",
+        "type": "ERROR",
+        "message": "There is an error message",
         "link": null
       }
     ]
   },
   {
     "hostId": "NDkwMF90cnVl",
-    "alertSeverity": "INFO",
+    "alertSeverity": "WARNING",
     "alerts": [
       {
-        "type": "INFO",
-        "message": "There are no IOCs deployed to host",
+        "type": "WARNING",
+        "message": "This is a warning message",
         "link": null
       }
     ]
diff --git a/src/mocks/fixtures/HostStatus.json b/src/mocks/fixtures/HostStatus.json
index a841f0fb..91e7955f 100644
--- a/src/mocks/fixtures/HostStatus.json
+++ b/src/mocks/fixtures/HostStatus.json
@@ -2,8 +2,7 @@
   {
     "hostId": "MjE5MV9mYWxzZQ",
     "assigned": true,
-    "status": "AVAILABLE",
-    "alerts": []
+    "status": "AVAILABLE"
   },
   {
     "hostId": "MjIwNV9mYWxzZQ",
@@ -11,22 +10,22 @@
     "status": "AVAILABLE"
   },
   {
-    "hostId": "MjE3Nl9mYWxzZQ",
+    "hostId": "MzcwNF9mYWxzZQ",
     "assigned": false,
     "status": "AVAILABLE"
   },
   {
-    "hostId": "MzcwNF9mYWxzZQ",
+    "hostId": "NDkzN190cnVl",
     "assigned": false,
     "status": "AVAILABLE"
   },
   {
-    "hostId": "MzcwM19mYWxzZQ",
+    "hostId": "MjE5M19mYWxzZQ",
     "assigned": false,
     "status": "AVAILABLE"
   },
   {
-    "hostId": "NDkzN190cnVl",
+    "hostId": "NTU4MF90cnVl",
     "assigned": true,
     "status": "UNREACHABLE"
   },
@@ -36,23 +35,13 @@
     "status": "UNREACHABLE"
   },
   {
-    "hostId": "NDk5MV90cnVl",
-    "assigned": true,
-    "status": "UNREACHABLE"
-  },
-  {
-    "hostId": "MjE5M19mYWxzZQ",
-    "assigned": true,
-    "status": "UNREACHABLE"
-  },
-  {
-    "hostId": "NTU4MF90cnVl",
+    "hostId": "NDcwNF90cnVl",
     "assigned": true,
     "status": "UNREACHABLE"
   },
   {
     "hostId": "NDkwMF90cnVl",
     "assigned": true,
-    "status": "AVAILABLE"
+    "status": "UNREACHABLE"
   }
 ]
diff --git a/src/mocks/fixtures/Hosts.json b/src/mocks/fixtures/Hosts.json
index 581dad81..bd0480f0 100644
--- a/src/mocks/fixtures/Hosts.json
+++ b/src/mocks/fixtures/Hosts.json
@@ -1,6 +1,6 @@
 {
-  "totalCount": 11,
-  "listSize": 11,
+  "totalCount": 10,
+  "listSize": 10,
   "pageNumber": 0,
   "limit": 100,
   "netBoxHosts": [
@@ -12,7 +12,7 @@
       "description": "MEBT RF SSPA (Buncher Amplifier) IOC ",
       "network": "ChannelAccess-ACC",
       "deviceType": "VirtualMachine",
-      "hostId": "MjE5MV9mYWxzZQ=",
+      "hostId": "MjE5MV9mYWxzZQ",
       "vm": true
     },
     {
@@ -23,7 +23,7 @@
       "description": "Virtual Machine that runs the IOC of the MEBT Chopper Local Protection PLC",
       "network": "ChannelAccess-FEB",
       "deviceType": "VirtualMachine",
-      "hostId": "MjIwNV9mYWxzZQ=",
+      "hostId": "MjIwNV9mYWxzZQ",
       "vm": true
     },
     {
@@ -37,17 +37,6 @@
       "hostId": "MzcwNF9mYWxzZQ",
       "vm": false
     },
-    {
-      "id": 3916,
-      "fqdn": "mebt-ifc1410-02.tn.esss.lu.se",
-      "name": "mebt-ifc1410-02",
-      "scope": "TechnicalNetwork",
-      "description": "MEBT RFLPS FIM system 02 - IFC1410",
-      "network": "ChannelAccess-ACC",
-      "deviceType": "MTCA-IFC",
-      "hostId": "MzcwM19mYWxzZQ",
-      "vm": false
-    },
     {
       "id": 3917,
       "fqdn": "mebt-ifc1410-03.tn.esss.lu.se",
diff --git a/src/stories/components/common/host/HostTable.stories.js b/src/stories/components/common/host/HostTable.stories.js
index 9c8b6a51..16c87d96 100644
--- a/src/stories/components/common/host/HostTable.stories.js
+++ b/src/stories/components/common/host/HostTable.stories.js
@@ -66,6 +66,9 @@ BeforeAsync.parameters = {
       rest.get("*/hosts/:host_id/status", (req, res, ctx) => {
         const { host_id } = req.params; // eslint-disable-line
         res(ctx.delay("infinite"));
+      }),
+      rest.get("*/hosts/:host_id/alerts", (req, res, ctx) => {
+        res(ctx.delay("infinite"));
       })
     ]
   }
diff --git a/src/stories/views/Host/HostDetailsView.stories.js b/src/stories/views/Host/HostDetailsView.stories.js
index 8df68075..6db057af 100644
--- a/src/stories/views/Host/HostDetailsView.stories.js
+++ b/src/stories/views/Host/HostDetailsView.stories.js
@@ -12,14 +12,36 @@ const Template = (args) => (
     {...args}
   >
     <HostDetailsContainer
-      hostId="MjIwNV9mYWxzZQ"
-      hostFqdn="a2t-lwu-vm-ioc-02.tn.esss.lu.se"
-      {...args}
+      hostId={args.hostId}
+      hostFqdn={args.hostFqdn}
     />
   </AppHarness>
 );
 
-export const Default = (args) => <Template {...args} />;
-Default.args = {
-  ...userImpersonatorArgs
+export const Active = (args) => <Template {...args} />;
+Active.args = {
+  ...userImpersonatorArgs,
+  hostId: "MjE5MV9mYWxzZQ",
+  hostFqdn: "mebt-vm-ioc01.tn.esss.lu.se"
+};
+
+export const InActive = (args) => <Template {...args} />;
+InActive.args = {
+  ...userImpersonatorArgs,
+  hostId: "MjEwOF9mYWxzZQ",
+  hostFqdn: "mebt-vm-ioc02.tn.esss.lu.se"
+};
+
+export const ActiveWithError = (args) => <Template {...args} />;
+ActiveWithError.args = {
+  ...userImpersonatorArgs,
+  hostId: "NDkzN190cnVl",
+  hostFqdn: "mebt-ifc1410-03.tn.esss.lu.se"
+};
+
+export const InActiveWithError = (args) => <Template {...args} />;
+InActiveWithError.args = {
+  ...userImpersonatorArgs,
+  hostId: "NTU4MF90cnVl",
+  hostFqdn: "mebt-llrf3-mtca-ioc.tn.esss.lu.se"
 };
-- 
GitLab