mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Cases] Fixes toast message showing for non-synced cases (#124026)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
bc6e30d740
commit
ecba4787f5
5 changed files with 79 additions and 3 deletions
|
@ -62,7 +62,7 @@ describe('RecentCases', () => {
|
|||
<RecentCases {...defaultProps} />
|
||||
</TestProviders>
|
||||
);
|
||||
expect(getAllByTestId('case-details-link')).toHaveLength(5);
|
||||
expect(getAllByTestId('case-details-link')).toHaveLength(7);
|
||||
});
|
||||
|
||||
it('is good at rendering max cases', () => {
|
||||
|
|
|
@ -229,6 +229,7 @@ describe('Case Configuration API', () => {
|
|||
});
|
||||
|
||||
test('should return correct response', async () => {
|
||||
fetchMock.mockResolvedValue(allCasesSnake);
|
||||
const resp = await getCases({
|
||||
filterOptions: { ...DEFAULT_FILTER_OPTIONS, owner: [SECURITY_SOLUTION_OWNER] },
|
||||
queryParams: DEFAULT_QUERY_PARAMS,
|
||||
|
|
|
@ -36,6 +36,8 @@ import { covertToSnakeCase } from './utils';
|
|||
export { connectorsMock } from './configure/mock';
|
||||
|
||||
export const basicCaseId = 'basic-case-id';
|
||||
export const caseWithAlertsId = 'case-with-alerts-id';
|
||||
export const caseWithAlertsSyncOffId = 'case-with-alerts-syncoff-id';
|
||||
export const basicSubCaseId = 'basic-sub-case-id';
|
||||
const basicCommentId = 'basic-comment-id';
|
||||
const basicCreatedAt = '2020-02-19T23:06:33.798Z';
|
||||
|
@ -169,6 +171,20 @@ export const basicCase: Case = {
|
|||
subCaseIds: [],
|
||||
};
|
||||
|
||||
export const caseWithAlerts = {
|
||||
...basicCase,
|
||||
totalAlerts: 2,
|
||||
id: caseWithAlertsId,
|
||||
};
|
||||
export const caseWithAlertsSyncOff = {
|
||||
...basicCase,
|
||||
totalAlerts: 2,
|
||||
settings: {
|
||||
syncAlerts: false,
|
||||
},
|
||||
id: caseWithAlertsSyncOffId,
|
||||
};
|
||||
|
||||
export const basicResolvedCase: ResolvedCase = {
|
||||
case: basicCase,
|
||||
outcome: 'aliasMatch',
|
||||
|
@ -314,6 +330,8 @@ export const cases: Case[] = [
|
|||
{ ...pushedCase, updatedAt: laterTime, id: '2', totalComment: 0, comments: [] },
|
||||
{ ...basicCase, id: '3', totalComment: 0, comments: [] },
|
||||
{ ...basicCase, id: '4', totalComment: 0, comments: [] },
|
||||
caseWithAlerts,
|
||||
caseWithAlertsSyncOff,
|
||||
];
|
||||
|
||||
export const allCases: AllCases = {
|
||||
|
@ -378,6 +396,20 @@ export const basicCaseSnake: CaseResponse = {
|
|||
owner: SECURITY_SOLUTION_OWNER,
|
||||
} as CaseResponse;
|
||||
|
||||
export const caseWithAlertsSnake = {
|
||||
...basicCaseSnake,
|
||||
totalAlerts: 2,
|
||||
id: caseWithAlertsId,
|
||||
};
|
||||
export const caseWithAlertsSyncOffSnake = {
|
||||
...basicCaseSnake,
|
||||
totalAlerts: 2,
|
||||
settings: {
|
||||
syncAlerts: false,
|
||||
},
|
||||
id: caseWithAlertsSyncOffId,
|
||||
};
|
||||
|
||||
export const casesStatusSnake: CasesStatusResponse = {
|
||||
count_closed_cases: 130,
|
||||
count_in_progress_cases: 40,
|
||||
|
@ -423,6 +455,8 @@ export const casesSnake: CasesResponse = [
|
|||
{ ...pushedCaseSnake, updated_at: laterTime, id: '2', totalComment: 0, comments: [] },
|
||||
{ ...basicCaseSnake, id: '3', totalComment: 0, comments: [] },
|
||||
{ ...basicCaseSnake, id: '4', totalComment: 0, comments: [] },
|
||||
caseWithAlertsSnake,
|
||||
caseWithAlertsSyncOffSnake,
|
||||
];
|
||||
|
||||
export const allCasesSnake: CasesFindResponse = {
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
UseGetCases,
|
||||
} from './use_get_cases';
|
||||
import { UpdateKey } from './types';
|
||||
import { allCases, basicCase } from './mock';
|
||||
import { allCases, basicCase, caseWithAlerts, caseWithAlertsSyncOff } from './mock';
|
||||
import * as api from './api';
|
||||
import { TestProviders } from '../common/mock';
|
||||
import { useToasts } from '../common/lib/kibana';
|
||||
|
@ -121,6 +121,47 @@ describe('useGetCases', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('shows a success toast notifying of synced alerts when sync is on', async () => {
|
||||
await act(async () => {
|
||||
const updateCase = {
|
||||
updateKey: 'status' as UpdateKey,
|
||||
updateValue: 'open',
|
||||
caseId: caseWithAlerts.id,
|
||||
refetchCasesStatus: jest.fn(),
|
||||
version: '99999',
|
||||
};
|
||||
const { result, waitForNextUpdate } = renderHook<string, UseGetCases>(() => useGetCases(), {
|
||||
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
|
||||
});
|
||||
await waitForNextUpdate();
|
||||
result.current.dispatchUpdateCaseProperty(updateCase);
|
||||
});
|
||||
expect(addSuccess).toHaveBeenCalledWith({
|
||||
text: 'Updated the statuses of attached alerts.',
|
||||
title: 'Updated "Another horrible breach!!"',
|
||||
});
|
||||
});
|
||||
|
||||
it('shows a success toast without notifying of synced alerts when sync is off', async () => {
|
||||
await act(async () => {
|
||||
const updateCase = {
|
||||
updateKey: 'status' as UpdateKey,
|
||||
updateValue: 'open',
|
||||
caseId: caseWithAlertsSyncOff.id,
|
||||
refetchCasesStatus: jest.fn(),
|
||||
version: '99999',
|
||||
};
|
||||
const { result, waitForNextUpdate } = renderHook<string, UseGetCases>(() => useGetCases(), {
|
||||
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
|
||||
});
|
||||
await waitForNextUpdate();
|
||||
result.current.dispatchUpdateCaseProperty(updateCase);
|
||||
});
|
||||
expect(addSuccess).toHaveBeenCalledWith({
|
||||
title: 'Updated "Another horrible breach!!"',
|
||||
});
|
||||
});
|
||||
|
||||
it('refetch cases', async () => {
|
||||
const spyOnGetCases = jest.spyOn(api, 'getCases');
|
||||
await act(async () => {
|
||||
|
|
|
@ -235,7 +235,7 @@ export const useGetCases = (
|
|||
toasts.addSuccess({
|
||||
title: i18n.UPDATED_CASE(caseData.title),
|
||||
text:
|
||||
updateKey === 'status' && caseData.totalAlerts > 0
|
||||
updateKey === 'status' && caseData.totalAlerts > 0 && caseData.settings.syncAlerts
|
||||
? i18n.STATUS_CHANGED_TOASTER_TEXT
|
||||
: undefined,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue