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

Commit 7de0d06

Browse files
Yaacov Zamiryaacov
authored andcommitted
Do not get template if not in edit mode.
1 parent 6937cc0 commit 7de0d06

File tree

7 files changed

+509
-1
lines changed

7 files changed

+509
-1
lines changed

src/components/Details/Flavor/Flavor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ export class Flavor extends React.Component {
3232
};
3333

3434
componentDidMount() {
35+
// If not in edit mode, just init state and exit.
36+
if (!this.props.editing) {
37+
this.setState({
38+
loadingTemplate: false,
39+
template: null,
40+
});
41+
42+
return;
43+
}
44+
3545
this.setState({
3646
loadingTemplate: true,
3747
});

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class VmDetails extends React.Component {
4141
constructor(props) {
4242
super(props);
4343
this.state = {
44-
editing: false,
44+
editing: !!props.editing,
4545
updating: false,
4646
k8sError: null,
4747
form: {},
@@ -298,6 +298,7 @@ VmDetails.propTypes = {
298298
k8sGet: PropTypes.func.isRequired,
299299
LoadingComponent: PropTypes.func,
300300
overview: PropTypes.bool,
301+
editing: PropTypes.bool,
301302
};
302303

303304
VmDetails.defaultProps = {
@@ -310,4 +311,5 @@ VmDetails.defaultProps = {
310311
LoadingComponent: Loading,
311312
NodeLink: undefined,
312313
overview: false,
314+
editing: false,
313315
};

src/components/Details/VmDetails/fixtures/VmDetails.fixture.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,65 @@ export const vmFixtures = {
8787
running: false,
8888
},
8989
},
90+
vmWithLabelsEditMode: {
91+
metadata: {
92+
...metadata,
93+
labels: {
94+
'flavor.template.cnv.io/small': 'true',
95+
'os.template.cnv.io/fedora29': 'true',
96+
[LABEL_USED_TEMPLATE_NAME]: 'fedora-generic',
97+
[LABEL_USED_TEMPLATE_NAMESPACE]: 'default',
98+
'workload.template.cnv.io/generic': 'true',
99+
},
100+
},
101+
spec: {
102+
template: {
103+
spec: {
104+
domain: {
105+
cpu: {
106+
cores: 2,
107+
},
108+
resources: {
109+
requests: {
110+
memory: '2G',
111+
},
112+
},
113+
},
114+
},
115+
},
116+
running: false,
117+
},
118+
editing: true,
119+
},
120+
vmWithDeletedTemplate: {
121+
metadata: {
122+
...metadata,
123+
labels: {
124+
'flavor.template.cnv.io/small': 'true',
125+
'os.template.cnv.io/fedora29': 'true',
126+
[LABEL_USED_TEMPLATE_NAME]: 'deleted-template',
127+
[LABEL_USED_TEMPLATE_NAMESPACE]: 'default',
128+
'workload.template.cnv.io/generic': 'true',
129+
},
130+
},
131+
spec: {
132+
template: {
133+
spec: {
134+
domain: {
135+
cpu: {
136+
cores: 2,
137+
},
138+
resources: {
139+
requests: {
140+
memory: '2G',
141+
},
142+
},
143+
},
144+
},
145+
},
146+
running: false,
147+
},
148+
},
90149
customVm: {
91150
metadata: {
92151
...metadata,
@@ -204,4 +263,14 @@ export default [
204263
overview: true,
205264
},
206265
},
266+
{
267+
component: VmDetails,
268+
name: 'VM detail with deleted template',
269+
props: {
270+
vm: vmFixtures.vmWithDeletedTemplate,
271+
k8sPatch,
272+
k8sGet,
273+
NodeLink: () => true,
274+
},
275+
},
207276
];

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ describe('<VmDetails />', () => {
4141
expect(component).toMatchSnapshot();
4242
});
4343

44+
it('renders values from labels correctly in edit mode', () => {
45+
const component = render(testVmDetails(vmFixtures.vmWithLabelsEditMode));
46+
expect(component).toMatchSnapshot();
47+
});
48+
4449
it('renders CPU and Memory settings for VM with custom flavor', () => {
4550
const component = render(testVmDetails(vmFixtures.customVm));
4651
expect(component).toMatchSnapshot();
@@ -60,6 +65,11 @@ describe('<VmDetails />', () => {
6065
const component = render(testVmDetails(vmFixtures.runningVm, { overview: true }));
6166
expect(component).toMatchSnapshot();
6267
});
68+
69+
it('renders deleted template correctly', () => {
70+
const component = render(testVmDetails(vmFixtures.vmWithDeletedTemplate));
71+
expect(component).toMatchSnapshot();
72+
});
6373
});
6474

6575
describe('<VmDetails /> enzyme', () => {

0 commit comments

Comments
 (0)