[Security Solution] Host isolation exceptions - fixes for QA issues (#116089)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Esteban Beltran 2021-10-28 17:54:17 +02:00 committed by GitHub
parent d4f4e64426
commit ddf092f38c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 17 deletions

View file

@ -48,6 +48,13 @@ export const getListItems: HostIsolationExceptionsSelector<Immutable<ExceptionLi
return apiResponseData?.data || [];
});
export const getTotalListItems: HostIsolationExceptionsSelector<Immutable<number>> = createSelector(
getListApiSuccessResponse,
(apiResponseData) => {
return apiResponseData?.total || 0;
}
);
export const getListPagination: HostIsolationExceptionsSelector<Pagination> = createSelector(
getListApiSuccessResponse,
// memoized via `reselect` until the API response changes

View file

@ -94,10 +94,13 @@ describe('When on the host isolation exceptions page', () => {
expect(renderResult.container.querySelector('.euiProgress')).toBeNull();
});
it('should display the search bar', async () => {
it('should display the search bar and item count', async () => {
render();
await dataReceived();
expect(renderResult.getByTestId('searchExceptions')).toBeTruthy();
expect(renderResult.getByTestId('hostIsolationExceptions-totalCount').textContent).toBe(
'Showing 1 exception'
);
});
it('should show items on the list', async () => {
@ -127,20 +130,22 @@ describe('When on the host isolation exceptions page', () => {
});
describe('is license platinum plus', () => {
beforeEach(() => {
beforeEach(async () => {
isPlatinumPlusMock.mockReturnValue(true);
getHostIsolationExceptionItemsMock.mockImplementation(getFoundExceptionListItemSchemaMock);
});
it('should show the create flyout when the add button is pressed', async () => {
render();
await dataReceived();
act(() => {
userEvent.click(renderResult.getByTestId('hostIsolationExceptionsEmptyStateAddButton'));
userEvent.click(renderResult.getByTestId('hostIsolationExceptionsListAddButton'));
});
expect(renderResult.getByTestId('hostIsolationExceptionsCreateEditFlyout')).toBeTruthy();
});
it('should show the create flyout when the show location is create', () => {
it('should show the create flyout when the show location is create', async () => {
history.push(`${HOST_ISOLATION_EXCEPTIONS_PATH}?show=create`);
render();
await dataReceived();
expect(renderResult.getByTestId('hostIsolationExceptionsCreateEditFlyout')).toBeTruthy();
expect(renderResult.queryByTestId('hostIsolationExceptionsCreateEditFlyout')).toBeTruthy();
});

View file

@ -8,7 +8,7 @@
import { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types';
import { i18n } from '@kbn/i18n';
import React, { Dispatch, useCallback, useEffect } from 'react';
import { EuiButton } from '@elastic/eui';
import { EuiButton, EuiText, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
@ -21,6 +21,7 @@ import {
getListIsLoading,
getListItems,
getListPagination,
getTotalListItems,
} from '../store/selector';
import {
useHostIsolationExceptionsNavigateCallback,
@ -48,6 +49,7 @@ type HostIsolationExceptionPaginatedContent = PaginatedContentProps<
export const HostIsolationExceptionsList = () => {
const listItems = useHostIsolationExceptionsSelector(getListItems);
const totalCountListItems = useHostIsolationExceptionsSelector(getTotalListItems);
const pagination = useHostIsolationExceptionsSelector(getListPagination);
const isLoading = useHostIsolationExceptionsSelector(getListIsLoading);
const fetchError = useHostIsolationExceptionsSelector(getListFetchError);
@ -74,7 +76,7 @@ export const HostIsolationExceptionsList = () => {
function handleItemComponentProps(element: ExceptionListItemSchema): ArtifactEntryCardProps {
const editAction = {
icon: 'trash',
icon: 'controlsHorizontal',
onClick: () => {
navigateCallback({
show: 'edit',
@ -130,8 +132,14 @@ export const HostIsolationExceptionsList = () => {
defaultMessage="Host isolation exceptions"
/>
}
subtitle={
<FormattedMessage
id="xpack.securitySolution.hostIsolationExceptions.list.pageSubTitle"
defaultMessage="Add a Host isolation exception to allow isolated hosts to communicate with specific IPs."
/>
}
actions={
license.isPlatinumPlus() ? (
license.isPlatinumPlus() && listItems.length > 0 ? (
<EuiButton
fill
iconType="plusInCircle"
@ -155,16 +163,27 @@ export const HostIsolationExceptionsList = () => {
{itemToDelete ? <HostIsolationExceptionDeleteModal /> : null}
{!isLoading && listItems.length ? (
<SearchExceptions
defaultValue={location.filter}
onSearch={handleOnSearch}
placeholder={i18n.translate(
'xpack.securitySolution.hostIsolationExceptions.search.placeholder',
{
defaultMessage: 'Search on the fields below: name, description, ip',
}
)}
/>
<>
<SearchExceptions
defaultValue={location.filter}
onSearch={handleOnSearch}
placeholder={i18n.translate(
'xpack.securitySolution.hostIsolationExceptions.search.placeholder',
{
defaultMessage: 'Search on the fields below: name, description, ip',
}
)}
/>
<EuiSpacer size="m" />
<EuiText color="subdued" size="xs" data-test-subj="hostIsolationExceptions-totalCount">
<FormattedMessage
id="xpack.securitySolution.hostIsolationExceptions.list.totalCount"
defaultMessage="Showing {total, plural, one {# exception} other {# exceptions}}"
values={{ total: totalCountListItems }}
/>
</EuiText>
<EuiSpacer size="s" />
</>
) : null}
<PaginatedContent<ExceptionListItemSchema, typeof ArtifactEntryCard>