@@ -2,79 +2,59 @@ import React from 'react';
22import toJson from 'enzyme-to-json' ;
33import fetchMock from 'fetch-mock' ;
44import { act } from 'react-dom/test-utils' ;
5- import { Button } from 'carbon-components-react' ;
65import 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' ;
109import '../../oldjs/miq_application' ; // for miqJqueryRequest
1110import '../helpers/miqSparkle' ;
1211
1312describe ( '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