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

[RAM] Remove errors and warning in triggers_actions_ui jest test #144443

Merged
merged 10 commits into from
Nov 8, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('action_form', () => {
},
actionConnectorFields: null,
actionParamsFields: mockedActionParamsFields,
actionTypeTitle: 'action-type-title',
};

const disabledByConfigActionType = {
Expand Down Expand Up @@ -415,6 +416,11 @@ describe('action_form', () => {
},
]
`);

await act(async () => {
await nextTick();
wrapper.update();
});
});

it('renders disabled action groups for selected action type', async () => {
Expand Down Expand Up @@ -449,6 +455,10 @@ describe('action_form', () => {
},
]
`);
await act(async () => {
await nextTick();
wrapper.update();
});
});

it('renders disabled action groups for custom recovered action groups', async () => {
Expand Down Expand Up @@ -486,6 +496,10 @@ describe('action_form', () => {
},
]
`);
await act(async () => {
await nextTick();
wrapper.update();
});
});

it('renders available connectors for the selected action type', async () => {
Expand Down Expand Up @@ -528,6 +542,10 @@ describe('action_form', () => {
},
]
`);
await act(async () => {
await nextTick();
wrapper.update();
});
});

it('renders only preconfigured connectors for the selected preconfigured action type', async () => {
Expand All @@ -551,6 +569,10 @@ describe('action_form', () => {
},
]
`);
await act(async () => {
await nextTick();
wrapper.update();
});
});

it('does not render "Add connector" button for preconfigured only action type', async () => {
Expand All @@ -564,6 +586,10 @@ describe('action_form', () => {
'[data-test-subj="addNewActionConnectorButton-preconfigured"]'
);
expect(addNewConnectorButton.exists()).toBeFalsy();
await act(async () => {
await nextTick();
wrapper.update();
});
});

it('renders action types disabled by license', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
const ruleTypeRegistry = ruleTypeRegistryMock.create();

import { getIsExperimentalFeatureEnabled } from '../../../../common/get_experimental_features';
import { waitFor } from '@testing-library/react';

const fakeNow = new Date('2020-02-09T23:15:41.941Z');
const fake2MinutesAgo = new Date('2020-02-09T23:13:41.941Z');
Expand Down Expand Up @@ -348,7 +349,7 @@ describe('execution duration overview', () => {
});

describe('disable/enable functionality', () => {
it('should show that the rule is enabled', () => {
it('should show that the rule is enabled', async () => {
const rule = mockRule();
const ruleType = mockRuleType();
const ruleSummary = mockRuleSummary();
Expand All @@ -361,7 +362,9 @@ describe('disable/enable functionality', () => {
readOnly={false}
/>
);
const actionsElem = wrapper.find('[data-test-subj="statusDropdown"]').first();
const actionsElem = await waitFor(() =>
wrapper.find('[data-test-subj="statusDropdown"]').first()
);

expect(actionsElem.text()).toEqual('Enabled');
});
Expand All @@ -381,7 +384,9 @@ describe('disable/enable functionality', () => {
readOnly={false}
/>
);
const actionsElem = wrapper.find('[data-test-subj="statusDropdown"]').first();
const actionsElem = await waitFor(() =>
wrapper.find('[data-test-subj="statusDropdown"]').first()
);

expect(actionsElem.text()).toEqual('Disabled');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,38 @@
* 2.0.
*/

import React, { useEffect, useState, useCallback } from 'react';
import React, { useState, useCallback } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiPopover, EuiFilterButton, EuiFilterSelectItem } from '@elastic/eui';
import { ActionType } from '../../../../types';

interface ActionTypeFilterProps {
actionTypes: ActionType[];
onChange?: (selectedActionTypeIds: string[]) => void;
filters: string[];
}

export const ActionTypeFilter: React.FunctionComponent<ActionTypeFilterProps> = ({
actionTypes,
onChange,
onChange: onFilterChange,
filters,
}: ActionTypeFilterProps) => {
const [selectedValues, setSelectedValues] = useState<string[]>([]);
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);

useEffect(() => {
Copy link
Contributor Author

@jcger jcger Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was causing rerenders that also caused duplicated calls to the api. Having the bug duplicated in another component meant to be calling the api 4 times

if (onChange) {
onChange(selectedValues);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedValues]);

const onClick = useCallback(
(item: ActionType) => {
return () => {
const isPreviouslyChecked = selectedValues.includes(item.id);
if (!onFilterChange) return;
jcger marked this conversation as resolved.
Show resolved Hide resolved

const isPreviouslyChecked = filters.includes(item.id);
if (isPreviouslyChecked) {
setSelectedValues(selectedValues.filter((val) => val !== item.id));
onFilterChange(filters.filter((val) => val !== item.id));
} else {
setSelectedValues(selectedValues.concat(item.id));
onFilterChange(filters.concat(item.id));
}
};
},
[selectedValues, setSelectedValues]
[filters, onFilterChange]
);

return (
Expand All @@ -50,9 +46,9 @@ export const ActionTypeFilter: React.FunctionComponent<ActionTypeFilterProps> =
button={
<EuiFilterButton
iconType="arrowDown"
hasActiveFilters={selectedValues.length > 0}
numActiveFilters={selectedValues.length}
numFilters={selectedValues.length}
hasActiveFilters={filters.length > 0}
numActiveFilters={filters.length}
numFilters={filters.length}
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
data-test-subj="actionTypeFilterButton"
>
Expand All @@ -68,7 +64,7 @@ export const ActionTypeFilter: React.FunctionComponent<ActionTypeFilterProps> =
<EuiFilterSelectItem
key={item.id}
onClick={onClick(item)}
checked={selectedValues.includes(item.id) ? 'on' : undefined}
checked={filters.includes(item.id) ? 'on' : undefined}
data-test-subj={`actionType${item.id}FilterOption`}
>
{item.name}
Expand Down
Loading