Skip to content

Commit 611b7ff

Browse files
committed
starting on remmoving act
1 parent 2acb7cc commit 611b7ff

File tree

2 files changed

+127
-137
lines changed

2 files changed

+127
-137
lines changed

x-pack/plugins/security_solution/public/cases/components/user_action_tree/index.test.tsx

Lines changed: 126 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import React from 'react';
88
import { mount } from 'enzyme';
9-
import { waitFor } from '@testing-library/react';
10-
import { act } from 'react-dom/test-utils';
9+
import { wait as waitFor } from '@testing-library/react';
1110

1211
import { Router, routeData, mockHistory, mockLocation } from '../__mock__/router';
1312
import { getFormMock, useFormMock, useFormDataMock } from '../__mock__/form';
@@ -91,16 +90,14 @@ describe('UserActionTree ', () => {
9190
},
9291
caseUserActions: ourActions,
9392
};
94-
95-
await act(async () => {
96-
const wrapper = mount(
97-
<TestProviders>
98-
<Router history={mockHistory}>
99-
<UserActionTree {...props} />
100-
</Router>
101-
</TestProviders>
102-
);
103-
93+
const wrapper = mount(
94+
<TestProviders>
95+
<Router history={mockHistory}>
96+
<UserActionTree {...props} />
97+
</Router>
98+
</TestProviders>
99+
);
100+
await waitFor(() => {
104101
expect(wrapper.find(`[data-test-subj="top-footer"]`).exists()).toBeTruthy();
105102
expect(wrapper.find(`[data-test-subj="bottom-footer"]`).exists()).toBeTruthy();
106103
});
@@ -122,14 +119,14 @@ describe('UserActionTree ', () => {
122119
},
123120
};
124121

125-
await act(async () => {
126-
const wrapper = mount(
127-
<TestProviders>
128-
<Router history={mockHistory}>
129-
<UserActionTree {...props} />
130-
</Router>
131-
</TestProviders>
132-
);
122+
const wrapper = mount(
123+
<TestProviders>
124+
<Router history={mockHistory}>
125+
<UserActionTree {...props} />
126+
</Router>
127+
</TestProviders>
128+
);
129+
await waitFor(() => {
133130
expect(wrapper.find(`[data-test-subj="top-footer"]`).exists()).toBeTruthy();
134131
expect(wrapper.find(`[data-test-subj="bottom-footer"]`).exists()).toBeFalsy();
135132
});
@@ -142,15 +139,15 @@ describe('UserActionTree ', () => {
142139
caseUserActions: ourActions,
143140
};
144141

145-
await act(async () => {
146-
const wrapper = mount(
147-
<TestProviders>
148-
<Router history={mockHistory}>
149-
<UserActionTree {...props} />
150-
</Router>
151-
</TestProviders>
152-
);
142+
const wrapper = mount(
143+
<TestProviders>
144+
<Router history={mockHistory}>
145+
<UserActionTree {...props} />
146+
</Router>
147+
</TestProviders>
148+
);
153149

150+
await waitFor(() => {
154151
expect(
155152
wrapper
156153
.find(`[data-test-subj="comment-create-action-${props.data.comments[0].id}"]`)
@@ -165,34 +162,32 @@ describe('UserActionTree ', () => {
165162
.first()
166163
.simulate('click');
167164

168-
await waitFor(() => {
169-
wrapper.update();
170-
expect(
171-
wrapper
172-
.find(`[data-test-subj="comment-create-action-${props.data.comments[0].id}"]`)
173-
.first()
174-
.hasClass('outlined')
175-
).toBeTruthy();
176-
});
165+
wrapper.update();
166+
expect(
167+
wrapper
168+
.find(`[data-test-subj="comment-create-action-${props.data.comments[0].id}"]`)
169+
.first()
170+
.hasClass('outlined')
171+
).toBeTruthy();
177172
});
178173
});
179174

180175
it('Switches to markdown when edit is clicked and back to panel when canceled', async () => {
181-
await waitFor(() => {
182-
const ourActions = [getUserAction(['comment'], 'create')];
183-
const props = {
184-
...defaultProps,
185-
caseUserActions: ourActions,
186-
};
187-
188-
const wrapper = mount(
189-
<TestProviders>
190-
<Router history={mockHistory}>
191-
<UserActionTree {...props} />
192-
</Router>
193-
</TestProviders>
194-
);
176+
const ourActions = [getUserAction(['comment'], 'create')];
177+
const props = {
178+
...defaultProps,
179+
caseUserActions: ourActions,
180+
};
181+
182+
const wrapper = mount(
183+
<TestProviders>
184+
<Router history={mockHistory}>
185+
<UserActionTree {...props} />
186+
</Router>
187+
</TestProviders>
188+
);
195189

190+
await waitFor(() => {
196191
expect(
197192
wrapper
198193
.find(
@@ -278,24 +273,22 @@ describe('UserActionTree ', () => {
278273
.first()
279274
.simulate('click');
280275

281-
await act(async () => {
282-
await waitFor(() => {
283-
wrapper.update();
284-
expect(
285-
wrapper
286-
.find(
287-
`[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="user-action-markdown-form"]`
288-
)
289-
.exists()
290-
).toEqual(false);
291-
expect(patchComment).toBeCalledWith({
292-
commentUpdate: sampleData.content,
293-
caseId: props.data.id,
294-
commentId: props.data.comments[0].id,
295-
fetchUserActions,
296-
updateCase,
297-
version: props.data.comments[0].version,
298-
});
276+
await waitFor(() => {
277+
wrapper.update();
278+
expect(
279+
wrapper
280+
.find(
281+
`[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="user-action-markdown-form"]`
282+
)
283+
.exists()
284+
).toEqual(false);
285+
expect(patchComment).toBeCalledWith({
286+
commentUpdate: sampleData.content,
287+
caseId: props.data.id,
288+
commentId: props.data.comments[0].id,
289+
fetchUserActions,
290+
updateCase,
291+
version: props.data.comments[0].version,
299292
});
300293
});
301294
});
@@ -320,89 +313,86 @@ describe('UserActionTree ', () => {
320313
.first()
321314
.simulate('click');
322315

323-
await act(async () => {
324-
wrapper
325-
.find(`[data-test-subj="description-action"] [data-test-subj="user-action-save-markdown"]`)
326-
.first()
327-
.simulate('click');
328-
});
329-
330-
wrapper.update();
316+
wrapper
317+
.find(`[data-test-subj="description-action"] [data-test-subj="user-action-save-markdown"]`)
318+
.first()
319+
.simulate('click');
320+
await waitFor(() => {
321+
wrapper.update();
331322

332-
expect(
333-
wrapper
334-
.find(`[data-test-subj="description-action"] [data-test-subj="user-action-markdown-form"]`)
335-
.exists()
336-
).toEqual(false);
323+
expect(
324+
wrapper
325+
.find(
326+
`[data-test-subj="description-action"] [data-test-subj="user-action-markdown-form"]`
327+
)
328+
.exists()
329+
).toEqual(false);
337330

338-
expect(onUpdateField).toBeCalledWith({ key: 'description', value: sampleData.content });
331+
expect(onUpdateField).toBeCalledWith({ key: 'description', value: sampleData.content });
332+
});
339333
});
340334

341335
it('quotes', async () => {
342-
await act(async () => {
343-
const commentData = {
344-
comment: '',
345-
};
346-
const setFieldValue = jest.fn();
347-
348-
const formHookMock = getFormMock(commentData);
349-
useFormMock.mockImplementation(() => ({ form: { ...formHookMock, setFieldValue } }));
350-
351-
const props = defaultProps;
352-
const wrapper = mount(
353-
<TestProviders>
354-
<Router history={mockHistory}>
355-
<UserActionTree {...props} />
356-
</Router>
357-
</TestProviders>
358-
);
336+
const commentData = {
337+
comment: '',
338+
};
339+
const setFieldValue = jest.fn();
359340

360-
wrapper
361-
.find(`[data-test-subj="description-action"] [data-test-subj="property-actions-ellipses"]`)
362-
.first()
363-
.simulate('click');
341+
const formHookMock = getFormMock(commentData);
342+
useFormMock.mockImplementation(() => ({ form: { ...formHookMock, setFieldValue } }));
364343

365-
await waitFor(() => {
366-
wrapper.update();
344+
const props = defaultProps;
345+
const wrapper = mount(
346+
<TestProviders>
347+
<Router history={mockHistory}>
348+
<UserActionTree {...props} />
349+
</Router>
350+
</TestProviders>
351+
);
367352

368-
wrapper
369-
.find(`[data-test-subj="description-action"] [data-test-subj="property-actions-quote"]`)
370-
.first()
371-
.simulate('click');
372-
});
353+
wrapper
354+
.find(`[data-test-subj="description-action"] [data-test-subj="property-actions-ellipses"]`)
355+
.first()
356+
.simulate('click');
357+
358+
await waitFor(() => {
359+
wrapper.update();
373360

374-
expect(setFieldValue).toBeCalledWith('comment', `> ${props.data.description} \n`);
361+
wrapper
362+
.find(`[data-test-subj="description-action"] [data-test-subj="property-actions-quote"]`)
363+
.first()
364+
.simulate('click');
375365
});
366+
367+
expect(setFieldValue).toBeCalledWith('comment', `> ${props.data.description} \n`);
376368
});
377369

378370
it('Outlines comment when url param is provided', async () => {
379371
const commentId = 'basic-comment-id';
380372
jest.spyOn(routeData, 'useParams').mockReturnValue({ commentId });
381373

382-
await act(async () => {
383-
const ourActions = [getUserAction(['comment'], 'create')];
384-
const props = {
385-
...defaultProps,
386-
caseUserActions: ourActions,
387-
};
388-
389-
const wrapper = mount(
390-
<TestProviders>
391-
<Router history={mockHistory}>
392-
<UserActionTree {...props} />
393-
</Router>
394-
</TestProviders>
395-
);
396-
397-
await waitFor(() => {
398-
wrapper.update();
399-
expect(
400-
wrapper
401-
.find(`[data-test-subj="comment-create-action-${commentId}"]`)
402-
.first()
403-
.hasClass('outlined')
404-
).toBeTruthy();
405-
});
374+
const ourActions = [getUserAction(['comment'], 'create')];
375+
const props = {
376+
...defaultProps,
377+
caseUserActions: ourActions,
378+
};
379+
380+
const wrapper = mount(
381+
<TestProviders>
382+
<Router history={mockHistory}>
383+
<UserActionTree {...props} />
384+
</Router>
385+
</TestProviders>
386+
);
387+
388+
await waitFor(() => {
389+
wrapper.update();
390+
expect(
391+
wrapper
392+
.find(`[data-test-subj="comment-create-action-${commentId}"]`)
393+
.first()
394+
.hasClass('outlined')
395+
).toBeTruthy();
406396
});
407397
});
408398
});

x-pack/plugins/security_solution/public/timelines/components/open_timeline/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import React from 'react';
1010
import { renderHook, act } from '@testing-library/react-hooks';
1111
import { mount } from 'enzyme';
1212
import { MockedProvider } from 'react-apollo/test-utils';
13-
import { waitFor } from '@testing-library/react';
13+
import { wait as waitFor } from '@testing-library/react';
1414
import { useHistory, useParams } from 'react-router-dom';
1515

1616
import '../../../common/mock/match_media';

0 commit comments

Comments
 (0)