Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CTI] Filters alerts table by presence of threat (elastic/security-team#907) #96096

Merged
merged 12 commits into from
Apr 12, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ describe('AlertsUtilityBar', () => {
test('renders correctly', () => {
const wrapper = shallow(
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
rylnd marked this conversation as resolved.
Show resolved Hide resolved
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
onShowBuildingBlockAlertsChanged={jest.fn()}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
);
Expand All @@ -41,17 +43,19 @@ describe('AlertsUtilityBar', () => {
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false} // Does not show showBuildingBlockAlerts checked if this is false
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
Expand All @@ -72,22 +76,61 @@ describe('AlertsUtilityBar', () => {
).toEqual(false);
});

test('does not show the showOnlyThreatIndicatorAlerts checked if the showThreatMatchOnly is false', () => {
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false} // Does not show showBuildingBlockAlerts checked if this is false
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should be false
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(false);
});

test('does show the showBuildingBlockAlerts checked if the showBuildingBlockAlerts is true', () => {
const onShowBuildingBlockAlertsChanged = jest.fn();
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={true} // Does show showBuildingBlockAlerts checked if this is true
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
Expand All @@ -108,22 +151,61 @@ describe('AlertsUtilityBar', () => {
).toEqual(true);
});

test('does show the showOnlyThreatIndicatorAlerts checked if the showOnlyThreatIndicatorAlerts is true', () => {
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={true} // Does show showBuildingBlockAlerts checked if this is true
showClearSelection={true}
showOnlyThreatIndicatorAlerts={true}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should be true
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(true);
});

test('calls the onShowBuildingBlockAlertsChanged when the check box is clicked', () => {
const onShowBuildingBlockAlertsChanged = jest.fn();
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
Expand All @@ -145,39 +227,82 @@ describe('AlertsUtilityBar', () => {
expect(onShowBuildingBlockAlertsChanged).toHaveBeenCalled();
});

test('calls the onShowOnlyThreatIndicatorAlertsChanged when the check box is clicked', () => {
const onShowOnlyThreatIndicatorAlertsChanged = jest.fn();
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={onShowOnlyThreatIndicatorAlertsChanged}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// check the box
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.simulate('change', { target: { checked: true } });

// Make sure our callback is called
expect(onShowOnlyThreatIndicatorAlertsChanged).toHaveBeenCalled();
});

test('can update showBuildingBlockAlerts from false to true', () => {
const Proxy = (props: AlertsUtilityBarProps) => (
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={props.showBuildingBlockAlerts}
onShowBuildingBlockAlertsChanged={jest.fn()}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);

const wrapper = mount(
<Proxy
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
onShowBuildingBlockAlertsChanged={jest.fn()}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
);
Expand Down Expand Up @@ -214,5 +339,79 @@ describe('AlertsUtilityBar', () => {
.prop('checked')
).toEqual(true);
});

test('can update showOnlyThreatIndicatorAlerts from false to true', () => {
const Proxy = (props: AlertsUtilityBarProps) => (
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={props.showOnlyThreatIndicatorAlerts}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);

const wrapper = mount(
<Proxy
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should false now since we initially set the showBuildingBlockAlerts to false
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(false);

wrapper.setProps({ showOnlyThreatIndicatorAlerts: true });
wrapper.update();

// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should be true now since we changed the showBuildingBlockAlerts from false to true
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(true);
});
});
});
Loading