Skip to content

Commit ec6787a

Browse files
committed
Fix CloudObjectStoreContainerForm test
1 parent b5dc2f5 commit ec6787a

File tree

2 files changed

+60
-56
lines changed

2 files changed

+60
-56
lines changed

app/javascript/spec/cloud-object-store-container-form/__snapshots__/cloud-object-store-container-form.spec.js.snap

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ exports[`Cloud Object Store Container form component should add Amazon cloud obj
512512
</IsRequired>
513513
}
514514
loadOptions={[Function]}
515-
loadOptionsChangeCounter={1}
515+
loadOptionsChangeCounter={0}
516516
loadingMessage="Loading..."
517517
name="storage_manager_id"
518518
onBlur={[Function]}
@@ -523,11 +523,13 @@ exports[`Cloud Object Store Container form component should add Amazon cloud obj
523523
value=""
524524
>
525525
<ClearedSelect
526+
className=""
527+
closeMenuOnSelect={true}
528+
hideSelectedOptions={false}
526529
id="storage_manager_id"
527530
invalidText=""
528531
isClearable={false}
529-
isDisabled={true}
530-
isFetching={true}
532+
isFetching={false}
531533
isSearchable={false}
532534
labelText={
533535
<IsRequired>
@@ -546,6 +548,7 @@ exports[`Cloud Object Store Container form component should add Amazon cloud obj
546548
value=""
547549
>
548550
<Select
551+
className=""
549552
disabled={false}
550553
helperText=""
551554
id="storage_manager_id"
@@ -598,6 +601,7 @@ exports[`Cloud Object Store Container form component should add Amazon cloud obj
598601
onChange={[Function]}
599602
onFocus={[Function]}
600603
value=""
604+
<<<<<<< HEAD
601605
>
602606
<SelectItem
603607
disabled={false}
@@ -615,6 +619,9 @@ exports[`Cloud Object Store Container form component should add Amazon cloud obj
615619
</option>
616620
</SelectItem>
617621
</select>
622+
=======
623+
/>
624+
>>>>>>> f199ae1db1 (Fix CloudObjectStoreContainerForm test)
618625
<ForwardRef(ChevronDown16)
619626
className="bx--select__arrow"
620627
>
@@ -736,9 +743,7 @@ exports[`Cloud Object Store Container form component should add Amazon cloud obj
736743
"dirtyFieldsSinceLastSubmit": Object {},
737744
"dirtySinceLastSubmit": false,
738745
"error": undefined,
739-
"errors": Object {
740-
"storage_manager_id": "Required",
741-
},
746+
"errors": Object {},
742747
"form": Object {
743748
"batch": [Function],
744749
"blur": [Function],
@@ -774,28 +779,22 @@ exports[`Cloud Object Store Container form component should add Amazon cloud obj
774779
"subscribe": [Function],
775780
},
776781
"hasSubmitErrors": false,
777-
"hasValidationErrors": true,
782+
"hasValidationErrors": false,
778783
"initialValues": Object {},
779-
"invalid": true,
780-
"modified": Object {
781-
"storage_manager_id": false,
782-
},
784+
"invalid": false,
785+
"modified": Object {},
783786
"modifiedSinceLastSubmit": false,
784787
"pristine": true,
785788
"submitError": undefined,
786789
"submitErrors": undefined,
787790
"submitFailed": false,
788791
"submitSucceeded": false,
789792
"submitting": false,
790-
"touched": Object {
791-
"storage_manager_id": false,
792-
},
793-
"valid": false,
793+
"touched": Object {},
794+
"valid": true,
794795
"validating": false,
795796
"values": Object {},
796-
"visited": Object {
797-
"storage_manager_id": false,
798-
},
797+
"visited": Object {},
799798
}
800799
}
801800
onCancel={[Function]}
@@ -1428,7 +1427,7 @@ exports[`Cloud Object Store Container form component should add Openstack cloud
14281427
</IsRequired>
14291428
}
14301429
loadOptions={[Function]}
1431-
loadOptionsChangeCounter={1}
1430+
loadOptionsChangeCounter={0}
14321431
loadingMessage="Loading..."
14331432
name="storage_manager_id"
14341433
onBlur={[Function]}
@@ -1439,11 +1438,13 @@ exports[`Cloud Object Store Container form component should add Openstack cloud
14391438
value=""
14401439
>
14411440
<ClearedSelect
1441+
className=""
1442+
closeMenuOnSelect={true}
1443+
hideSelectedOptions={false}
14421444
id="storage_manager_id"
14431445
invalidText=""
14441446
isClearable={false}
1445-
isDisabled={true}
1446-
isFetching={true}
1447+
isFetching={false}
14471448
isSearchable={false}
14481449
labelText={
14491450
<IsRequired>
@@ -1462,6 +1463,7 @@ exports[`Cloud Object Store Container form component should add Openstack cloud
14621463
value=""
14631464
>
14641465
<Select
1466+
className=""
14651467
disabled={false}
14661468
helperText=""
14671469
id="storage_manager_id"
@@ -1514,6 +1516,7 @@ exports[`Cloud Object Store Container form component should add Openstack cloud
15141516
onChange={[Function]}
15151517
onFocus={[Function]}
15161518
value=""
1519+
<<<<<<< HEAD
15171520
>
15181521
<SelectItem
15191522
disabled={false}
@@ -1531,6 +1534,9 @@ exports[`Cloud Object Store Container form component should add Openstack cloud
15311534
</option>
15321535
</SelectItem>
15331536
</select>
1537+
=======
1538+
/>
1539+
>>>>>>> f199ae1db1 (Fix CloudObjectStoreContainerForm test)
15341540
<ForwardRef(ChevronDown16)
15351541
className="bx--select__arrow"
15361542
>
@@ -1652,9 +1658,7 @@ exports[`Cloud Object Store Container form component should add Openstack cloud
16521658
"dirtyFieldsSinceLastSubmit": Object {},
16531659
"dirtySinceLastSubmit": false,
16541660
"error": undefined,
1655-
"errors": Object {
1656-
"storage_manager_id": "Required",
1657-
},
1661+
"errors": Object {},
16581662
"form": Object {
16591663
"batch": [Function],
16601664
"blur": [Function],
@@ -1690,28 +1694,22 @@ exports[`Cloud Object Store Container form component should add Openstack cloud
16901694
"subscribe": [Function],
16911695
},
16921696
"hasSubmitErrors": false,
1693-
"hasValidationErrors": true,
1697+
"hasValidationErrors": false,
16941698
"initialValues": Object {},
1695-
"invalid": true,
1696-
"modified": Object {
1697-
"storage_manager_id": false,
1698-
},
1699+
"invalid": false,
1700+
"modified": Object {},
16991701
"modifiedSinceLastSubmit": false,
17001702
"pristine": true,
17011703
"submitError": undefined,
17021704
"submitErrors": undefined,
17031705
"submitFailed": false,
17041706
"submitSucceeded": false,
17051707
"submitting": false,
1706-
"touched": Object {
1707-
"storage_manager_id": false,
1708-
},
1709-
"valid": false,
1708+
"touched": Object {},
1709+
"valid": true,
17101710
"validating": false,
17111711
"values": Object {},
1712-
"visited": Object {
1713-
"storage_manager_id": false,
1714-
},
1712+
"visited": Object {},
17151713
}
17161714
}
17171715
onCancel={[Function]}

app/javascript/spec/cloud-object-store-container-form/cloud-object-store-container-form.spec.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { act } from 'react-dom/test-utils'; // Import act
23
import toJson from 'enzyme-to-json';
34
import fetchMock from 'fetch-mock';
45
import { mount } from '../helpers/mountForm';
@@ -8,6 +9,9 @@ require('../helpers/miqSparkle.js');
89
require('../helpers/miqAjaxButton.js');
910

1011
describe('Cloud Object Store Container form component', () => {
12+
const attributes = 'attributes=id,name,supports_cloud_object_store_container_create';
13+
const filter = 'filter[]=supports_cloud_object_store_container_create=true';
14+
const url = `/api/providers?expand=resources&${attributes}&${filter}`;
1115
const providerOptions = {
1216
resources: [
1317
{
@@ -38,6 +42,7 @@ describe('Cloud Object Store Container form component', () => {
3842
fetchMock.reset();
3943
fetchMock.restore();
4044
});
45+
4146
it('should render add cloud object store container form', () => {
4247
const wrapper = mount(<CloudObjectStoreContainerForm />);
4348
expect(toJson(wrapper)).toMatchSnapshot();
@@ -53,16 +58,17 @@ describe('Cloud Object Store Container form component', () => {
5358
ems_id: '6',
5459
cloud_tenant_id: '1',
5560
};
56-
fetchMock.get(
57-
// eslint-disable-next-line max-len
58-
'/api/providers?expand=resources&attributes=id,name,supports_cloud_object_store_container_create&filter[]=supports_cloud_object_store_container_create=true',
59-
providerOptions
60-
);
61-
fetchMock.mock('/api/cloud_object_store_containers?ems_id=6', { data: { form_schema: { fields: [] } } }, options);
62-
fetchMock.getOnce('/api/providers/6?attributes=type,parent_manager.type', providerDetails);
63-
fetchMock.postOnce('/api/cloud_object_store_containers/', submitData);
64-
const wrapper = mount(<CloudObjectStoreContainerForm />);
65-
expect(toJson(wrapper)).toMatchSnapshot();
61+
62+
await act(async() => { // Wrap the test code in act(...)
63+
fetchMock.get(url, providerOptions);
64+
fetchMock.mock('/api/cloud_object_store_containers?ems_id=6', { data: { form_schema: { fields: [] } } }, options);
65+
fetchMock.getOnce('/api/providers/6?attributes=type,parent_manager.type', providerDetails);
66+
fetchMock.postOnce('/api/cloud_object_store_containers/', submitData);
67+
68+
const wrapper = mount(<CloudObjectStoreContainerForm />);
69+
expect(toJson(wrapper)).toMatchSnapshot();
70+
});
71+
6672
done();
6773
});
6874

@@ -76,16 +82,16 @@ describe('Cloud Object Store Container form component', () => {
7682
ems_id: '87',
7783
providerRegion: 'us-gov-west-1',
7884
};
79-
fetchMock.get(
80-
// eslint-disable-next-line max-len
81-
'/api/providers?expand=resources&attributes=id,name,supports_cloud_object_store_container_create&filter[]=supports_cloud_object_store_container_create=true',
82-
providerOptions
83-
);
84-
fetchMock.mock('/api/cloud_object_store_containers?ems_id=87', { data: { form_schema: { fields: [] } } }, options);
85-
fetchMock.getOnce('/api/providers/6?attributes=type,parent_manager.type', providerDetails);
86-
fetchMock.postOnce('/api/cloud_object_store_containers/', submitData);
87-
const wrapper = mount(<CloudObjectStoreContainerForm />);
88-
expect(toJson(wrapper)).toMatchSnapshot();
85+
86+
await act(async() => { // Wrap the test code in act(...)
87+
fetchMock.get(url, providerOptions);
88+
fetchMock.mock('/api/cloud_object_store_containers?ems_id=87', { data: { form_schema: { fields: [] } } }, options);
89+
fetchMock.getOnce('/api/providers/6?attributes=type,parent_manager.type', providerDetails);
90+
fetchMock.postOnce('/api/cloud_object_store_containers/', submitData);
91+
const wrapper = mount(<CloudObjectStoreContainerForm />);
92+
expect(toJson(wrapper)).toMatchSnapshot();
93+
});
94+
8995
done();
9096
});
9197
});

0 commit comments

Comments
 (0)