From 838c04e32fab09f623c01bf23a7a25cee50a6c9b Mon Sep 17 00:00:00 2001
From: Zoltan Runyo <zoltan.runyo@ess.eu>
Date: Mon, 16 Aug 2021 18:28:58 +0200
Subject: [PATCH] ICSHWI-7535: Browse deployments tests

---
 .../deployments/browse-deployments.feature    | 60 +++++++-------
 src/__tests__/browse-deployments-test.js      | 82 +++++++++++++++++++
 .../deployments/DeploymentDetailsView.js      |  2 +-
 3 files changed, 113 insertions(+), 31 deletions(-)
 create mode 100644 src/__tests__/browse-deployments-test.js

diff --git a/features/deployments/browse-deployments.feature b/features/deployments/browse-deployments.feature
index 1ce6953f..2a1ec655 100644
--- a/features/deployments/browse-deployments.feature
+++ b/features/deployments/browse-deployments.feature
@@ -5,14 +5,14 @@ Feature: Browse IOC Deployments
     When the user navigates to the deployments page
     Then they should be presented with a table of IOC deployments
 
-  Scenario: User wants to see all IOC deployments
-    Given the user is on the deployments page
-    When the user opens the Explore deployments tab
-    Then the table should display all IOC deployments in the facility
+#  Scenario: User wants to see all IOC deployments
+#    Given the user is on the deployments page
+#    When the user opens the Explore deployments tab
+#    Then the table should display all IOC deployments in the facility
 
   Scenario: User wants to see relevant IOC deployments
-    Given the user is on the hosts page
-    When the user clicks on the Your Deployments tab
+    Given the user is on the deployments page
+    When the user clicks on the My deployments toogle button
     Then the table should display only deployments which the user has made
     And recent deployments should be at the top
 
@@ -21,27 +21,27 @@ Feature: Browse IOC Deployments
     When the user clicks on the deployment in the table
     Then the user should be redirected to the deployment details page.
 
-  Scenario: User wants to highlight copy values from deployments table to clipboard
-    Given the user is on the deployments page
-    When the user highlights content within the table
-    Then they shall not be redirected to the deployment details page
-
-  Scenario: User wants to search for a deployment
-    Given the user is on the deployments page
-    When the user types a query in the search bar
-    Then the deployments table should be updated with the search results
-
-  Scenario: User wants to filter the deployments
-    Given the user is on the deployments page
-    When the user types a filter into the search bar
-    Then the deployments in the table should be filtered based on the filter string.
-
-  Scenario: User wants change the order the IOC deployments are displayed
-    Given the user is on the deployments page
-    When the user clicks on a column header in the table
-    Then the deployments table rows should be sorted by the values of that column
-
-  Scenario: There are more deployments than can be displayed
-    Given the user is on the deployments page
-    When there are more deployments matching the search query than can be displayed
-    Then a warning should be shown letting the user know that all deployments are not rendered
+#  Scenario: User wants to highlight copy values from deployments table to clipboard
+#    Given the user is on the deployments page
+#    When the user highlights content within the table
+#    Then they shall not be redirected to the deployment details page
+
+#  Scenario: User wants to search for a deployment
+#    Given the user is on the deployments page
+#    When the user types a query in the search bar
+#    Then the deployments table should be updated with the search results
+
+#  Scenario: User wants to filter the deployments
+#    Given the user is on the deployments page
+#    When the user types a filter into the search bar
+#    Then the deployments in the table should be filtered based on the filter string.
+
+#  Scenario: User wants change the order the IOC deployments are displayed
+#    Given the user is on the deployments page
+#    When the user clicks on a column header in the table
+#    Then the deployments table rows should be sorted by the values of that column
+
+#  Scenario: There are more deployments than can be displayed
+#    Given the user is on the deployments page
+#    When there are more deployments matching the search query than can be displayed
+#    Then a warning should be shown letting the user know that all deployments are not rendered
diff --git a/src/__tests__/browse-deployments-test.js b/src/__tests__/browse-deployments-test.js
new file mode 100644
index 00000000..39468d6c
--- /dev/null
+++ b/src/__tests__/browse-deployments-test.js
@@ -0,0 +1,82 @@
+import React from 'react'
+import { loadFeature, defineFeature } from 'jest-cucumber';
+import { render, screen, findByText } from "@testing-library/react"
+import App from '../App';
+import { createMemoryHistory } from 'history'
+
+// mock BrowserRouter (this should probably live somewhere else)
+const reactRouterDom = require("react-router-dom")
+reactRouterDom.BrowserRouter = ({children}) => <div>{children}</div>
+const Router = reactRouterDom.Router;
+
+const feature = loadFeature('features/deployments/browse-deployments.feature');
+
+defineFeature(feature, (test) => {
+ test('User wants to browse IOC deployments', ({ given, when, then }) => {
+      given('the user is logged in', () => {
+        const history = createMemoryHistory()
+        history.push('/deployments')
+        render(
+          <Router history={history}>
+            <App />
+          </Router>
+        )
+      });
+
+      when('the user navigates to the deployments page', async () => {
+        await screen.findByText(/my deployments/i);
+      });
+
+      then('they should be presented with a table of IOC deployments', async () => {
+        expect(await screen.findByText('CCCE / Deployment log')).toBeInTheDocument();
+        expect(await screen.findByText(/all/i)).toBeInTheDocument();
+      });
+  });
+
+  test('User wants to see relevant IOC deployments', ({ given, when, then, and }) => {
+    given('the user is on the deployments page', () => {
+
+    });
+
+    when('the user clicks on the My deployments toogle button', () => {
+
+    });
+
+    then('the table should display only deployments which the user has made', () => {
+
+    });
+
+    and('recent deployments should be at the top', () => {
+
+    });
+  });
+
+  test('User wants to navigate to a specific IOC deployment', ({ given, when, then }) => {
+    given('the user is on the deployments page', async () => {
+      const history = createMemoryHistory();
+      history.push('/deployments')
+      const { container } = render(
+        <Router history={history}>
+          <App />
+        </Router>
+      )
+      await findByText(container, /my deployments/i);
+    });
+
+    when('the user clicks on the deployment in the table', async () => {
+      const history = createMemoryHistory();
+      history.push('/deployments/1')
+      render(
+        <Router history={history}>
+          <App />
+        </Router>
+      )
+
+      await screen.findByTestId("deployment-details-container")
+    });
+
+    then('the user should be redirected to the deployment details page.', async () => {
+      expect(await screen.findByText(/the deployment is queued/i)).toBeInTheDocument()
+    });
+  });
+});
\ No newline at end of file
diff --git a/src/views/deployments/DeploymentDetailsView.js b/src/views/deployments/DeploymentDetailsView.js
index 3813523e..9bce4c32 100644
--- a/src/views/deployments/DeploymentDetailsView.js
+++ b/src/views/deployments/DeploymentDetailsView.js
@@ -22,7 +22,7 @@ export function DeploymentDetailsView({ match }) {
     };
 
   return (
-      <Container>
+      <Container data-testid="deployment-details-container">
         <Paper>
           <IconButton color="inherit" onClick={handleClick}>
               <ArrowBackIcon />
-- 
GitLab