-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pushing changes, user_action_tree is wip
- Loading branch information
1 parent
fee0a47
commit 2520299
Showing
5 changed files
with
311 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
x-pack/legacy/plugins/siem/public/pages/case/components/use_push_to_service/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
/* eslint-disable react/display-name */ | ||
// import React from 'react'; | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
import { usePushToService, ReturnUsePushToService, UsePushToService } from './'; | ||
import { TestProviders } from '../../../../mock'; | ||
import React from 'react'; | ||
import * as api from '../../../../containers/case/configure/api'; | ||
import { usePostPushToService } from '../../../../containers/case/use_post_push_to_service'; | ||
import { ClosureType } from '../../../../../../../../plugins/case/common/api/cases'; | ||
import * as i18n from './translations'; | ||
jest.mock('../../../../containers/case/use_post_push_to_service'); | ||
jest.mock('../../../../containers/case/configure/api'); | ||
import { useGetActionLicense } from '../../../../containers/case/use_get_action_license'; | ||
import { getKibanaConfigError, getLicenseError } from './helpers'; | ||
jest.mock('../../../../containers/case/use_get_action_license'); | ||
|
||
describe('usePushToService', () => { | ||
const caseId = '12345'; | ||
const updateCase = jest.fn(); | ||
const postPushToService = jest.fn(); | ||
const mockPostPush = { | ||
isLoading: false, | ||
postPushToService, | ||
}; | ||
const closureType: ClosureType = 'close-by-user'; | ||
const mockConnector = { | ||
connectorId: 'c00l', | ||
connectorName: 'name', | ||
}; | ||
const mockCaseConfigure = { | ||
...mockConnector, | ||
createdAt: 'string', | ||
createdBy: {}, | ||
closureType, | ||
updatedAt: 'string', | ||
updatedBy: {}, | ||
version: 'string', | ||
}; | ||
const getConfigureMock = api.getCaseConfigure as jest.Mock; | ||
const actionLicense = { | ||
id: '.servicenow', | ||
name: 'ServiceNow', | ||
minimumLicenseRequired: 'platinum', | ||
enabled: true, | ||
enabledInConfig: true, | ||
enabledInLicense: true, | ||
}; | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
(usePostPushToService as jest.Mock).mockImplementation(() => mockPostPush); | ||
(useGetActionLicense as jest.Mock).mockImplementation(() => ({ | ||
isLoading: false, | ||
actionLicense, | ||
})); | ||
getConfigureMock.mockImplementation(() => Promise.resolve(mockCaseConfigure)); | ||
}); | ||
it('push case button posts the push with correct args', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<UsePushToService, ReturnUsePushToService>( | ||
() => | ||
usePushToService({ | ||
caseId, | ||
caseStatus: 'open', | ||
isNew: false, | ||
updateCase, | ||
userCanCrud: true, | ||
}), | ||
{ | ||
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>, | ||
} | ||
); | ||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
expect(getConfigureMock).toBeCalled(); | ||
result.current.pushButton.props.children.props.onClick(); | ||
expect(postPushToService).toBeCalledWith({ ...mockConnector, caseId, updateCase }); | ||
expect(result.current.pushCallouts).toBeNull(); | ||
}); | ||
}); | ||
it('Displays message when user does not have premium license', async () => { | ||
(useGetActionLicense as jest.Mock).mockImplementation(() => ({ | ||
isLoading: false, | ||
actionLicense: { | ||
...actionLicense, | ||
enabledInLicense: false, | ||
}, | ||
})); | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<UsePushToService, ReturnUsePushToService>( | ||
() => | ||
usePushToService({ | ||
caseId, | ||
caseStatus: 'open', | ||
isNew: false, | ||
updateCase, | ||
userCanCrud: true, | ||
}), | ||
{ | ||
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>, | ||
} | ||
); | ||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
const errorsMsg = result.current.pushCallouts?.props.messages; | ||
expect(errorsMsg).toHaveLength(1); | ||
expect(errorsMsg[0].title).toEqual(getLicenseError().title); | ||
}); | ||
}); | ||
it('Displays message when user does not have case enabled in config', async () => { | ||
(useGetActionLicense as jest.Mock).mockImplementation(() => ({ | ||
isLoading: false, | ||
actionLicense: { | ||
...actionLicense, | ||
enabledInConfig: false, | ||
}, | ||
})); | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<UsePushToService, ReturnUsePushToService>( | ||
() => | ||
usePushToService({ | ||
caseId, | ||
caseStatus: 'open', | ||
isNew: false, | ||
updateCase, | ||
userCanCrud: true, | ||
}), | ||
{ | ||
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>, | ||
} | ||
); | ||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
const errorsMsg = result.current.pushCallouts?.props.messages; | ||
expect(errorsMsg).toHaveLength(1); | ||
expect(errorsMsg[0].title).toEqual(getKibanaConfigError().title); | ||
}); | ||
}); | ||
it('Displays message when user does not have a connector configured', async () => { | ||
getConfigureMock.mockImplementation(() => | ||
Promise.resolve({ | ||
...mockCaseConfigure, | ||
connectorId: 'none', | ||
}) | ||
); | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<UsePushToService, ReturnUsePushToService>( | ||
() => | ||
usePushToService({ | ||
caseId, | ||
caseStatus: 'open', | ||
isNew: false, | ||
updateCase, | ||
userCanCrud: true, | ||
}), | ||
{ | ||
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>, | ||
} | ||
); | ||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
const errorsMsg = result.current.pushCallouts?.props.messages; | ||
expect(errorsMsg).toHaveLength(1); | ||
expect(errorsMsg[0].title).toEqual(i18n.PUSH_DISABLE_BY_NO_CASE_CONFIG_TITLE); | ||
}); | ||
}); | ||
it('Displays message when case is closed', async () => { | ||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook<UsePushToService, ReturnUsePushToService>( | ||
() => | ||
usePushToService({ | ||
caseId, | ||
caseStatus: 'closed', | ||
isNew: false, | ||
updateCase, | ||
userCanCrud: true, | ||
}), | ||
{ | ||
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>, | ||
} | ||
); | ||
await waitForNextUpdate(); | ||
await waitForNextUpdate(); | ||
const errorsMsg = result.current.pushCallouts?.props.messages; | ||
expect(errorsMsg).toHaveLength(1); | ||
expect(errorsMsg[0].title).toEqual(i18n.PUSH_DISABLE_BECAUSE_CASE_CLOSED_TITLE); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
x-pack/legacy/plugins/siem/public/pages/case/components/user_action_tree/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { Router, routeData, mockHistory } from '../__mock__/router'; | ||
import { UserActionTree } from './'; | ||
import { TestProviders } from '../../../../mock'; | ||
import { UserActionField } from '../../../../../../../../plugins/case/common/api/cases'; | ||
|
||
const fetchUserActions = jest.fn(); | ||
const onUpdateField = jest.fn(); | ||
const updateCase = jest.fn(); | ||
const defaultProps = { | ||
data: { | ||
id: '89bae2b0-74f4-11ea-a8d2-2bcd64fb2cdd', | ||
version: 'WzcxNiwxXQ==', | ||
comments: [], | ||
totalComment: 0, | ||
description: 'This looks not so good', | ||
title: 'Bad meanie defacing data', | ||
tags: ['defacement'], | ||
closedAt: null, | ||
closedBy: null, | ||
createdAt: '2020-04-02T15:13:41.925Z', | ||
createdBy: { | ||
email: '[email protected]', | ||
fullName: 'Steph Milovic', | ||
username: 'smilovic', | ||
}, | ||
externalService: null, | ||
status: 'open', | ||
updatedAt: null, | ||
updatedBy: null, | ||
}, | ||
caseUserActions: [], | ||
firstIndexPushToService: -1, | ||
isLoadingDescription: false, | ||
isLoadingUserActions: false, | ||
lastIndexPushToService: -1, | ||
userCanCrud: true, | ||
fetchUserActions, | ||
onUpdateField, | ||
updateCase, | ||
}; | ||
|
||
describe.skip('UserActionTree ', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
jest.spyOn(routeData, 'useParams').mockReturnValue({ commentId: '123' }); | ||
}); | ||
|
||
it('Loading spinner when user actions loading', async () => { | ||
const props = defaultProps; | ||
const wrapper = mount( | ||
<TestProviders> | ||
<Router history={mockHistory}> | ||
<UserActionTree {...{ ...props, isLoadingUserActions: true }} /> | ||
</Router> | ||
</TestProviders> | ||
); | ||
expect(wrapper.find(`[data-test-subj="user-actions-loading"]`).exists()).toBeTruthy(); | ||
}); | ||
it.only('Renders user action items', async () => { | ||
const commentAction = { | ||
actionField: [('comment' as unknown) as UserActionField['comment']], | ||
action: 'create', | ||
actionAt: '2020-04-06T21:54:19.459Z', | ||
actionBy: { email: '', fullName: '', username: 'casetester3' }, | ||
newValue: 'sdfsd', | ||
oldValue: null, | ||
actionId: '2b825fb0-7851-11ea-8b3c-092fb98f129e', | ||
caseId: '89bae2b0-74f4-11ea-a8d2-2bcd64fb2cdd', | ||
commentId: '2adcf7f0-7851-11ea-8b3c-092fb98f129e', | ||
}; | ||
const props = { | ||
...defaultProps, | ||
caseUserActions: [commentAction], | ||
}; | ||
const wrapper = mount( | ||
<TestProviders> | ||
<Router history={mockHistory}> | ||
<UserActionTree {...props} /> | ||
</Router> | ||
</TestProviders> | ||
); | ||
expect( | ||
wrapper | ||
.find(`[data-test-subj="comment-action"] [data-test-subj="user-action-title"] strong`) | ||
.text() | ||
).toEqual(commentAction.actionBy.username); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters