diff --git a/x-pack/plugins/cases/public/components/add_comment/index.test.tsx b/x-pack/plugins/cases/public/components/add_comment/index.test.tsx index f7535e6f52071..b9a253adc76f5 100644 --- a/x-pack/plugins/cases/public/components/add_comment/index.test.tsx +++ b/x-pack/plugins/cases/public/components/add_comment/index.test.tsx @@ -14,17 +14,17 @@ import { TestProviders } from '../../common/mock'; import { CommentRequest, CommentType } from '../../../common/api'; import { SECURITY_SOLUTION_OWNER } from '../../../common/constants'; -import { usePostComment } from '../../containers/use_post_comment'; +import { useCreateAttachments } from '../../containers/use_create_attachments'; import { AddComment, AddCommentProps, AddCommentRefObject } from '.'; import { CasesTimelineIntegrationProvider } from '../timeline_context'; import { timelineIntegrationMock } from '../__mock__/timeline'; -jest.mock('../../containers/use_post_comment'); +jest.mock('../../containers/use_create_attachments'); -const usePostCommentMock = usePostComment as jest.Mock; +const useCreateAttachmentsMock = useCreateAttachments as jest.Mock; const onCommentSaving = jest.fn(); const onCommentPosted = jest.fn(); -const postComment = jest.fn(); +const createAttachments = jest.fn(); const addCommentProps: AddCommentProps = { id: 'newComment', @@ -36,10 +36,10 @@ const addCommentProps: AddCommentProps = { statusActionButton: null, }; -const defaultPostComment = { +const defaultResponse = { isLoading: false, isError: false, - postComment, + createAttachments, }; const sampleData: CommentRequest = { @@ -51,7 +51,7 @@ const sampleData: CommentRequest = { describe('AddComment ', () => { beforeEach(() => { jest.clearAllMocks(); - usePostCommentMock.mockImplementation(() => defaultPostComment); + useCreateAttachmentsMock.mockImplementation(() => defaultResponse); }); it('should post comment on submit click', async () => { @@ -72,9 +72,9 @@ describe('AddComment ', () => { wrapper.find(`[data-test-subj="submit-comment"]`).first().simulate('click'); await waitFor(() => { expect(onCommentSaving).toBeCalled(); - expect(postComment).toBeCalledWith({ + expect(createAttachments).toBeCalledWith({ caseId: addCommentProps.caseId, - data: sampleData, + data: [sampleData], updateCase: onCommentPosted, }); expect(wrapper.find(`[data-test-subj="add-comment"] textarea`).text()).toBe(''); @@ -82,7 +82,10 @@ describe('AddComment ', () => { }); it('should render spinner and disable submit when loading', () => { - usePostCommentMock.mockImplementation(() => ({ ...defaultPostComment, isLoading: true })); + useCreateAttachmentsMock.mockImplementation(() => ({ + ...defaultResponse, + isLoading: true, + })); const wrapper = mount( @@ -96,7 +99,10 @@ describe('AddComment ', () => { }); it('should disable submit button when isLoading is true', () => { - usePostCommentMock.mockImplementation(() => ({ ...defaultPostComment, isLoading: true })); + useCreateAttachmentsMock.mockImplementation(() => ({ + ...defaultResponse, + isLoading: true, + })); const wrapper = mount( @@ -109,7 +115,10 @@ describe('AddComment ', () => { }); it('should hide the component when the user does not have crud permissions', () => { - usePostCommentMock.mockImplementation(() => ({ ...defaultPostComment, isLoading: true })); + useCreateAttachmentsMock.mockImplementation(() => ({ + ...defaultResponse, + isLoading: true, + })); const wrapper = mount( diff --git a/x-pack/plugins/cases/public/components/add_comment/index.tsx b/x-pack/plugins/cases/public/components/add_comment/index.tsx index dea692f7c71a1..f3630d16cda79 100644 --- a/x-pack/plugins/cases/public/components/add_comment/index.tsx +++ b/x-pack/plugins/cases/public/components/add_comment/index.tsx @@ -18,7 +18,7 @@ import styled from 'styled-components'; import { isEmpty } from 'lodash'; import { CommentType } from '../../../common/api'; -import { usePostComment } from '../../containers/use_post_comment'; +import { useCreateAttachments } from '../../containers/use_create_attachments'; import { Case } from '../../containers/types'; import { EuiMarkdownEditorRef, MarkdownEditorForm } from '../markdown_editor'; import { Form, useForm, UseField, useFormData } from '../../common/shared_imports'; @@ -71,7 +71,7 @@ export const AddComment = React.memo( const editorRef = useRef(null); const [focusOnContext, setFocusOnContext] = useState(false); const { owner } = useCasesContext(); - const { isLoading, postComment } = usePostComment(); + const { isLoading, createAttachments } = useCreateAttachments(); const { form } = useForm({ defaultValue: initialCommentValue, @@ -112,14 +112,14 @@ export const AddComment = React.memo( if (onCommentSaving != null) { onCommentSaving(); } - postComment({ + createAttachments({ caseId, - data: { ...data, type: CommentType.user, owner: owner[0] }, + data: [{ ...data, type: CommentType.user, owner: owner[0] }], updateCase: onCommentPosted, }); reset(); } - }, [submit, onCommentSaving, postComment, caseId, owner, onCommentPosted, reset]); + }, [submit, onCommentSaving, createAttachments, caseId, owner, onCommentPosted, reset]); /** * Focus on the text area when a quote has been added. diff --git a/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx b/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx index b1f5af86cf8ab..a3d91617a20c4 100644 --- a/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx @@ -33,11 +33,11 @@ import { triggersActionsUiMock } from '../../../../triggers_actions_ui/public/mo import { registerConnectorsToMockActionRegistry } from '../../common/mock/register_connectors'; import { createStartServicesMock } from '../../common/lib/kibana/kibana_react.mock'; import { waitForComponentToUpdate } from '../../common/test_utils'; -import { usePostComment } from '../../containers/use_post_comment'; +import { useCreateAttachments } from '../../containers/use_create_attachments'; import { useGetTags } from '../../containers/use_get_tags'; import { useGetReporters } from '../../containers/use_get_reporters'; -jest.mock('../../containers/use_post_comment'); +jest.mock('../../containers/use_create_attachments'); jest.mock('../../containers/use_bulk_update_case'); jest.mock('../../containers/use_delete_cases'); jest.mock('../../containers/use_get_cases'); @@ -61,7 +61,7 @@ const useGetTagsMock = useGetTags as jest.Mock; const useGetReportersMock = useGetReporters as jest.Mock; const useKibanaMock = useKibana as jest.MockedFunction; const useConnectorsMock = useConnectors as jest.Mock; -const usePostCommentMock = usePostComment as jest.Mock; +const useCreateAttachmentsMock = useCreateAttachments as jest.Mock; const mockTriggersActionsUiService = triggersActionsUiMock.createStart(); @@ -88,7 +88,10 @@ describe('AllCasesListGeneric', () => { const fetchCasesStatus = jest.fn(); const onRowClick = jest.fn(); const emptyTag = getEmptyTagValue().props.children; - usePostCommentMock.mockReturnValue({ status: { isLoading: false }, postComment: jest.fn() }); + useCreateAttachmentsMock.mockReturnValue({ + status: { isLoading: false }, + createAttachments: jest.fn(), + }); const defaultGetCases = { ...useGetCasesMockState, diff --git a/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx b/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx index 25360800554b2..f0eea39d551a7 100644 --- a/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx @@ -14,14 +14,14 @@ import { Case, CaseStatuses, StatusAll } from '../../../../common'; import { AppMockRenderer, createAppMockRenderer } from '../../../common/mock'; import { useCasesToast } from '../../../common/use_cases_toast'; import { alertComment } from '../../../containers/mock'; -import { usePostComment } from '../../../containers/use_post_comment'; +import { useCreateAttachments } from '../../../containers/use_create_attachments'; import { SupportedCaseAttachment } from '../../../types'; import { CasesContext } from '../../cases_context'; import { CasesContextStoreActionsList } from '../../cases_context/cases_context_reducer'; import { useCasesAddToExistingCaseModal } from './use_cases_add_to_existing_case_modal'; jest.mock('../../../common/use_cases_toast'); -jest.mock('../../../containers/use_post_comment'); +jest.mock('../../../containers/use_create_attachments'); // dummy mock, will call onRowclick when rendering jest.mock('./all_cases_selector_modal', () => { return { @@ -46,11 +46,11 @@ const TestComponent: React.FC = () => { return