Skip to content

Commit

Permalink
[Canvas] Fix expression updating bug (#54297)
Browse files Browse the repository at this point in the history
* Fix expression updating bug

* Add functional test for expression editor

* Add page object helper to open expression editor

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
poffdeluxe and elasticmachine authored Jan 13, 2020
1 parent e54a717 commit 71dfdea
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
11 changes: 11 additions & 0 deletions x-pack/legacy/plugins/canvas/public/components/expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
};

const expressionLifecycle = lifecycle({
componentDidUpdate({ expression }) {
if (
this.props.expression !== expression &&
this.props.expression !== this.props.formState.expression
) {
this.props.setFormState({
expression: this.props.expression,
dirty: false,
});
}
},
componentDidMount() {
const { functionDefinitionsPromise, setFunctionDefinitions } = this.props;
functionDefinitionsPromise.then(defs => setFunctionDefinitions(defs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const Toolbar = (props: Props) => {

const trays = {
pageManager: <PageManager previousPage={previousPage} />,
expression: !elementIsSelected ? null : <Expression key={selectedElement.id} done={done} />,
expression: !elementIsSelected ? null : <Expression done={done} />,
};

return (
Expand Down Expand Up @@ -141,6 +141,7 @@ export const Toolbar = (props: Props) => {
color="text"
iconType="editorCodeBlock"
onClick={() => showHideTray(TrayType.expression)}
data-test-subj="canvasExpressionEditorButton"
>
{strings.getEditorButtonLabel()}
</EuiButtonEmpty>
Expand Down
70 changes: 70 additions & 0 deletions x-pack/test/functional/apps/canvas/expression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';

import { FtrProviderContext } from '../../ftr_provider_context';

export default function canvasExpressionTest({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
// const browser = getService('browser');
const retry = getService('retry');
const PageObjects = getPageObjects(['canvas', 'common']);
const find = getService('find');

describe('expression editor', function() {
// there is an issue with FF not properly clicking on workpad elements
this.tags('skipFirefox');

before(async () => {
// init data
await esArchiver.loadIfNeeded('logstash_functional');
await esArchiver.load('canvas/default');

// load test workpad
await PageObjects.common.navigateToApp('canvas', {
hash: '/workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31/page/1',
});
});

it('updates when element is changed via side bar', async () => {
// wait for all our elements to load up
await retry.try(async () => {
const elements = await testSubjects.findAll(
'canvasWorkpadPage > canvasWorkpadPageElementContent'
);
expect(elements).to.have.length(4);
});

// find the first workpad element (a markdown element) and click it to select it
await testSubjects.click('canvasWorkpadPage > canvasWorkpadPageElementContent', 20000);

// open the expression editor
await PageObjects.canvas.openExpressionEditor();

// select markdown content and clear it
const mdBox = await find.byCssSelector('.canvasSidebar__panel .canvasTextArea__code');
const oldMd = await mdBox.getVisibleText();
await mdBox.clearValueWithKeyboard();

// type the new text
const newMd = `${oldMd} and this is a test`;
await mdBox.type(newMd);
await find.clickByCssSelector('.canvasArg--controls .euiButton');

// make sure the open expression editor also has the changes
const editor = await find.byCssSelector('.monaco-editor .view-lines');
const editorText = await editor.getVisibleText();
expect(editorText).to.contain('Orange: Timelion, Server function and this is a test');

// reset the markdown
await mdBox.clearValueWithKeyboard();
await mdBox.type(oldMd);
await find.clickByCssSelector('.canvasArg--controls .euiButton');
});
});
}
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function canvasApp({ loadTestFile }) {
describe('Canvas app', function canvasAppTestSuite() {
this.tags('ciGroup2'); // CI requires tags ヽ(゜Q。)ノ?
loadTestFile(require.resolve('./smoke_test'));
loadTestFile(require.resolve('./expression'));
loadTestFile(require.resolve('./feature_controls/canvas_security'));
loadTestFile(require.resolve('./feature_controls/canvas_spaces'));
});
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/page_objects/canvas_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function CanvasPageProvider({ getService }: FtrProviderContext) {
await browser.pressKeys(browser.keys.ESCAPE);
},

async openExpressionEditor() {
await testSubjects.click('canvasExpressionEditorButton');
},

async waitForWorkpadElements() {
await testSubjects.findAll('canvasWorkpadPage > canvasWorkpadPageElementContent');
},
Expand Down

0 comments on commit 71dfdea

Please sign in to comment.