mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* [SIEM] fix bug to not allow to unpinn an event when adding 2*nth note on this event * fix type check
This commit is contained in:
parent
29d5c02ad4
commit
0f634b7a5b
3 changed files with 133 additions and 5 deletions
|
@ -22,6 +22,7 @@ import { EventColumnView } from './event_column_view';
|
|||
import { ColumnRenderer } from '../renderers/column_renderer';
|
||||
import { RowRenderer } from '../renderers/row_renderer';
|
||||
import { getRowRenderer } from '../renderers/get_row_renderer';
|
||||
import { eventIsPinned } from '../helpers';
|
||||
|
||||
interface Props {
|
||||
actionsColumnWidth: number;
|
||||
|
@ -179,6 +180,8 @@ export class StatefulEvent extends React.PureComponent<Props, State> {
|
|||
onPinEvent: OnPinEvent
|
||||
): ((noteId: string) => void) => (noteId: string) => {
|
||||
addNoteToEvent({ eventId, noteId });
|
||||
onPinEvent(eventId); // pin the event, because it has notes
|
||||
if (!eventIsPinned({ eventId, pinnedEventIds: this.props.pinnedEventIds })) {
|
||||
onPinEvent(eventId); // pin the event, because it has notes
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { mount } from 'enzyme';
|
||||
import { mount, ReactWrapper } from 'enzyme';
|
||||
import 'jest-styled-components';
|
||||
import * as React from 'react';
|
||||
|
||||
|
@ -13,7 +13,7 @@ import { Direction } from '../../../graphql/types';
|
|||
import { defaultHeaders, mockTimelineData } from '../../../mock';
|
||||
import { TestProviders } from '../../../mock/test_providers';
|
||||
|
||||
import { Body } from '.';
|
||||
import { Body, BodyProps } from '.';
|
||||
import { columnRenderers, rowRenderers } from './renderers';
|
||||
import { Sort } from './sort';
|
||||
|
||||
|
@ -187,4 +187,129 @@ describe('Body', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('action on event', () => {
|
||||
const dispatchAddNoteToEvent = jest.fn();
|
||||
const dispatchOnPinEvent = jest.fn();
|
||||
|
||||
const addaNoteToEvent = (wrapper: ReactWrapper, note: string) => {
|
||||
wrapper
|
||||
.find('[data-test-subj="timeline-notes-icon"]')
|
||||
.first()
|
||||
.simulate('click');
|
||||
wrapper.update();
|
||||
wrapper
|
||||
.find('[data-test-subj="new-note-tabs"] textarea')
|
||||
.simulate('change', { target: { value: 'hello world' } });
|
||||
wrapper.update();
|
||||
wrapper
|
||||
.find('button[data-test-subj="add-note"]')
|
||||
.first()
|
||||
.simulate('click');
|
||||
wrapper.update();
|
||||
};
|
||||
|
||||
// We are doing that because we need to wrapped this component with redux
|
||||
// and redux does not like to be updated and since we need to update our
|
||||
// child component (BODY) and we do not want to scare anyone with this error
|
||||
// we are hiding it!!!
|
||||
// eslint-disable-next-line no-console
|
||||
const originalError = console.error;
|
||||
beforeAll(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error = (...args: string[]) => {
|
||||
if (/<Provider> does not support changing `store` on the fly/.test(args[0])) {
|
||||
return;
|
||||
}
|
||||
originalError.call(console, ...args);
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
dispatchAddNoteToEvent.mockClear();
|
||||
dispatchOnPinEvent.mockClear();
|
||||
});
|
||||
|
||||
test('Add a Note to an event', () => {
|
||||
const wrapper = mount(
|
||||
<TestProviders>
|
||||
<Body
|
||||
addNoteToEvent={dispatchAddNoteToEvent}
|
||||
browserFields={mockBrowserFields}
|
||||
columnHeaders={defaultHeaders}
|
||||
columnRenderers={columnRenderers}
|
||||
data={mockTimelineData}
|
||||
eventIdToNoteIds={{}}
|
||||
height={testBodyHeight}
|
||||
id={'timeline-test'}
|
||||
isLoading={false}
|
||||
getNotesByIds={mockGetNotesByIds}
|
||||
onColumnRemoved={jest.fn()}
|
||||
onColumnResized={jest.fn()}
|
||||
onColumnSorted={jest.fn()}
|
||||
onFilterChange={jest.fn()}
|
||||
onPinEvent={dispatchOnPinEvent}
|
||||
onUnPinEvent={jest.fn()}
|
||||
onUpdateColumns={jest.fn()}
|
||||
pinnedEventIds={{}}
|
||||
range={'1 Day'}
|
||||
rowRenderers={rowRenderers}
|
||||
sort={mockSort}
|
||||
updateNote={jest.fn()}
|
||||
width={100}
|
||||
/>
|
||||
</TestProviders>
|
||||
);
|
||||
addaNoteToEvent(wrapper, 'hello world');
|
||||
|
||||
expect(dispatchAddNoteToEvent).toHaveBeenCalled();
|
||||
expect(dispatchOnPinEvent).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('Add two Note to an event', () => {
|
||||
const Proxy = (props: BodyProps) => (
|
||||
<TestProviders>
|
||||
<Body {...props} />
|
||||
</TestProviders>
|
||||
);
|
||||
|
||||
const wrapper = mount(
|
||||
<Proxy
|
||||
addNoteToEvent={dispatchAddNoteToEvent}
|
||||
browserFields={mockBrowserFields}
|
||||
columnHeaders={defaultHeaders}
|
||||
columnRenderers={columnRenderers}
|
||||
data={mockTimelineData}
|
||||
eventIdToNoteIds={{}}
|
||||
height={testBodyHeight}
|
||||
id={'timeline-test'}
|
||||
isLoading={false}
|
||||
getNotesByIds={mockGetNotesByIds}
|
||||
onColumnRemoved={jest.fn()}
|
||||
onColumnResized={jest.fn()}
|
||||
onColumnSorted={jest.fn()}
|
||||
onFilterChange={jest.fn()}
|
||||
onPinEvent={dispatchOnPinEvent}
|
||||
onUnPinEvent={jest.fn()}
|
||||
onUpdateColumns={jest.fn()}
|
||||
pinnedEventIds={{}}
|
||||
range={'1 Day'}
|
||||
rowRenderers={rowRenderers}
|
||||
sort={mockSort}
|
||||
updateNote={jest.fn()}
|
||||
width={100}
|
||||
/>
|
||||
);
|
||||
addaNoteToEvent(wrapper, 'hello world');
|
||||
|
||||
dispatchAddNoteToEvent.mockClear();
|
||||
dispatchOnPinEvent.mockClear();
|
||||
wrapper.setProps({ pinnedEventIds: { 1: true } });
|
||||
wrapper.update();
|
||||
addaNoteToEvent(wrapper, 'new hello world');
|
||||
|
||||
expect(dispatchAddNoteToEvent).toHaveBeenCalled();
|
||||
expect(dispatchOnPinEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ import { Sort } from './sort';
|
|||
import { ColumnRenderer } from './renderers/column_renderer';
|
||||
import { RowRenderer } from './renderers/row_renderer';
|
||||
|
||||
interface Props {
|
||||
export interface BodyProps {
|
||||
addNoteToEvent: AddNoteToEvent;
|
||||
browserFields: BrowserFields;
|
||||
columnHeaders: ColumnHeader[];
|
||||
|
@ -80,7 +80,7 @@ const VerticalScrollContainer = styled.div<{
|
|||
`;
|
||||
|
||||
/** Renders the timeline body */
|
||||
export const Body = pure<Props>(
|
||||
export const Body = pure<BodyProps>(
|
||||
({
|
||||
addNoteToEvent,
|
||||
browserFields,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue