From 91f8d4f6dc84e618fc9aade4a1fd771584ac6248 Mon Sep 17 00:00:00 2001 From: Dmitry Tomashevich <39378793+Dmitriynj@users.noreply.github.com> Date: Fri, 14 Jan 2022 12:14:08 +0300 Subject: [PATCH] [Discover] Fix context view for document ids containing special characters (#122737) * [Discover] fix encoded param for context * [Discover] add functional test * [Discover] add test file * [Discover] change field name Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 6956d9c1fe86745f7c24c807a8198ad3acaedf34) # Conflicts: # src/plugins/discover/public/application/apps/context/context_app_route.tsx --- .../application/apps/context/context_app.tsx | 2 +- .../apps/context/context_app_route.tsx | 6 +- .../discover/_context_encoded_url_param.ts | 55 +++++++++++++++++++ test/functional/apps/discover/index.ts | 1 + 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/functional/apps/discover/_context_encoded_url_param.ts diff --git a/src/plugins/discover/public/application/apps/context/context_app.tsx b/src/plugins/discover/public/application/apps/context/context_app.tsx index 2a0fe3ba2d31..0a46532a2013 100644 --- a/src/plugins/discover/public/application/apps/context/context_app.tsx +++ b/src/plugins/discover/public/application/apps/context/context_app.tsx @@ -152,7 +152,7 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => { - + (); - + const anchorId = decodeURIComponent(id); + useEffect(() => { chrome.setBreadcrumbs([ ...getRootBreadcrumbs(), @@ -73,5 +74,6 @@ export function ContextAppRoute(props: ContextAppProps) { return ; } - return ; + return ; } + diff --git a/test/functional/apps/discover/_context_encoded_url_param.ts b/test/functional/apps/discover/_context_encoded_url_param.ts new file mode 100644 index 000000000000..83ac63afd915 --- /dev/null +++ b/test/functional/apps/discover/_context_encoded_url_param.ts @@ -0,0 +1,55 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const dataGrid = getService('dataGrid'); + const kibanaServer = getService('kibanaServer'); + const PageObjects = getPageObjects(['common', 'discover', 'timePicker', 'settings', 'header']); + const testSubjects = getService('testSubjects'); + const es = getService('es'); + + describe('context encoded id param', () => { + before(async function () { + await PageObjects.common.navigateToApp('settings'); + await es.transport.request({ + path: '/includes-plus-symbol-doc-id/_doc/1+1=2', + method: 'PUT', + body: { + username: 'Dmitry', + '@timestamp': '2015-09-21T09:30:23', + }, + }); + await PageObjects.settings.createIndexPattern('includes-plus-symbol-doc-id'); + + await kibanaServer.uiSettings.update({ 'doc_table:legacy': false }); + await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings(); + await PageObjects.common.navigateToApp('discover'); + }); + + it('should navigate to context page correctly', async () => { + await PageObjects.discover.selectIndexPattern('includes-plus-symbol-doc-id'); + await PageObjects.header.waitUntilLoadingHasFinished(); + + // navigate to the context view + await dataGrid.clickRowToggle({ rowIndex: 0 }); + const [, surroundingActionEl] = await dataGrid.getRowActions({ + isAnchorRow: false, + rowIndex: 0, + }); + await surroundingActionEl.click(); + await PageObjects.header.waitUntilLoadingHasFinished(); + + const headerElement = await testSubjects.find('contextDocumentSurroundingHeader'); + + expect(await headerElement.getVisibleText()).to.be('Documents surrounding #1+1=2'); + }); + }); +} diff --git a/test/functional/apps/discover/index.ts b/test/functional/apps/discover/index.ts index 13658215e9e5..1241b0e892e9 100644 --- a/test/functional/apps/discover/index.ts +++ b/test/functional/apps/discover/index.ts @@ -53,5 +53,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./_date_nested')); loadTestFile(require.resolve('./_search_on_page_load')); loadTestFile(require.resolve('./_chart_hidden')); + loadTestFile(require.resolve('./_context_encoded_url_param')); }); }