From 71bde614defd9b37b9d1d56b5cc79e2c63becc8a Mon Sep 17 00:00:00 2001 From: Yaacov Zamir Date: Sun, 24 Mar 2019 18:48:27 +0200 Subject: [PATCH] Do not get template if not in edit mode. --- src/components/Details/Flavor/Flavor.js | 10 + .../Details/Flavor/tests/Flavor.test.js | 5 + .../tests/__snapshots__/Flavor.test.js.snap | 58 ++++++ .../VmDetails/fixtures/VmDetails.fixture.js | 39 ++++ .../Details/VmDetails/tests/VmDetails.test.js | 5 + .../__snapshots__/VmDetails.test.js.snap | 177 ++++++++++++++++++ 6 files changed, 294 insertions(+) diff --git a/src/components/Details/Flavor/Flavor.js b/src/components/Details/Flavor/Flavor.js index 9ac681622..685405863 100644 --- a/src/components/Details/Flavor/Flavor.js +++ b/src/components/Details/Flavor/Flavor.js @@ -32,6 +32,16 @@ export class Flavor extends React.Component { }; componentDidMount() { + // If not in edit mode, just init state and exit. + if (!this.props.editing) { + this.setState({ + loadingTemplate: false, + template: null, + }); + + return; + } + this.setState({ loadingTemplate: true, }); diff --git a/src/components/Details/Flavor/tests/Flavor.test.js b/src/components/Details/Flavor/tests/Flavor.test.js index 508364eb6..526e0e5d6 100644 --- a/src/components/Details/Flavor/tests/Flavor.test.js +++ b/src/components/Details/Flavor/tests/Flavor.test.js @@ -6,10 +6,15 @@ import { Flavor } from '..'; import { default as FlavorFixture } from '../fixtures/Flavor.fixture'; const testFlavor = () => ; +const testFlavorEdit = () => ; describe('', () => { it('renders correctly', () => { const component = shallow(testFlavor()); expect(component).toMatchSnapshot(); }); + it('renders correctly in edit mode', () => { + const component = shallow(testFlavorEdit()); + expect(component).toMatchSnapshot(); + }); }); diff --git a/src/components/Details/Flavor/tests/__snapshots__/Flavor.test.js.snap b/src/components/Details/Flavor/tests/__snapshots__/Flavor.test.js.snap index 1822379dd..a729270f7 100644 --- a/src/components/Details/Flavor/tests/__snapshots__/Flavor.test.js.snap +++ b/src/components/Details/Flavor/tests/__snapshots__/Flavor.test.js.snap @@ -45,3 +45,61 @@ exports[` renders correctly 1`] = ` `; + +exports[` renders correctly in edit mode 1`] = ` + +
+ small +
+
+ 2 CPU, 2G Memory +
+
+`; diff --git a/src/components/Details/VmDetails/fixtures/VmDetails.fixture.js b/src/components/Details/VmDetails/fixtures/VmDetails.fixture.js index f2d08a4d1..021fd8d04 100644 --- a/src/components/Details/VmDetails/fixtures/VmDetails.fixture.js +++ b/src/components/Details/VmDetails/fixtures/VmDetails.fixture.js @@ -87,6 +87,35 @@ export const vmFixtures = { running: false, }, }, + vmWithDeletedTemplate: { + metadata: { + ...metadata, + labels: { + 'flavor.template.cnv.io/small': 'true', + 'os.template.cnv.io/fedora29': 'true', + [LABEL_USED_TEMPLATE_NAME]: 'deleted-template', + [LABEL_USED_TEMPLATE_NAMESPACE]: 'default', + 'workload.template.cnv.io/generic': 'true', + }, + }, + spec: { + template: { + spec: { + domain: { + cpu: { + cores: 2, + }, + resources: { + requests: { + memory: '2G', + }, + }, + }, + }, + }, + running: false, + }, + }, customVm: { metadata: { ...metadata, @@ -204,4 +233,14 @@ export default [ overview: true, }, }, + { + component: VmDetails, + name: 'VM detail with deleted template', + props: { + vm: vmFixtures.vmWithDeletedTemplate, + k8sPatch, + k8sGet, + NodeLink: () => true, + }, + }, ]; diff --git a/src/components/Details/VmDetails/tests/VmDetails.test.js b/src/components/Details/VmDetails/tests/VmDetails.test.js index 20a4eedd8..4aa95a2e7 100644 --- a/src/components/Details/VmDetails/tests/VmDetails.test.js +++ b/src/components/Details/VmDetails/tests/VmDetails.test.js @@ -60,6 +60,11 @@ describe('', () => { const component = render(testVmDetails(vmFixtures.runningVm, { overview: true })); expect(component).toMatchSnapshot(); }); + + it('renders deleted template correctly', async () => { + const component = render(testVmDetails(vmFixtures.vmWithDeletedTemplate)); + expect(component).toMatchSnapshot(); + }); }); describe(' enzyme', () => { diff --git a/src/components/Details/VmDetails/tests/__snapshots__/VmDetails.test.js.snap b/src/components/Details/VmDetails/tests/__snapshots__/VmDetails.test.js.snap index 94144dc56..449dd336e 100644 --- a/src/components/Details/VmDetails/tests/__snapshots__/VmDetails.test.js.snap +++ b/src/components/Details/VmDetails/tests/__snapshots__/VmDetails.test.js.snap @@ -175,6 +175,183 @@ Array [ ] `; +exports[` enzyme renders deleted template correctly 1`] = ` +Array [ +

+ Virtual Machine Overview +
+ +
+

, +
+
+
+ Name +
+
+ my-vm +
+
+ Description +
+
+
+
+ --- +
+
+
+
+
+
+
+ Status +
+
+
+
+
+
+ Operating System +
+
+ fedora29 +
+
+ IP Addresses +
+
+ --- +
+
+ Workload Profile +
+
+ generic +
+
+ Template +
+
+ default/deleted-template +
+
+
+
+
+ FQDN +
+
+ --- +
+
+ Namespace +
+
+ --- +
+
+ Pod +
+
+ --- +
+
+ --- +
+
+ Boot Order +
+
+ --- +
+
+
+
+ Node +
+
+ --- +
+
+ Flavor +
+
+
+
+ small +
+
+ 2 CPU, 2G Memory +
+
+
+
+
+
+
, +] +`; + exports[` renders CPU and Memory settings for VM with custom flavor 1`] = ` Array [