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

Commit 88af55e

Browse files
Yaacov Zamiryaacov
authored andcommitted
Do not get template if not in edit mode.
1 parent 865ecf0 commit 88af55e

File tree

6 files changed

+72
-36
lines changed

6 files changed

+72
-36
lines changed

src/components/Details/Flavor/tests/Flavor.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import { Flavor } from '..';
66
import { default as FlavorFixture } from '../fixtures/Flavor.fixture';
77

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

1011
describe('<Flavor />', () => {
1112
it('renders correctly', () => {
1213
const component = shallow(testFlavor());
1314
expect(component).toMatchSnapshot();
1415
});
16+
it('renders correctly in edit mode', () => {
17+
const component = shallow(testFlavorEdit());
18+
expect(component).toMatchSnapshot();
19+
});
1520
});

src/components/Details/Flavor/tests/__snapshots__/Flavor.test.js.snap

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,61 @@ exports[`<Flavor /> renders correctly 1`] = `
4545
</div>
4646
</InlineEdit>
4747
`;
48+
49+
exports[`<Flavor /> renders correctly in edit mode 1`] = `
50+
<InlineEdit
51+
LoadingComponent={[Function]}
52+
editing={true}
53+
fieldsValues={
54+
Object {
55+
"cpu": Object {
56+
"value": "2",
57+
},
58+
"flavor": Object {
59+
"value": "Custom",
60+
},
61+
"memory": Object {
62+
"value": "2",
63+
},
64+
}
65+
}
66+
formFields={
67+
Object {
68+
"cpu": Object {
69+
"id": "myflavor-flavor-cpu",
70+
"isVisible": [Function],
71+
"required": true,
72+
"title": "CPU",
73+
"type": "positive-number",
74+
},
75+
"flavor": Object {
76+
"choices": Array [
77+
"Custom",
78+
],
79+
"id": "myflavor-flavor-dropdown",
80+
"type": "dropdown",
81+
},
82+
"memory": Object {
83+
"id": "myflavor-flavor-memory",
84+
"isVisible": [Function],
85+
"required": true,
86+
"title": "Memory (GB)",
87+
"type": "positive-number",
88+
},
89+
}
90+
}
91+
onFormChange={[Function]}
92+
updating={true}
93+
>
94+
<div
95+
id="myflavor-flavor"
96+
>
97+
small
98+
</div>
99+
<div
100+
id="myflavor-flavor-description"
101+
>
102+
2 CPU, 2G Memory
103+
</div>
104+
</InlineEdit>
105+
`;

src/components/Details/VmDetails/VmDetails.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
prefixedId,
2929
} from '../../../utils';
3030
import { VirtualMachineModel } from '../../../models';
31-
import { CUSTOM_FLAVOR, DASHES, MISSING_STR, PENDING_STR } from '../../../constants';
31+
import { CUSTOM_FLAVOR, DASHES } from '../../../constants';
3232
import { settingsValue, selectVm } from '../../../k8s/selectors';
3333
import { Flavor } from '../Flavor';
3434
import { Description } from '../Description';
@@ -45,7 +45,6 @@ export class VmDetails extends React.Component {
4545
updating: false,
4646
k8sError: null,
4747
form: {},
48-
templateError: PENDING_STR,
4948
};
5049
}
5150

@@ -54,11 +53,6 @@ export class VmDetails extends React.Component {
5453
editing,
5554
});
5655

