Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiWu committed Apr 26, 2022
1 parent b42c959 commit 10ece1c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
parseDuration,
} from '@kbn/alerting-plugin/common';
import { getFormattedDuration, getFormattedMilliseconds } from '../../../lib/monitoring_utils';
import { getIsExperimentalFeatureEnabled } from '../../../../common/get_experimental_features';

import { useKibana } from '../../../../common/lib/kibana';
jest.mock('../../../../common/lib/kibana');
Expand Down Expand Up @@ -59,6 +60,9 @@ jest.mock('../../../lib/capabilities', () => ({
hasShowActionsCapability: jest.fn(() => true),
hasExecuteActionsCapability: jest.fn(() => true),
}));
jest.mock('../../../../common/get_experimental_features', () => ({
getIsExperimentalFeatureEnabled: jest.fn(),
}));
const { loadRules, loadRuleTypes, loadRuleAggregations } =
jest.requireMock('../../../lib/rule_api');
const { loadActionTypes, loadAllActions } = jest.requireMock('../../../lib/action_connector_api');
Expand Down Expand Up @@ -95,6 +99,10 @@ ruleTypeRegistry.list.mockReturnValue([ruleType]);
actionTypeRegistry.list.mockReturnValue([]);
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;

beforeEach(() => {
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
});

describe('rules_list component empty', () => {
let wrapper: ReactWrapper<any>;
async function setup() {
Expand Down Expand Up @@ -801,6 +809,39 @@ describe('rules_list component with items', () => {
'Warning: 6'
);
});

it('does not render the state filter if the feature flag is off', async () => {
await setup();
expect(wrapper.find('[data-test-subj="ruleStateFilter"]').exists()).toBeFalsy();
});

it('renders the tag filter if the experiment is on', async () => {
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => true);
await setup();
expect(wrapper.find('[data-test-subj="ruleStateFilter"]').exists()).toBeTruthy();
});

it('can filter by rule states', async () => {
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => true);
loadRules.mockReset();
await setup();

expect(loadRules.mock.calls[0][0].ruleStateFilter).toEqual([]);

wrapper.find('[data-test-subj="ruleStateFilterButton"] button').simulate('click');

wrapper.find('[data-test-subj="ruleStateFilterOption-enabled"]').first().simulate('click');

expect(loadRules.mock.calls[1][0].ruleStateFilter).toEqual(['enabled']);

wrapper.find('[data-test-subj="ruleStateFilterOption-snoozed"]').first().simulate('click');

expect(loadRules.mock.calls[2][0].ruleStateFilter).toEqual(['enabled', 'snoozed']);

wrapper.find('[data-test-subj="ruleStateFilterOption-snoozed"]').first().simulate('click');

expect(loadRules.mock.calls[3][0].ruleStateFilter).toEqual(['enabled']);
});
});

describe('rules_list component empty with show only capability', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ export const RulesList: React.FunctionComponent = () => {
isEmpty(typesFilter) &&
isEmpty(actionTypesFilter) &&
isEmpty(ruleStatusesFilter) &&
isRuleStateFilterEnabled &&
isEmpty(ruleStateFilter)
);

Expand Down

0 comments on commit 10ece1c

Please sign in to comment.