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

[Console] Unskip legacy editor test #51907

Merged
merged 2 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

jest.mock('../../../../contexts/editor_context/editor_registry.ts', () => ({
instance: {
setInputEditor: () => {},
getInputEditor: () => ({
getRequestsInRange: (cb: any) => cb([{ test: 'test' }]),
}),
},
}));
jest.mock('../../../../components/editor_example.tsx', () => {});
jest.mock('../../../../../../../public/quarantined/src/mappings.js', () => ({
retrieveAutoCompleteInfo: () => {},
clearSubscriptions: () => {},
}));
jest.mock('../../../../../../../public/quarantined/src/input.ts', () => {
return {
initializeEditor: () => ({
$el: {
css: () => {},
},
focus: () => {},
update: () => {},
getSession: () => ({ on: () => {}, setUseWrapMode: () => {} }),
commands: {
addCommand: () => {},
},
}),
};
});

jest.mock('../../../../hooks/use_send_current_request_to_es/send_request_to_es', () => ({
sendRequestToES: jest.fn(),
}));
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,33 @@
* under the License.
*/

import './editor.test.mock';

import React from 'react';
import { ReactWrapper, mount } from 'enzyme';
import { mount } from 'enzyme';
import { I18nProvider } from '@kbn/i18n/react';
import { act } from 'react-dom/test-utils';
import * as sinon from 'sinon';

import { notificationServiceMock } from '../../../../../../../../../../../src/core/public/mocks';

import { nextTick } from 'test_utils/enzyme_helpers';
import {
ServicesContextProvider,
EditorContextProvider,
RequestContextProvider,
} from '../../../../contexts';

import { Editor } from './editor';

jest.mock('../../../../contexts/editor_context/editor_registry.ts', () => ({
instance: {
setInputEditor: () => {},
getInputEditor: () => ({
getRequestsInRange: (cb: any) => cb([{ test: 'test' }]),
}),
},
}));
jest.mock('../../../../components/editor_example.tsx', () => {});
jest.mock('../../../../../../../public/quarantined/src/mappings.js', () => ({
retrieveAutoCompleteInfo: () => {},
clearSubscriptions: () => {},
}));
jest.mock('../../../../../../../public/quarantined/src/input.ts', () => {
return {
initializeEditor: () => ({
$el: {
css: () => {},
},
focus: () => {},
update: () => {},
getSession: () => ({ on: () => {}, setUseWrapMode: () => {} }),
commands: {
addCommand: () => {},
},
}),
};
});

import * as sendRequestModule from '../../../../hooks/use_send_current_request_to_es/send_request_to_es';
import { sendRequestToES } from '../../../../hooks/use_send_current_request_to_es/send_request_to_es';
import * as consoleMenuActions from '../console_menu_actions';
import { Editor } from './editor';

describe('Legacy (Ace) Console Editor Component Smoke Test', () => {
let mockedAppContextValue: any;
let editor: ReactWrapper;
const sandbox = sinon.createSandbox();

beforeEach(() => {
document.queryCommandSupported = sinon.fake(() => true);
mockedAppContextValue = {
services: {
history: {
getSavedEditorState: () => null,
updateCurrentState: () => {},
},
},
docLinkVersion: 'NA',
};
editor = mount(
const doMount = () =>
mount(
<I18nProvider>
<ServicesContextProvider value={mockedAppContextValue}>
<RequestContextProvider>
Expand All @@ -89,51 +54,56 @@ describe('Legacy (Ace) Console Editor Component Smoke Test', () => {
</ServicesContextProvider>
</I18nProvider>
);

beforeEach(() => {
document.queryCommandSupported = sinon.fake(() => true);
mockedAppContextValue = {
services: {
history: {
getSavedEditorState: () => null,
updateCurrentState: jest.fn(),
},
notifications: notificationServiceMock.createSetupContract(),
},
docLinkVersion: 'NA',
};
});

afterEach(() => {
sandbox.restore();
});

// TODO: Re-enable when React ^16.9 is available
it.skip('calls send current request to ES', () => {
const stub = sinon.stub(sendRequestModule, 'sendRequestToES');
try {
act(() => {
editor.find('[data-test-subj~="sendRequestButton"]').simulate('click');
});
expect(stub.called).toBe(true);
expect(stub.callCount).toBe(1);
} finally {
stub.restore();
}
it('calls send current request to ES', async () => {
(sendRequestToES as jest.Mock).mockRejectedValue({});
const editor = doMount();
act(() => {
editor.find('[data-test-subj~="sendRequestButton"]').simulate('click');
});
await nextTick();
expect(sendRequestToES).toBeCalledTimes(1);
});

it('opens docs', () => {
const stub = sinon.stub(consoleMenuActions, 'getDocumentation');
try {
const consoleMenuToggle = editor.find('[data-test-subj~="toggleConsoleMenu"]').last();
consoleMenuToggle.simulate('click');

const docsButton = editor.find('[data-test-subj~="consoleMenuOpenDocs"]').last();
docsButton.simulate('click');

expect(stub.called).toBe(true);
expect(stub.callCount).toBe(1);
} finally {
stub.restore();
}
const stub = sandbox.stub(consoleMenuActions, 'getDocumentation');
const editor = doMount();
const consoleMenuToggle = editor.find('[data-test-subj~="toggleConsoleMenu"]').last();
consoleMenuToggle.simulate('click');

const docsButton = editor.find('[data-test-subj~="consoleMenuOpenDocs"]').last();
docsButton.simulate('click');

expect(stub.callCount).toBe(1);
});

it('prompts auto-indent', () => {
const stub = sinon.stub(consoleMenuActions, 'autoIndent');
try {
const consoleMenuToggle = editor.find('[data-test-subj~="toggleConsoleMenu"]').last();
consoleMenuToggle.simulate('click');

const autoIndentButton = editor.find('[data-test-subj~="consoleMenuAutoIndent"]').last();
autoIndentButton.simulate('click');

expect(stub.called).toBe(true);
expect(stub.callCount).toBe(1);
} finally {
stub.restore();
}
const stub = sandbox.stub(consoleMenuActions, 'autoIndent');
const editor = doMount();
const consoleMenuToggle = editor.find('[data-test-subj~="toggleConsoleMenu"]').last();
consoleMenuToggle.simulate('click');

const autoIndentButton = editor.find('[data-test-subj~="consoleMenuAutoIndent"]').last();
autoIndentButton.simulate('click');

expect(stub.callCount).toBe(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const useSendCurrentRequestToES = () => {
});
return;
}

const results = await sendRequestToES({
requests,
});
Expand Down