mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Co-authored-by: David Sánchez <davidsansol92@gmail.com>
This commit is contained in:
parent
aa3c54879e
commit
1d7c3d2769
4 changed files with 59 additions and 1 deletions
|
@ -22,6 +22,11 @@ import { EventFiltersListPageState, EventFiltersService } from '../types';
|
|||
import { getFoundExceptionListItemSchemaMock } from '../../../../../../lists/common/schemas/response/found_exception_list_item_schema.mock';
|
||||
import { isFailedResourceState, isLoadedResourceState } from '../../../state';
|
||||
import { getListFetchError } from './selector';
|
||||
import type {
|
||||
ExceptionListItemSchema,
|
||||
CreateExceptionListItemSchema,
|
||||
} from '@kbn/securitysolution-io-ts-list-types';
|
||||
import { Immutable } from '../../../../../common/endpoint/types';
|
||||
|
||||
const createEventFiltersServiceMock = (): jest.Mocked<EventFiltersService> => ({
|
||||
addEventFilters: jest.fn(),
|
||||
|
@ -208,6 +213,38 @@ describe('Event filters middleware', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('does submit when entry has empty comments with white spaces', async () => {
|
||||
service.addEventFilters.mockImplementation(
|
||||
async (exception: Immutable<ExceptionListItemSchema | CreateExceptionListItemSchema>) => {
|
||||
expect(exception.comments).toStrictEqual(createdEventFilterEntryMock().comments);
|
||||
return createdEventFilterEntryMock();
|
||||
}
|
||||
);
|
||||
const entry = getInitialExceptionFromEvent(ecsEventMock());
|
||||
store.dispatch({
|
||||
type: 'eventFiltersInitForm',
|
||||
payload: { entry },
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'eventFiltersChangeForm',
|
||||
payload: { newComment: ' ', entry },
|
||||
});
|
||||
|
||||
store.dispatch({ type: 'eventFiltersCreateStart' });
|
||||
await spyMiddleware.waitForAction('eventFiltersFormStateChanged');
|
||||
expect(store.getState()).toStrictEqual({
|
||||
...initialState,
|
||||
form: {
|
||||
...store.getState().form,
|
||||
submissionResourceState: {
|
||||
type: 'LoadedResourceState',
|
||||
data: createdEventFilterEntryMock(),
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('does throw error when creating', async () => {
|
||||
service.addEventFilters.mockRejectedValue({
|
||||
body: { message: 'error message', statusCode: 500, error: 'Internal Server Error' },
|
||||
|
|
|
@ -57,7 +57,8 @@ const addNewComments = (
|
|||
): UpdateExceptionListItemSchema | CreateExceptionListItemSchema => {
|
||||
if (newComment) {
|
||||
if (!entry.comments) entry.comments = [];
|
||||
entry.comments.push({ comment: newComment });
|
||||
const trimmedComment = newComment.trim();
|
||||
if (trimmedComment) entry.comments.push({ comment: trimmedComment });
|
||||
}
|
||||
return entry;
|
||||
};
|
||||
|
|
|
@ -88,6 +88,25 @@ describe('event filters reducer', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('clean form after change form status', () => {
|
||||
const entry = getInitialExceptionFromEvent(ecsEventMock());
|
||||
const nameChanged = 'name changed';
|
||||
const newComment = 'new comment';
|
||||
const result = eventFiltersPageReducer(initialState, {
|
||||
type: 'eventFiltersChangeForm',
|
||||
payload: { entry: { ...entry, name: nameChanged }, newComment },
|
||||
});
|
||||
const cleanState = eventFiltersPageReducer(result, {
|
||||
type: 'eventFiltersInitForm',
|
||||
payload: { entry },
|
||||
});
|
||||
|
||||
expect(cleanState).toStrictEqual({
|
||||
...initialState,
|
||||
form: { ...initialState.form, entry, hasNameError: true, newComment: '' },
|
||||
});
|
||||
});
|
||||
|
||||
it('create is success and force list refresh', () => {
|
||||
const initialStateWithListPageActive = {
|
||||
...initialState,
|
||||
|
|
|
@ -86,6 +86,7 @@ const eventFiltersInitForm: CaseReducer<EventFiltersInitForm> = (state, action)
|
|||
entry: action.payload.entry,
|
||||
hasNameError: !action.payload.entry.name,
|
||||
hasOSError: !action.payload.entry.os_types?.length,
|
||||
newComment: '',
|
||||
submissionResourceState: {
|
||||
type: 'UninitialisedResourceState',
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue