[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:
Esteban Beltran 2022-01-31 12:49:59 +01:00 committed by GitHub
parent bc6e30d740
commit ecba4787f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 3 deletions

View file

@ -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', () => {

View file

@ -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,

View file

@ -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 = {

View file

@ -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 () => {

View file

@ -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,
});