[RAM] Reactivate most tests in triggers_actions_ui (#147535)

## Summary

Reactivating triggers_actions_ui tests.

Rules list tests will remain skipped until we finish its refactor in
https://github.com/elastic/kibana/pull/147014
@cnasikas will take care of this one
`x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/connector_form.test.tsx`

Co-authored-by: Xavier Mouligneau <xavier.mouligneau@elastic.co>
This commit is contained in:
Julian Gernun 2022-12-14 20:58:12 +01:00 committed by GitHub
parent c04f154df7
commit 058a3dafbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 26 deletions

View file

@ -1,5 +1,4 @@
[
"x-pack/plugins/triggers_actions_ui/jest.config.js",
"x-pack/plugins/watcher/jest.config.js",
"src/core/server/integration_tests/ui_settings/jest.integration.config.js"
]

View file

@ -6,17 +6,30 @@
*/
import * as React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { RouteComponentProps, Router } from 'react-router-dom';
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
import { createMemoryHistory, createLocation } from 'history';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import TriggersActionsUIHome, { MatchParams } from './home';
import { hasShowActionsCapability } from './lib/capabilities';
import { useKibana } from '../common/lib/kibana';
import { getIsExperimentalFeatureEnabled } from '../common/get_experimental_features';
jest.mock('../common/lib/kibana');
jest.mock('../common/get_experimental_features');
jest.mock('./lib/capabilities');
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
jest.mock('./sections/rules_list/components/rules_list', () => {
return () => <div data-test-subj="rulesListComponents">{'Render Rule list component'}</div>;
});
jest.mock('./components/health_check', () => ({
HealthCheck: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
jest.mock('./context/health_context', () => ({
HealthContextProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
describe('home', () => {
beforeEach(() => {
@ -24,10 +37,12 @@ describe('home', () => {
(getIsExperimentalFeatureEnabled as jest.Mock).mockClear();
});
it('renders the documentation link', async () => {
it('renders rule list components', async () => {
const props: RouteComponentProps<MatchParams> = {
history: createMemoryHistory(),
location: createLocation('/'),
history: createMemoryHistory({
initialEntries: ['/rules'],
}),
location: createLocation('/rules'),
match: {
isExact: true,
path: `/rules`,
@ -38,16 +53,17 @@ describe('home', () => {
},
};
const wrapper = mountWithIntl(
<Router history={useKibanaMock().services.history}>
<TriggersActionsUIHome {...props} />
</Router>
);
const documentationLink = wrapper.find('[data-test-subj="documentationLink"]');
expect(documentationLink.exists()).toBeTruthy();
expect(documentationLink.first().prop('href')).toEqual(
'https://www.elastic.co/guide/en/kibana/mocked-test-branch/create-and-manage-rules.html'
render(
<IntlProvider locale="en">
<Router history={props.history}>
<TriggersActionsUIHome {...props} />
</Router>
</IntlProvider>
);
await waitFor(() => {
expect(screen.getByTestId('rulesListComponents')).toBeInTheDocument();
});
});
it('hides the internal alerts table route if the config is not set', async () => {
@ -67,7 +83,11 @@ describe('home', () => {
},
};
let home = mountWithIntl(<TriggersActionsUIHome {...props} />);
let home = mountWithIntl(
<Router history={props.history}>
<TriggersActionsUIHome {...props} />
</Router>
);
// Just rules/logs
expect(home.find('span.euiTab__content').length).toBe(2);
@ -79,7 +99,11 @@ describe('home', () => {
return false;
});
home = mountWithIntl(<TriggersActionsUIHome {...props} />);
home = mountWithIntl(
<Router history={props.history}>
<TriggersActionsUIHome {...props} />
</Router>
);
// alerts now too!
expect(home.find('span.euiTab__content').length).toBe(3);
});

View file

@ -87,7 +87,7 @@ describe('ConnectorForm', () => {
});
});
it('calls onChange when the form is invalid', async () => {
it.skip('calls onChange when the form is invalid', async () => {
const actionTypeModel = actionTypeRegistryMock.createMockActionTypeModel({
actionConnectorFields: lazy(() => import('./connector_mock')),
});

View file

@ -756,7 +756,7 @@ describe('rule_details', () => {
disableButton.simulate('click');
expect(mockRuleApis.bulkDisableRules).toHaveBeenCalledTimes(1);
expect(mockRuleApis.bulkDisableRules).toHaveBeenCalledWith(rule);
expect(mockRuleApis.bulkDisableRules).toHaveBeenCalledWith({ ids: [rule.id] });
});
it('should enable the rule when clicked', async () => {
@ -785,7 +785,7 @@ describe('rule_details', () => {
enableButton.simulate('click');
expect(mockRuleApis.bulkEnableRules).toHaveBeenCalledTimes(1);
expect(mockRuleApis.bulkEnableRules).toHaveBeenCalledWith(rule);
expect(mockRuleApis.bulkEnableRules).toHaveBeenCalledWith({ ids: [rule.id] });
});
});

View file

@ -261,7 +261,7 @@ describe.skip('rules_list component empty', () => {
});
});
describe('rules_list component with props', () => {
describe.skip('rules_list component with props', () => {
describe('Status filter', () => {
let wrapper: ReactWrapper<any>;
async function setup(editable: boolean = true) {
@ -860,7 +860,7 @@ describe('rules_list component with props', () => {
});
});
describe('rules_list component with items', () => {
describe.skip('rules_list component with items', () => {
let wrapper: ReactWrapper<any>;
async function setup(editable: boolean = true) {
@ -1440,7 +1440,7 @@ describe('rules_list component with items', () => {
});
});
describe('rules_list component empty with show only capability', () => {
describe.skip('rules_list component empty with show only capability', () => {
let wrapper: ReactWrapper<any>;
async function setup() {
@ -1483,7 +1483,7 @@ describe('rules_list component empty with show only capability', () => {
});
});
describe('rules_list with show only capability', () => {
describe.skip('rules_list with show only capability', () => {
let wrapper: ReactWrapper<any>;
async function setup(editable: boolean = true) {
@ -1604,7 +1604,7 @@ describe('rules_list with show only capability', () => {
});
});
describe('rules_list with disabled items', () => {
describe.skip('rules_list with disabled items', () => {
let wrapper: ReactWrapper<any>;
async function setup() {

View file

@ -93,7 +93,7 @@ beforeEach(() => {
(getIsExperimentalFeatureEnabled as jest.Mock<any, any>).mockImplementation(() => false);
});
describe('Rules list bulk actions', () => {
describe.skip('Rules list bulk actions', () => {
let wrapper: ReactWrapper<any>;
async function setup(authorized: boolean = true) {