Skip to content

Commit

Permalink
updated tests, reverted changes to modals, to make sure they were sti…
Browse files Browse the repository at this point in the history
…ll checking signals index for closing alerts functionality
  • Loading branch information
yctercero committed Jul 20, 2020
1 parent 2861cfa commit 760ed31
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,27 @@ describe('AutocompleteFieldListsComponent', () => {
});

test('it allows user to clear values if "isClearable" is true', async () => {
await act(async () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<AutocompleteFieldListsComponent
placeholder="Placeholder text"
selectedField={getField('ip')}
selectedValue="some-list-id"
isLoading={false}
isClearable={true}
isDisabled={false}
onChange={jest.fn()}
/>
</ThemeProvider>
);
await wait();
expect(
wrapper
.find(`[data-test-subj="comboBoxInput"]`)
.hasClass('euiComboBox__inputWrap-isClearable')
).toBeTruthy();
});
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<AutocompleteFieldListsComponent
placeholder="Placeholder text"
selectedField={getField('ip')}
selectedValue="some-list-id"
isLoading={false}
isClearable={true}
isDisabled={false}
onChange={jest.fn()}
/>
</ThemeProvider>
);
expect(
wrapper
.find(`[data-test-subj="comboBoxInput"]`)
.hasClass('euiComboBox__inputWrap-isClearable')
).toBeTruthy();
});