57-
setTemplateError = error =>
58-
this.setState({
59-
templateError: error,
60-
});
61-
6256
onFormChange = (formKey, newValue, key, valid) =>
6357
this.setState(state => ({
6458
form: {
@@ -129,17 +123,10 @@ export class VmDetails extends React.Component {
129123
isFormValid = () => Object.keys(this.state.form).every(key => this.state.form[key].valid);
130124

131125
componentDidUpdate() {
132-
const { launcherPod, importerPods, migration, k8sGet, vm } = this.props;
126+
const { launcherPod, importerPods, migration, vm } = this.props;
133127
if (this.state.editing && !this.isVmOff(vm, launcherPod, importerPods, migration)) {
134128
this.setEditing(false);
135129
}
136-
137-
// Check template, if template is missing, update view.
138-
if (getVmTemplate(vm) != null && this.state.templateError === PENDING_STR) {
139-
retrieveVmTemplate(k8sGet, vm)
140-
.then(() => this.setTemplateError(''))
141-
.catch(() => this.setTemplateError(MISSING_STR));
142-
}
143130
}
144131

145132
isVmOff = (vm, launcherPod, importerPods, migration) => {
@@ -168,8 +155,6 @@ export class VmDetails extends React.Component {
168155
const hostName = getHostName(launcherPod);
169156
const fqdn = vmIsOff || !hostName ? DASHES : hostName;
170157
const template = getVmTemplate(vm);
171-
const templateIsMissing = this.state.templateError === MISSING_STR ? ` ${MISSING_STR}` : '';
172-
const templateLabel = template ? `${template.namespace}/${template.name}${templateIsMissing}` : DASHES;
173158
const id = getId(vm);
174159
const sortedBootableDevices = getBootableDevicesInOrder(vm);
175160
const editButton = (
@@ -253,7 +238,7 @@ export class VmDetails extends React.Component {
253238
<dd id={prefixedId(id, 'workload-profile')}>{getWorkloadProfile(vm) || DASHES}</dd>
254239

255240
<dt>Template</dt>
256-
<dd id={prefixedId(id, 'template')}>{templateLabel}</dd>
241+
<dd id={prefixedId(id, 'template')}>{template ? `${template.namespace}/${template.name}` : DASHES}</dd>
257242
</dl>
258243
<div className="kubevirt-vm-details__other-details">
259244
<dl className="kubevirt-vm-details__details-list">

src/components/Details/VmDetails/tests/VmDetails.test.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import { getId } from '../../../../selectors';
1515

1616
const testVmDetails = (vm, otherProps) => <VmDetails {...VmDetailsFixture[0].props} vm={vm} {...otherProps} />;
1717

18-
const flushAllPromises = () => new Promise(resolve => setImmediate(resolve));
19-
2018
describe('<VmDetails />', () => {
2119
it('renders correctly', () => {
2220
const component = render(testVmDetails(vmFixtures.downVm));
@@ -62,6 +60,11 @@ describe('<VmDetails />', () => {
6260
const component = render(testVmDetails(vmFixtures.runningVm, { overview: true }));
6361
expect(component).toMatchSnapshot();
6462
});
63+
64+
it('renders deleted template correctly', async () => {
65+
const component = render(testVmDetails(vmFixtures.vmWithDeletedTemplate));
66+
expect(component).toMatchSnapshot();
67+
});
6568
});
6669

6770
describe('<VmDetails /> enzyme', () => {
@@ -75,19 +78,6 @@ describe('<VmDetails /> enzyme', () => {
7578
return disablesEditOnCancel(component);
7679
});
7780

78-
it('renders deleted template correctly', async () => {
79-
const component = mount(testVmDetails(vmFixtures.vmWithDeletedTemplate));
80-
81-
// Wait for all promisses to terminate.
82-
//
83-
// Testing for deleted template is done using a promise
84-
// we need to wait for.
85-
await flushAllPromises();
86-
component.update();
87-
88-
expect(component.render()).toMatchSnapshot();
89-
});
90-
9181
it('updates VM description after clicking save button', () => {
9282
const k8sPatchMock = jest.fn().mockReturnValue(
9383
new Promise(resolve => {

src/components/Details/VmDetails/tests/__snapshots__/VmDetails.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Array [
272272
<dd
273273
id="my-namespace-my-vm-template"
274274
>
275-
default/deleted-template (Missing)
275+
default/deleted-template
276276
</dd>
277277
</dl>
278278
<div

src/constants/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ export const OS_WINDOWS_PREFIX = 'win';
6060

6161
export const DEFAULT_RDP_PORT = 3389;
6262
export const DASHES = '---';
63-
export const MISSING_STR = '(Missing)';
64-
export const PENDING_STR = '(Pending)';
6563

6664
export const CDI_KUBEVIRT_IO = 'cdi.kubevirt.io';
6765
export const STORAGE_IMPORT_PVC_NAME = 'storage.import.importPvcName';

0 commit comments

Comments
 (0)