Skip to content

Commit

Permalink
Unskip legacy editor test (#51907) (#52505)
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens authored Dec 9, 2019
1 parent 54f1b0c commit 282af26
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 84 deletions.
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

0 comments on commit 282af26

Please sign in to comment.