test('it correctly displays lists that match the selected "keyword" field esType', async () => {
test('it correctly displays lists that match the selected "keyword" field esType', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<AutocompleteFieldListsComponent
Expand All @@ -132,17 +129,16 @@ describe('AutocompleteFieldListsComponent', () => {
</ThemeProvider>
);

await act(async () => {
wrapper.find('[data-test-subj="comboBoxToggleListButton"] button').simulate('click');
});
wrapper.find('[data-test-subj="comboBoxToggleListButton"] button').simulate('click');

expect(
wrapper.find('[data-test-subj="valuesAutocompleteComboBox listsComboxBox"]').at(0).props()
.options
wrapper
.find('EuiComboBox[data-test-subj="valuesAutocompleteComboBox listsComboxBox"]')
.prop('options')
).toEqual([{ label: 'keyword list' }]);
});

test('it correctly displays lists that match the selected "ip" field esType', async () => {
test('it correctly displays lists that match the selected "ip" field esType', () => {
const wrapper = mount(
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>
<AutocompleteFieldListsComponent
Expand All @@ -157,13 +153,12 @@ describe('AutocompleteFieldListsComponent', () => {
</ThemeProvider>
);

await act(async () => {
wrapper.find('[data-test-subj="comboBoxToggleListButton"] button').simulate('click');
});
wrapper.find('[data-test-subj="comboBoxToggleListButton"] button').simulate('click');

expect(
wrapper.find('[data-test-subj="valuesAutocompleteComboBox listsComboxBox"]').at(0).props()
.options
wrapper
.find('EuiComboBox[data-test-subj="valuesAutocompleteComboBox listsComboxBox"]')
.prop('options')
).toEqual([{ label: 'some name' }]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useKibana } from '../../../lib/kibana';
import { ExceptionBuilder } from '../builder';
import { Loader } from '../../loader';
import { useAddOrUpdateException } from '../use_add_exception';
import { useSignalIndex } from '../../../../detections/containers/detection_engine/alerts/use_signal_index';
import { useFetchOrCreateRuleExceptionList } from '../use_fetch_or_create_rule_exception_list';
import { AddExceptionComments } from '../add_exception_comments';
import {
Expand All @@ -44,7 +45,6 @@ import {
getMappedNonEcsValue,
} from '../helpers';
import { useFetchIndexPatterns } from '../../../../detections/containers/detection_engine/rules';
import { useSignalIndex } from '../../../../detections/containers/detection_engine/alerts/use_signal_index';

export interface AddExceptionModalBaseProps {
ruleName: string;
Expand Down Expand Up @@ -108,14 +108,13 @@ export const AddExceptionModal = memo(function AddExceptionModal({
>([]);
const [fetchOrCreateListError, setFetchOrCreateListError] = useState(false);
const { addError, addSuccess } = useAppToasts();

const [{ isLoading: indexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);

const { loading: isSignalIndexLoading, signalIndexName } = useSignalIndex();
const [
{ isLoading: signalIndexPatternLoading, indexPatterns: signalIndexPatterns },
{ isLoading: isSignalIndexPatternLoading, indexPatterns: signalIndexPatterns },
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : []);

const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);

const onError = useCallback(
(error: Error) => {
addError(error, { title: i18n.ADD_EXCEPTION_ERROR });
Expand Down Expand Up @@ -174,7 +173,7 @@ export const AddExceptionModal = memo(function AddExceptionModal({
}, [alertData, exceptionListType, ruleExceptionList, ruleName]);

useEffect(() => {
if (signalIndexPatternLoading === false && isSignalIndexLoading === false) {
if (isSignalIndexPatternLoading === false && isSignalIndexLoading === false) {
setShouldDisableBulkClose(
entryHasListType(exceptionItemsToAdd) ||
entryHasNonEcsType(exceptionItemsToAdd, signalIndexPatterns)
Expand All @@ -183,9 +182,9 @@ export const AddExceptionModal = memo(function AddExceptionModal({
}, [
setShouldDisableBulkClose,
exceptionItemsToAdd,
signalIndexPatternLoading,
signalIndexPatterns,
isSignalIndexPatternLoading,
isSignalIndexLoading,
signalIndexPatterns,
]);

useEffect(() => {
Expand Down Expand Up @@ -265,7 +264,7 @@ export const AddExceptionModal = memo(function AddExceptionModal({
);

return (
<EuiOverlayMask>
<EuiOverlayMask onClick={onCancel}>
<Modal onClose={onCancel} data-test-subj="add-exception-modal">
<ModalHeader>
<EuiModalHeaderTitle>{i18n.ADD_EXCEPTION}</EuiModalHeaderTitle>
Expand All @@ -284,9 +283,9 @@ export const AddExceptionModal = memo(function AddExceptionModal({
)}
{fetchOrCreateListError === false &&
!isSignalIndexLoading &&
!signalIndexPatternLoading &&
!indexPatternLoading &&
!isSignalIndexPatternLoading &&
!isLoadingExceptionList &&
!isIndexPatternLoading &&
ruleExceptionList && (
<>
<ModalBodySection className="builder-section">
Expand All @@ -299,7 +298,6 @@ export const AddExceptionModal = memo(function AddExceptionModal({
listNamespaceType={ruleExceptionList.namespace_type}
ruleName={ruleName}
indexPatterns={indexPatterns}
isLoading={false}
isOrDisabled={false}
isAndDisabled={false}
data-test-subj="alert-exception-builder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { AndOrBadge } from '../../and_or_badge';
import { BuilderButtonOptions } from './builder_button_options';
import { getNewExceptionItem, filterExceptionItems } from '../helpers';
import { ExceptionsBuilderExceptionItem, CreateExceptionListItemBuilderSchema } from '../types';
import { Loader } from '../../loader';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import exceptionableFields from '../exceptionable_fields.json';

Expand Down Expand Up @@ -52,7 +51,6 @@ interface ExceptionBuilderProps {
listNamespaceType: NamespaceType;
ruleName: string;
indexPatterns: IIndexPattern;
isLoading: boolean;
isOrDisabled: boolean;
isAndDisabled: boolean;
onChange: (arg: OnChangeProps) => void;
Expand All @@ -65,7 +63,6 @@ export const ExceptionBuilder = ({
listNamespaceType,
ruleName,
indexPatterns,
isLoading,
isOrDisabled,
isAndDisabled,
onChange,
Expand Down Expand Up @@ -193,9 +190,6 @@ export const ExceptionBuilder = ({

return (
<EuiFlexGroup gutterSize="s" direction="column">
{(isLoading || indexPatterns == null) && (
<Loader data-test-subj="loadingPanelAllRulesTable" overlay size="xl" />
)}
{exceptions.map((exceptionListItem, index) => (
<EuiFlexItem grow={1} key={getExceptionListItemId(exceptionListItem, index)}>
<EuiFlexGroup gutterSize="s" direction="column">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ export const EditExceptionModal = memo(function EditExceptionModal({
Array<ExceptionListItemSchema | CreateExceptionListItemSchema>
>([]);
const { addError, addSuccess } = useAppToasts();
const [{ isLoading: indexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);

const { loading: isSignalIndexLoading, signalIndexName } = useSignalIndex();
const [
{ isLoading: signalIndexPatternLoading, indexPatterns: signalIndexPatterns },
{ isLoading: isSignalIndexPatternLoading, indexPatterns: signalIndexPatterns },
] = useFetchIndexPatterns(signalIndexName !== null ? [signalIndexName] : []);

const [{ isLoading: isIndexPatternLoading, indexPatterns }] = useFetchIndexPatterns(ruleIndices);

const onError = useCallback(
(error) => {
addError(error, { title: i18n.EDIT_EXCEPTION_ERROR });
Expand All @@ -121,7 +121,7 @@ export const EditExceptionModal = memo(function EditExceptionModal({
);

useEffect(() => {
if (signalIndexPatternLoading === false && isSignalIndexLoading === false) {
if (isSignalIndexPatternLoading === false && isSignalIndexLoading === false) {
setShouldDisableBulkClose(
entryHasListType(exceptionItemsToAdd) ||
entryHasNonEcsType(exceptionItemsToAdd, signalIndexPatterns)
Expand All @@ -130,9 +130,9 @@ export const EditExceptionModal = memo(function EditExceptionModal({
}, [
setShouldDisableBulkClose,
exceptionItemsToAdd,
signalIndexPatternLoading,
signalIndexPatterns,
isSignalIndexPatternLoading,
isSignalIndexLoading,
signalIndexPatterns,
]);

useEffect(() => {
Expand Down Expand Up @@ -188,7 +188,7 @@ export const EditExceptionModal = memo(function EditExceptionModal({
}, [addOrUpdateExceptionItems, enrichExceptionItems, shouldBulkCloseAlert, signalIndexName]);

return (
<EuiOverlayMask>
<EuiOverlayMask onClick={onCancel}>
<Modal onClose={onCancel} data-test-subj="add-exception-modal">
<ModalHeader>
<EuiModalHeaderTitle>{i18n.EDIT_EXCEPTION_TITLE}</EuiModalHeaderTitle>
Expand All @@ -197,7 +197,7 @@ export const EditExceptionModal = memo(function EditExceptionModal({
</ModalHeaderSubtitle>
</ModalHeader>

{!indexPatternLoading && !isSignalIndexLoading && !signalIndexPatternLoading && (
{!isSignalIndexLoading && !isIndexPatternLoading && (
<>
<ModalBodySection className="builder-section">
<EuiText>{i18n.EXCEPTION_BUILDER_INFO}</EuiText>
Expand All @@ -208,7 +208,6 @@ export const EditExceptionModal = memo(function EditExceptionModal({
listId={exceptionItem.list_id}
listNamespaceType={exceptionItem.namespace_type}
ruleName={ruleName}
isLoading={false}
isOrDisabled={false}
isAndDisabled={false}
data-test-subj="edit-exception-modal-builder"
Expand Down

0 comments on commit 760ed31

Please sign in to comment.