Skip to content

Commit

Permalink
[Cases] Fixes configuration page flaky tests (elastic#118521) (elasti…
Browse files Browse the repository at this point in the history
…c#118676)

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
  • Loading branch information
kibanamachine and cnasikas authored Nov 16, 2021
1 parent 0365722 commit ea9ce6e
Showing 1 changed file with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ const useConnectorsMock = useConnectors as jest.Mock;
const useCaseConfigureMock = useCaseConfigure as jest.Mock;
const useGetUrlSearchMock = jest.fn();
const useActionTypesMock = useActionTypes as jest.Mock;
const getAddConnectorFlyoutMock = jest.fn();
const getEditConnectorFlyoutMock = jest.fn();

describe('ConfigureCases', () => {
beforeAll(() => {
useKibanaMock().services.triggersActionsUi.actionTypeRegistry.get = jest.fn().mockReturnValue({
actionTypeTitle: '.servicenow',
iconClass: 'logoSecurity',
});

useKibanaMock().services.triggersActionsUi.getAddConnectorFlyout =
getAddConnectorFlyoutMock.mockReturnValue(<div data-test-subj="add-connector-flyout" />);

useKibanaMock().services.triggersActionsUi.getEditConnectorFlyout =
getEditConnectorFlyoutMock.mockReturnValue(<div data-test-subj="edit-connector-flyout" />);
});

beforeEach(() => {
Expand All @@ -72,12 +80,12 @@ describe('ConfigureCases', () => {
expect(wrapper.find('[data-test-subj="closure-options-radio-group"]').exists()).toBeTruthy();
});

test('it does NOT render the ConnectorAddFlyout', () => {
expect(wrapper.find('ConnectorAddFlyout').exists()).toBeFalsy();
test('it does NOT render the add connector flyout', () => {
expect(wrapper.find('[data-test-subj="add-connector-flyout"]').exists()).toBeFalsy();
});

test('it does NOT render the ConnectorEditFlyout', () => {
expect(wrapper.find('ConnectorEditFlyout').exists()).toBeFalsy();
test('it does NOT render the edit connector flyout"]', () => {
expect(wrapper.find('[data-test-subj="edit-connector-flyout"]').exists()).toBeFalsy();
});

test('it does NOT render the EuiCallOut', () => {
Expand Down Expand Up @@ -176,8 +184,8 @@ describe('ConfigureCases', () => {
expect(wrapper.find(ClosureOptions).prop('closureTypeSelected')).toBe('close-by-user');

// Flyouts
expect(wrapper.find('ConnectorAddFlyout').exists()).toBe(false);
expect(wrapper.find('ConnectorEditFlyout').exists()).toBe(false);
expect(wrapper.find('[data-test-subj="add-connector-flyout"]').exists()).toBe(false);
expect(wrapper.find('[data-test-subj="edit-connector-flyout"]').exists()).toBe(false);
});

test('it disables correctly when the user cannot crud', () => {
Expand Down Expand Up @@ -541,21 +549,25 @@ describe('ConfigureCases', () => {

await waitFor(() => {
wrapper.update();
expect(wrapper.find('ConnectorAddFlyout').exists()).toBe(true);
expect(wrapper.find('ConnectorAddFlyout').prop('actionTypes')).toEqual([
expect.objectContaining({
id: '.servicenow',
}),
expect.objectContaining({
id: '.jira',
}),
expect.objectContaining({
id: '.resilient',
}),
expect(wrapper.find('[data-test-subj="add-connector-flyout"]').exists()).toBe(true);
expect(getAddConnectorFlyoutMock).toHaveBeenCalledWith(
expect.objectContaining({
id: '.servicenow-sir',
}),
]);
actionTypes: [
expect.objectContaining({
id: '.servicenow',
}),
expect.objectContaining({
id: '.jira',
}),
expect.objectContaining({
id: '.resilient',
}),
expect.objectContaining({
id: '.servicenow-sir',
}),
],
})
);
});
});

Expand Down Expand Up @@ -588,8 +600,10 @@ describe('ConfigureCases', () => {

await waitFor(() => {
wrapper.update();
expect(wrapper.find('ConnectorEditFlyout').exists()).toBe(true);
expect(wrapper.find('ConnectorEditFlyout').prop('initialConnector')).toEqual(connectors[1]);
expect(wrapper.find('[data-test-subj="edit-connector-flyout"]').exists()).toBe(true);
expect(getEditConnectorFlyoutMock).toHaveBeenCalledWith(
expect.objectContaining({ initialConnector: connectors[1] })
);
});

expect(
Expand Down

0 comments on commit ea9ce6e

Please sign in to comment.