forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Search] Set up Curations routes & complete 'Edit Query' action i…
…n Analytics tables (elastic#91052) (elastic#91528) * Set up Curations routes * Update EngineRouter/Nav with Curations * Set up Curations find_or_create API * [bug] Fix view action not working correctly for "" query * Add Edit query action - to call find_or_create curation API & navigate to curation page + fix copy string, only just noticed this :doh: * Add/update unit tests for action column - Refactor out into a single shared test helper file that both AnalyticsTable and RecentQueriesTable simply calls & runs (instead of copying and pasting the same tests twice into 2 diff files) - note: test file can't be `.test.tsx` or Jest tries to automatically run it, which we don't want Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Constance <constancecchen@users.noreply.github.com>
- Loading branch information
1 parent
04eca96
commit 944476b
Showing
14 changed files
with
297 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...ions/app_search/components/analytics/components/analytics_tables/shared_columns_tests.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
mockHttpValues, | ||
mockKibanaValues, | ||
mockFlashMessageHelpers, | ||
} from '../../../../../__mocks__'; | ||
import '../../../../__mocks__/engine_logic.mock'; | ||
|
||
import { ReactWrapper } from 'enzyme'; | ||
|
||
import { nextTick } from '@kbn/test/jest'; | ||
|
||
export const runActionColumnTests = (wrapper: ReactWrapper) => { | ||
const { http } = mockHttpValues; | ||
const { navigateToUrl } = mockKibanaValues; | ||
const { flashAPIErrors } = mockFlashMessageHelpers; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('view action', () => { | ||
it('navigates to the query detail view', () => { | ||
wrapper.find('[data-test-subj="AnalyticsTableViewQueryButton"]').first().simulate('click'); | ||
|
||
expect(navigateToUrl).toHaveBeenCalledWith( | ||
'/engines/some-engine/analytics/query_detail/some%20search' | ||
); | ||
}); | ||
|
||
it('falls back to "" for the empty query', () => { | ||
wrapper.find('[data-test-subj="AnalyticsTableViewQueryButton"]').last().simulate('click'); | ||
expect(navigateToUrl).toHaveBeenCalledWith( | ||
'/engines/some-engine/analytics/query_detail/%22%22' | ||
); | ||
}); | ||
}); | ||
|
||
describe('edit action', () => { | ||
it('calls the find_or_create curation API, then navigates the user to the curation', async () => { | ||
http.get.mockReturnValue(Promise.resolve({ id: 'cur-123456789' })); | ||
wrapper.find('[data-test-subj="AnalyticsTableEditQueryButton"]').first().simulate('click'); | ||
await nextTick(); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
'/api/app_search/engines/some-engine/curations/find_or_create', | ||
{ | ||
query: { query: 'some search' }, | ||
} | ||
); | ||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations/cur-123456789'); | ||
}); | ||
|
||
it('falls back to "" for the empty query', async () => { | ||
http.get.mockReturnValue(Promise.resolve({ id: 'cur-987654321' })); | ||
wrapper.find('[data-test-subj="AnalyticsTableEditQueryButton"]').last().simulate('click'); | ||
await nextTick(); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
'/api/app_search/engines/some-engine/curations/find_or_create', | ||
{ | ||
query: { query: '""' }, | ||
} | ||
); | ||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations/cur-987654321'); | ||
}); | ||
|
||
it('handles API errors', async () => { | ||
http.get.mockReturnValue(Promise.reject()); | ||
wrapper.find('[data-test-subj="AnalyticsTableEditQueryButton"]').first().simulate('click'); | ||
await nextTick(); | ||
|
||
expect(flashAPIErrors).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}; |
22 changes: 22 additions & 0 deletions
22
...rise_search/public/applications/app_search/components/curations/curations_router.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Route, Switch } from 'react-router-dom'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { CurationsRouter } from './'; | ||
|
||
describe('CurationsRouter', () => { | ||
it('renders', () => { | ||
const wrapper = shallow(<CurationsRouter engineBreadcrumb={['Engines', 'some-engine']} />); | ||
|
||
expect(wrapper.find(Switch)).toHaveLength(1); | ||
expect(wrapper.find(Route)).toHaveLength(5); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
...nterprise_search/public/applications/app_search/components/curations/curations_router.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Route, Switch } from 'react-router-dom'; | ||
|
||
import { APP_SEARCH_PLUGIN } from '../../../../../common/constants'; | ||
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; | ||
import { BreadcrumbTrail } from '../../../shared/kibana_chrome/generate_breadcrumbs'; | ||
import { NotFound } from '../../../shared/not_found'; | ||
import { | ||
ENGINE_CURATIONS_PATH, | ||
ENGINE_CURATIONS_NEW_PATH, | ||
ENGINE_CURATION_PATH, | ||
ENGINE_CURATION_ADD_RESULT_PATH, | ||
} from '../../routes'; | ||
|
||
import { CURATIONS_TITLE } from './constants'; | ||
|
||
interface Props { | ||
engineBreadcrumb: BreadcrumbTrail; | ||
} | ||
export const CurationsRouter: React.FC<Props> = ({ engineBreadcrumb }) => { | ||
const CURATIONS_BREADCRUMB = [...engineBreadcrumb, CURATIONS_TITLE]; | ||
|
||
return ( | ||
<Switch> | ||
<Route exact path={ENGINE_CURATIONS_PATH}> | ||
<SetPageChrome trail={CURATIONS_BREADCRUMB} /> | ||
TODO: Curations overview | ||
</Route> | ||
<Route exact path={ENGINE_CURATIONS_NEW_PATH}> | ||
<SetPageChrome trail={[...CURATIONS_BREADCRUMB, 'Create a curation']} /> | ||
TODO: Curation creation view | ||
</Route> | ||
<Route exact path={ENGINE_CURATION_PATH}> | ||
<SetPageChrome trail={[...CURATIONS_BREADCRUMB, 'curation queries']} /> | ||
TODO: Curation view (+ show a NotFound view if ID is invalid) | ||
</Route> | ||
<Route exact path={ENGINE_CURATION_ADD_RESULT_PATH}> | ||
<SetPageChrome | ||
trail={[...CURATIONS_BREADCRUMB, 'curation queries', 'add result manually']} | ||
/> | ||
TODO: Curation Add Result view | ||
</Route> | ||
<Route> | ||
<NotFound breadcrumbs={CURATIONS_BREADCRUMB} product={APP_SEARCH_PLUGIN} /> | ||
</Route> | ||
</Switch> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*/ | ||
|
||
export { CURATIONS_TITLE } from './constants'; | ||
export { CurationsRouter } from './curations_router'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.