This repository was archived by the owner on Apr 28, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +509
-1
lines changed Expand file tree Collapse file tree 7 files changed +509
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,16 @@ export class Flavor extends React.Component {
32
32
} ;
33
33
34
34
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
+
35
45
this . setState ( {
36
46
loadingTemplate : true ,
37
47
} ) ;
Original file line number Diff line number Diff line change @@ -6,10 +6,15 @@ import { Flavor } from '..';
6
6
import { default as FlavorFixture } from '../fixtures/Flavor.fixture' ;
7
7
8
8
const testFlavor = ( ) => < Flavor { ...FlavorFixture [ 0 ] . props } id = "myflavor" /> ;
9
+ const testFlavorEdit = ( ) => < Flavor { ...FlavorFixture [ 1 ] . props } id = "myflavor" /> ;
9
10
10
11
describe ( '<Flavor />' , ( ) => {
11
12
it ( 'renders correctly' , ( ) => {
12
13
const component = shallow ( testFlavor ( ) ) ;
13
14
expect ( component ) . toMatchSnapshot ( ) ;
14
15
} ) ;
16
+ it ( 'renders correctly in edit mode' , ( ) => {
17
+ const component = shallow ( testFlavorEdit ( ) ) ;
18
+ expect ( component ) . toMatchSnapshot ( ) ;
19
+ } ) ;
15
20
} ) ;
Original file line number Diff line number Diff line change @@ -45,3 +45,61 @@ exports[`<Flavor /> renders correctly 1`] = `
45
45
</div >
46
46
</InlineEdit >
47
47
` ;
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
+ ` ;
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export class VmDetails extends React.Component {
41
41
constructor ( props ) {
42
42
super ( props ) ;
43
43
this . state = {
44
- editing : false ,
44
+ editing : ! ! props . editing ,
45
45
updating : false ,
46
46
k8sError : null ,
47
47
form : { } ,
@@ -298,6 +298,7 @@ VmDetails.propTypes = {
298
298
k8sGet : PropTypes . func . isRequired ,
299
299
LoadingComponent : PropTypes . func ,
300
300
overview : PropTypes . bool ,
301
+ editing : PropTypes . bool ,
301
302
} ;
302
303
303
304
VmDetails . defaultProps = {
@@ -310,4 +311,5 @@ VmDetails.defaultProps = {
310
311
LoadingComponent : Loading ,
311
312
NodeLink : undefined ,
312
313
overview : false ,
314
+ editing : false ,
313
315
} ;
Original file line number Diff line number Diff line change @@ -87,6 +87,65 @@ export const vmFixtures = {
87
87
running : false ,
88
88
} ,
89
89
} ,
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
+ } ,
90
149
customVm : {
91
150
metadata : {
92
151
...metadata ,
@@ -204,4 +263,14 @@ export default [
204
263
overview : true ,
205
264
} ,
206
265
} ,
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
+ } ,
207
276
] ;
Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ describe('<VmDetails />', () => {
41
41
expect ( component ) . toMatchSnapshot ( ) ;
42
42
} ) ;
43
43
44
+ it ( 'renders values from labels correctly in edit mode' , ( ) => {
45
+ const component = render ( testVmDetails ( vmFixtures . vmWithLabelsEditMode ) ) ;
46
+ expect ( component ) . toMatchSnapshot ( ) ;
47
+ } ) ;
48
+
44
49
it ( 'renders CPU and Memory settings for VM with custom flavor' , ( ) => {
45
50
const component = render ( testVmDetails ( vmFixtures . customVm ) ) ;
46
51
expect ( component ) . toMatchSnapshot ( ) ;
@@ -60,6 +65,11 @@ describe('<VmDetails />', () => {
60
65
const component = render ( testVmDetails ( vmFixtures . runningVm , { overview : true } ) ) ;
61
66
expect ( component ) . toMatchSnapshot ( ) ;
62
67
} ) ;
68
+
69
+ it ( 'renders deleted template correctly' , ( ) => {
70
+ const component = render ( testVmDetails ( vmFixtures . vmWithDeletedTemplate ) ) ;
71
+ expect ( component ) . toMatchSnapshot ( ) ;
72
+ } ) ;
63
73
} ) ;
64
74
65
75
describe ( '<VmDetails /> enzyme' , ( ) => {
You can’t perform that action at this time.
0 commit comments