filters are back (#54218)
This commit is contained in:
parent
fdea7b048d
commit
6abfbd1382
|
@ -11,14 +11,18 @@ import { Router } from 'react-router-dom';
|
|||
import { MockedProvider } from 'react-apollo/test-utils';
|
||||
import { ActionCreator } from 'typescript-fsa';
|
||||
|
||||
import { esFilters } from '../../../../../../../src/plugins/data/common/es_query';
|
||||
import '../../mock/match_media';
|
||||
import { mocksSource } from '../../containers/source/mock';
|
||||
import { wait } from '../../lib/helpers';
|
||||
import { TestProviders } from '../../mock';
|
||||
import { apolloClientObservable, TestProviders, mockGlobalState } from '../../mock';
|
||||
import { InputsModelId } from '../../store/inputs/constants';
|
||||
import { SiemNavigation } from '../../components/navigation';
|
||||
import { inputsActions } from '../../store/inputs';
|
||||
import { State, createStore } from '../../store';
|
||||
import { HostsComponentProps } from './types';
|
||||
import { Hosts } from './hosts';
|
||||
import { HostsTabs } from './hosts_tabs';
|
||||
|
||||
// Test will fail because we will to need to mock some core services to make the test work
|
||||
// For now let's forget about SiemSearchBar and QueryBar
|
||||
|
@ -136,4 +140,58 @@ describe('Hosts - rendering', () => {
|
|||
wrapper.update();
|
||||
expect(wrapper.find(SiemNavigation).exists()).toBe(true);
|
||||
});
|
||||
|
||||
test('it should add the new filters after init', async () => {
|
||||
const newFilters: esFilters.Filter[] = [
|
||||
{
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{
|
||||
bool: {
|
||||
should: [
|
||||
{
|
||||
match_phrase: {
|
||||
'host.name': 'ItRocks',
|
||||
},
|
||||
},
|
||||
],
|
||||
minimum_should_match: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
meta: {
|
||||
alias: '',
|
||||
disabled: false,
|
||||
key: 'bool',
|
||||
negate: false,
|
||||
type: 'custom',
|
||||
value:
|
||||
'{"query": {"bool": {"filter": [{"bool": {"should": [{"match_phrase": {"host.name": "ItRocks"}}],"minimum_should_match": 1}}]}}}',
|
||||
},
|
||||
},
|
||||
];
|
||||
localSource[0].result.data.source.status.indicesExist = true;
|
||||
const myState: State = mockGlobalState;
|
||||
const myStore = createStore(myState, apolloClientObservable);
|
||||
const wrapper = mount(
|
||||
<TestProviders store={myStore}>
|
||||
<MockedProvider mocks={localSource} addTypename={false}>
|
||||
<Router history={mockHistory}>
|
||||
<Hosts {...hostProps} />
|
||||
</Router>
|
||||
</MockedProvider>
|
||||
</TestProviders>
|
||||
);
|
||||
await wait();
|
||||
wrapper.update();
|
||||
|
||||
myStore.dispatch(inputsActions.setSearchBarFilter({ id: 'global', filters: newFilters }));
|
||||
wrapper.update();
|
||||
expect(wrapper.find(HostsTabs).props().filterQuery).toEqual(
|
||||
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"filter":[{"bool":{"should":[{"match_phrase":{"host.name":"ItRocks"}}],"minimum_should_match":1}}]}}],"should":[],"must_not":[]}}'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -41,7 +41,7 @@ import { HostsTableType } from '../../store/hosts/model';
|
|||
|
||||
const KpiHostsComponentManage = manageQuery(KpiHostsComponent);
|
||||
|
||||
const HostsComponent = React.memo<HostsComponentProps>(
|
||||
export const HostsComponent = React.memo<HostsComponentProps>(
|
||||
({
|
||||
deleteQuery,
|
||||
isInitializing,
|
||||
|
@ -56,13 +56,12 @@ const HostsComponent = React.memo<HostsComponentProps>(
|
|||
const capabilities = React.useContext(MlCapabilitiesContext);
|
||||
const kibana = useKibana();
|
||||
const { tabName } = useParams();
|
||||
|
||||
const hostsFilters = React.useMemo(() => {
|
||||
if (tabName === HostsTableType.alerts) {
|
||||
return filters.length > 0 ? [...filters, ...filterAlertsHosts] : filterAlertsHosts;
|
||||
}
|
||||
return filters;
|
||||
}, [tabName]);
|
||||
}, [tabName, filters]);
|
||||
const narrowDateRange = useCallback(
|
||||
(min: number, max: number) => {
|
||||
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
|
||||
|
|
|
@ -11,10 +11,13 @@ import { Router } from 'react-router-dom';
|
|||
import { MockedProvider } from 'react-apollo/test-utils';
|
||||
|
||||
import '../../mock/match_media';
|
||||
|
||||
import { esFilters } from '../../../../../../../src/plugins/data/common/es_query';
|
||||
import { mocksSource } from '../../containers/source/mock';
|
||||
import { TestProviders } from '../../mock';
|
||||
import { TestProviders, mockGlobalState, apolloClientObservable } from '../../mock';
|
||||
import { State, createStore } from '../../store';
|
||||
import { inputsActions } from '../../store/inputs';
|
||||
import { Network } from './network';
|
||||
import { NetworkRoutes } from './navigation';
|
||||
|
||||
// Test will fail because we will to need to mock some core services to make the test work
|
||||
// For now let's forget about SiemSearchBar and QueryBar
|
||||
|
@ -111,4 +114,58 @@ describe('rendering - rendering', () => {
|
|||
wrapper.update();
|
||||
expect(wrapper.find('[data-test-subj="empty-page"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
test('it should add the new filters after init', async () => {
|
||||
const newFilters: esFilters.Filter[] = [
|
||||
{
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{
|
||||
bool: {
|
||||
should: [
|
||||
{
|
||||
match_phrase: {
|
||||
'host.name': 'ItRocks',
|
||||
},
|
||||
},
|
||||
],
|
||||
minimum_should_match: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
meta: {
|
||||
alias: '',
|
||||
disabled: false,
|
||||
key: 'bool',
|
||||
negate: false,
|
||||
type: 'custom',
|
||||
value:
|
||||
'{"query": {"bool": {"filter": [{"bool": {"should": [{"match_phrase": {"host.name": "ItRocks"}}],"minimum_should_match": 1}}]}}}',
|
||||
},
|
||||
},
|
||||
];
|
||||
localSource[0].result.data.source.status.indicesExist = true;
|
||||
const myState: State = mockGlobalState;
|
||||
const myStore = createStore(myState, apolloClientObservable);
|
||||
const wrapper = mount(
|
||||
<TestProviders store={myStore}>
|
||||
<MockedProvider mocks={localSource} addTypename={false}>
|
||||
<Router history={mockHistory}>
|
||||
<Network {...getMockProps()} />
|
||||
</Router>
|
||||
</MockedProvider>
|
||||
</TestProviders>
|
||||
);
|
||||
await new Promise(resolve => setTimeout(resolve));
|
||||
wrapper.update();
|
||||
|
||||
myStore.dispatch(inputsActions.setSearchBarFilter({ id: 'global', filters: newFilters }));
|
||||
wrapper.update();
|
||||
expect(wrapper.find(NetworkRoutes).props().filterQuery).toEqual(
|
||||
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"filter":[{"bool":{"should":[{"match_phrase":{"host.name":"ItRocks"}}],"minimum_should_match":1}}]}}],"should":[],"must_not":[]}}'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -59,7 +59,8 @@ const NetworkComponent = React.memo<NetworkComponentProps>(
|
|||
return filters.length > 0 ? [...filters, ...filterAlertsNetwork] : filterAlertsNetwork;
|
||||
}
|
||||
return filters;
|
||||
}, [tabName]);
|
||||
}, [tabName, filters]);
|
||||
|
||||
const narrowDateRange = useCallback(
|
||||
(min: number, max: number) => {
|
||||
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
|
||||
|
|
Loading…
Reference in a new issue