From 6bdf80302865e779254c511afbadb54b02fdfb05 Mon Sep 17 00:00:00 2001
From: Karishma Chadha <kchadha@media.mit.edu>
Date: Mon, 3 Dec 2018 15:00:37 -0500
Subject: [PATCH] Add unit test for new hasCloudPermission prop. Update
 existing tests.

---
 test/unit/util/cloud-manager-hoc.test.jsx | 32 +++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/test/unit/util/cloud-manager-hoc.test.jsx b/test/unit/util/cloud-manager-hoc.test.jsx
index 84e4687cc..977b5045f 100644
--- a/test/unit/util/cloud-manager-hoc.test.jsx
+++ b/test/unit/util/cloud-manager-hoc.test.jsx
@@ -59,6 +59,7 @@ describe('CloudManagerHOC', () => {
         mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -76,6 +77,7 @@ describe('CloudManagerHOC', () => {
         mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 store={store}
                 username="user"
                 vm={vm}
@@ -93,6 +95,7 @@ describe('CloudManagerHOC', () => {
         mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 vm={vm}
@@ -109,6 +112,7 @@ describe('CloudManagerHOC', () => {
         mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={stillLoadingStore}
                 username="user"
@@ -119,12 +123,31 @@ describe('CloudManagerHOC', () => {
         expect(CloudProvider).not.toHaveBeenCalled();
     });
 
+    test('when hasCloudPermission is false, the cloud provider is not set on the vm', () => {
+        const Component = () => <div />;
+        const WrappedComponent = cloudManagerHOC(Component);
+        mount(
+            <WrappedComponent
+                canSave
+                cloudHost="nonEmpty"
+                hasCloudPermission={false}
+                store={store}
+                username="user"
+                vm={vm}
+            />
+        );
+
+        expect(vm.setCloudProvider.mock.calls.length).toBe(0);
+        expect(CloudProvider).not.toHaveBeenCalled();
+    });
+
     test('if the isShowingWithId prop becomes true, it sets the cloud provider on the vm', () => {
         const Component = () => <div />;
         const WrappedComponent = cloudManagerHOC(Component);
         const mounted = mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={stillLoadingStore}
                 username="user"
@@ -146,6 +169,7 @@ describe('CloudManagerHOC', () => {
         const mounted = mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={stillLoadingStore}
                 username="user"
@@ -172,6 +196,7 @@ describe('CloudManagerHOC', () => {
         const mounted = mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -197,6 +222,7 @@ describe('CloudManagerHOC', () => {
         const mounted = mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -223,6 +249,7 @@ describe('CloudManagerHOC', () => {
         const mounted = mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -253,6 +280,7 @@ describe('CloudManagerHOC', () => {
         mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -273,6 +301,7 @@ describe('CloudManagerHOC', () => {
         mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -297,6 +326,7 @@ describe('CloudManagerHOC', () => {
         mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -322,6 +352,7 @@ describe('CloudManagerHOC', () => {
         const mounted = mount(
             <WrappedComponent
                 canSave
+                hasCloudPermission
                 cloudHost="nonEmpty"
                 store={store}
                 username="user"
@@ -347,6 +378,7 @@ describe('CloudManagerHOC', () => {
         const WrappedComponent = cloudManagerHOC(Component);
         const mounted = mount(
             <WrappedComponent
+                hasCloudPermission
                 canSave={false}
                 cloudHost="nonEmpty"
                 store={store}
-- 
GitLab