Skip to content

Commit 3fceccb

Browse files
Merge pull request #9179 from jeffibm/fix-host-edit-form-test
Fix HostEditForm test
2 parents ba709e0 + 0eb4765 commit 3fceccb

File tree

2 files changed

+25
-45
lines changed

2 files changed

+25
-45
lines changed

app/javascript/spec/host-edit-form/helper-data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const samepleInitialValues = {
1+
export const sampleInitialValues = {
22
id: '1',
33
name: '10.197.65.254',
44
hostname: null,
@@ -7,7 +7,7 @@ export const samepleInitialValues = {
77
type: 'ManageIQ::Providers::IbmPowerHmc::InfraManager::Host',
88
};
99

10-
export const sampleSingleReponse = {
10+
export const sampleSingleResponse = {
1111
data: {
1212
form_schema: {
1313
fields: [

app/javascript/spec/host-edit-form/host-edit-form.spec.js

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,59 @@ import React from 'react';
22
import toJson from 'enzyme-to-json';
33
import fetchMock from 'fetch-mock';
44
import { act } from 'react-dom/test-utils';
5-
import { Button } from 'carbon-components-react';
65
import HostEditForm from '../../components/host-edit-form/host-edit-form';
7-
import { samepleInitialValues, sampleSingleReponse, sampleMultiResponse } from './helper-data';
6+
import { sampleInitialValues, sampleSingleResponse, sampleMultiResponse } from './helper-data';
87

9-
import { mount, shallow } from '../helpers/mountForm';
8+
import { mount } from '../helpers/mountForm';
109
import '../../oldjs/miq_application'; // for miqJqueryRequest
1110
import '../helpers/miqSparkle';
1211

1312
describe('Show Edit Host Form Component', () => {
14-
let submitSpy;
15-
1613
const id = [1];
1714
const ids = [1, 2, 3];
1815

1916
beforeEach(() => {
20-
// fetchMock
21-
// .once('/api/event_streams', sampleReponse);
22-
// submitSpy = jest.spyOn(window, 'miqJqueryRequest');
2317
});
2418

2519
afterEach(() => {
2620
fetchMock.reset();
2721
fetchMock.restore();
28-
// submitSpy.mockRestore();
2922
});
3023

31-
/*
32-
* Render Form
33-
*/
34-
24+
/** Render Form */
3525
it('should render form for *one* host', async(done) => {
3626
let wrapper;
37-
fetchMock
38-
.get(`/api/hosts/${id[0]}?expand=resources&attributes=authentications`, samepleInitialValues)
39-
.mock(`/api/hosts/${id[0]}`, sampleSingleReponse);
4027
await act(async() => {
28+
fetchMock
29+
.get(`/api/hosts/${id[0]}?expand=resources&attributes=authentications`, sampleInitialValues)
30+
.mock(`/api/hosts/${id[0]}`, sampleSingleResponse);
4131
wrapper = mount(<HostEditForm ids={id} />);
4232
});
43-
setImmediate(() => {
44-
wrapper.update();
45-
expect(toJson(wrapper)).toMatchSnapshot();
46-
done();
33+
34+
// Wrap AsyncCredentials updates in act(...)
35+
await act(async() => {
36+
setImmediate(() => {
37+
wrapper.update();
38+
expect(toJson(wrapper)).toMatchSnapshot();
39+
done();
40+
});
4741
});
4842
});
4943

5044
it('should render form for multiple hosts', async(done) => {
5145
let wrapper;
52-
fetchMock.get(`/api/hosts?expand=resources&attributes=id,name&filter[]=id=[${ids}]`, sampleMultiResponse);
5346
await act(async() => {
47+
fetchMock.get(`/api/hosts?expand=resources&attributes=id,name&filter[]=id=[${ids}]`, sampleMultiResponse);
5448
wrapper = mount(<HostEditForm ids={ids} />);
5549
});
56-
setImmediate(() => {
57-
wrapper.update();
58-
expect(toJson(wrapper)).toMatchSnapshot();
59-
done();
50+
51+
// Wrap AsyncCredentials updates in act(...)
52+
await act(async() => {
53+
setImmediate(() => {
54+
wrapper.update();
55+
expect(toJson(wrapper)).toMatchSnapshot();
56+
done();
57+
});
6058
});
6159
});
62-
63-
/*
64-
* Submit Logic
65-
*/
66-
67-
// it('should not submit values when form is empty', async(done) => {
68-
// let wrapper;
69-
// await act(async() => {
70-
// wrapper = mount(<TimelineOptions url="sample/url" />);
71-
// });
72-
// setImmediate(() => {
73-
// wrapper.update();
74-
// expect(wrapper.find(Button)).toHaveLength(1);
75-
// wrapper.find(Button).first().simulate('click');
76-
// expect(submitSpy).toHaveBeenCalledTimes(0);
77-
// done();
78-
// });
79-
// });
8060
});

0 commit comments

Comments
 (0)