Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Do not get template if not in edit mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaacov Zamir authored and yaacov committed Mar 25, 2019
1 parent 6937cc0 commit 71bde61
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/Details/Flavor/Flavor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
5 changes: 5 additions & 0 deletions src/components/Details/Flavor/tests/Flavor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import { Flavor } from '..';
import { default as FlavorFixture } from '../fixtures/Flavor.fixture';

const testFlavor = () => <Flavor {...FlavorFixture[0].props} id="myflavor" />;
const testFlavorEdit = () => <Flavor {...FlavorFixture[1].props} id="myflavor" />;

describe('<Flavor />', () => {
it('renders correctly', () => {
const component = shallow(testFlavor());
expect(component).toMatchSnapshot();
});
it('renders correctly in edit mode', () => {
const component = shallow(testFlavorEdit());
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,61 @@ exports[`<Flavor /> renders correctly 1`] = `
</div>
</InlineEdit>
`;

exports[`<Flavor /> renders correctly in edit mode 1`] = `
<InlineEdit
LoadingComponent={[Function]}
editing={true}
fieldsValues={
Object {
"cpu": Object {
"value": "2",
},
"flavor": Object {
"value": "Custom",
},
"memory": Object {
"value": "2",
},
}
}
formFields={
Object {
"cpu": Object {
"id": "myflavor-flavor-cpu",
"isVisible": [Function],
"required": true,
"title": "CPU",
"type": "positive-number",
},
"flavor": Object {
"choices": Array [
"Custom",
],
"id": "myflavor-flavor-dropdown",
"type": "dropdown",
},
"memory": Object {
"id": "myflavor-flavor-memory",
"isVisible": [Function],
"required": true,
"title": "Memory (GB)",
"type": "positive-number",
},
}
}
onFormChange={[Function]}
updating={true}
>
<div
id="myflavor-flavor"
>
small
</div>
<div
id="myflavor-flavor-description"
>
2 CPU, 2G Memory
</div>
</InlineEdit>
`;
39 changes: 39 additions & 0 deletions src/components/Details/VmDetails/fixtures/VmDetails.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -204,4 +233,14 @@ export default [
overview: true,
},
},
{
component: VmDetails,
name: 'VM detail with deleted template',
props: {
vm: vmFixtures.vmWithDeletedTemplate,
k8sPatch,
k8sGet,
NodeLink: () => true,
},
},
];
5 changes: 5 additions & 0 deletions src/components/Details/VmDetails/tests/VmDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ describe('<VmDetails />', () => {
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('<VmDetails /> enzyme', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,183 @@ Array [
]
`;

exports[`<VmDetails /> enzyme renders deleted template correctly 1`] = `
Array [
<h1
class="co-m-pane__heading"
>
Virtual Machine Overview
<div>
<button
class="btn btn-default"
type="button"
>
Edit
</button>
</div>
</h1>,
<div
class="kubevirt-vm-details__content"
>
<dl
class="kubevirt-vm-details__name-list"
>
<dt
class=""
>
Name
</dt>
<dd
class=""
id="my-namespace-my-vm-name"
>
my-vm
</dd>
<dt
class=""
>
Description
</dt>
<dd>
<div
class="kubevirt-vm-details__description"
>
<div
id="my-namespace-my-vm-description"
>
---
</div>
</div>
</dd>
</dl>
<div
class="kubevirt-vm-details__details"
>
<dl
class="kubevirt-vm-details__details-list"
>
<dt>
Status
</dt>
<dd>
<div>
<span
aria-hidden="true"
class="kubevirt-vm-status__icon pficon pficon-off"
/>
Off
</div>
</dd>
<dt>
Operating System
</dt>
<dd
id="my-namespace-my-vm-os"
>
fedora29
</dd>
<dt>
IP Addresses
</dt>
<dd
id="my-namespace-my-vm-ip-addresses"
>
---
</dd>
<dt>
Workload Profile
</dt>
<dd
id="my-namespace-my-vm-workload-profile"
>
generic
</dd>
<dt>
Template
</dt>
<dd
id="my-namespace-my-vm-template"
>
default/deleted-template
</dd>
</dl>
<div
class="kubevirt-vm-details__other-details"
>
<dl
class="kubevirt-vm-details__details-list"
>
<dt>
FQDN
</dt>
<dd
id="my-namespace-my-vm-fqdn"
>
---
</dd>
<dt>
Namespace
</dt>
<dd
id="my-namespace-my-vm-namespace"
>
---
</dd>
<dt>
Pod
</dt>
<dd
id="my-namespace-my-vm-pod"
>
---
</dd>
<dd>
---
</dd>
<dt>
Boot Order
</dt>
<dd
id="my-namespace-my-vm-boot-order"
>
---
</dd>
</dl>
<dl
class="kubevirt-vm-details__details-list"
>
<dt>
Node
</dt>
<dd
id="my-namespace-my-vm-node"
>
---
</dd>
<dt>
Flavor
</dt>
<dd>
<div>
<div
id="my-namespace-my-vm-flavor"
>
small
</div>
<div
id="my-namespace-my-vm-flavor-description"
>
2 CPU, 2G Memory
</div>
</div>
</dd>
</dl>
</div>
</div>
</div>,
]
`;

exports[`<VmDetails /> renders CPU and Memory settings for VM with custom flavor 1`] = `
Array [
<h1
Expand Down

0 comments on commit 71bde61

Please sign in to comment.