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 7de0d06
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 1 deletion.
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>
`;
4 changes: 3 additions & 1 deletion src/components/Details/VmDetails/VmDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class VmDetails extends React.Component {
constructor(props) {
super(props);
this.state = {
editing: false,
editing: !!props.editing,
updating: false,
k8sError: null,
form: {},
Expand Down Expand Up @@ -298,6 +298,7 @@ VmDetails.propTypes = {
k8sGet: PropTypes.func.isRequired,
LoadingComponent: PropTypes.func,
overview: PropTypes.bool,
editing: PropTypes.bool,
};

VmDetails.defaultProps = {
Expand All @@ -310,4 +311,5 @@ VmDetails.defaultProps = {
LoadingComponent: Loading,
NodeLink: undefined,
overview: false,
editing: false,
};
69 changes: 69 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,65 @@ export const vmFixtures = {
running: false,
},
},
vmWithLabelsEditMode: {
metadata: {
...metadata,
labels: {
'flavor.template.cnv.io/small': 'true',
'os.template.cnv.io/fedora29': 'true',
[LABEL_USED_TEMPLATE_NAME]: 'fedora-generic',
[LABEL_USED_TEMPLATE_NAMESPACE]: 'default',
'workload.template.cnv.io/generic': 'true',
},
},
spec: {
template: {
spec: {
domain: {
cpu: {
cores: 2,
},
resources: {
requests: {
memory: '2G',
},
},
},
},
},
running: false,
},
editing: true,
},
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 +263,14 @@ export default [
overview: true,
},
},
{
component: VmDetails,
name: 'VM detail with deleted template',
props: {
vm: vmFixtures.vmWithDeletedTemplate,
k8sPatch,
k8sGet,
NodeLink: () => true,
},
},
];
10 changes: 10 additions & 0 deletions src/components/Details/VmDetails/tests/VmDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ describe('<VmDetails />', () => {
expect(component).toMatchSnapshot();
});

it('renders values from labels correctly in edit mode', () => {
const component = render(testVmDetails(vmFixtures.vmWithLabelsEditMode));
expect(component).toMatchSnapshot();
});

it('renders CPU and Memory settings for VM with custom flavor', () => {
const component = render(testVmDetails(vmFixtures.customVm));
expect(component).toMatchSnapshot();
Expand All @@ -60,6 +65,11 @@ describe('<VmDetails />', () => {
const component = render(testVmDetails(vmFixtures.runningVm, { overview: true }));
expect(component).toMatchSnapshot();
});

it('renders deleted template correctly', () => {
const component = render(testVmDetails(vmFixtures.vmWithDeletedTemplate));
expect(component).toMatchSnapshot();
});
});

describe('<VmDetails /> enzyme', () => {
Expand Down
Loading

0 comments on commit 7de0d06

Please sign in to comment.