-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Search] Empty shell view for engine source engines view (#96896)
* Add route to get source engines for meta engines * New empty SourceEngines component * Add SourceEngines to EngineRouter * New SourceEnginesLogic file * Hook up SourceEngines component to SourceEnginesLogic * Update EngineNav link to manage source engines to point internally * PR Feedback: - Copy fixes - Markup improvements - Spleling erors - Test improvements * Move EnginesAPIResponse to shared types file * Use existing mock for EngineLogic * setSourceEngines -> onSourceEnginesFetch Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
e2933b5
commit 9cade42
Showing
11 changed files
with
364 additions
and
16 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
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
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/types.ts
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,14 @@ | ||
/* | ||
* 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 { Meta } from '../../../../../common/types'; | ||
import { EngineDetails } from '../engine/types'; | ||
|
||
export interface EnginesAPIResponse { | ||
results: EngineDetails[]; | ||
meta: Meta; | ||
} |
8 changes: 8 additions & 0 deletions
8
...ugins/enterprise_search/public/applications/app_search/components/source_engines/index.ts
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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { SourceEngines } from './source_engines'; |
56 changes: 56 additions & 0 deletions
56
...e_search/public/applications/app_search/components/source_engines/source_engines.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,56 @@ | ||
/* | ||
* 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 '../../../__mocks__/shallow_useeffect.mock'; | ||
import { setMockActions, setMockValues } from '../../../__mocks__'; | ||
import '../../__mocks__/engine_logic.mock'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { EuiCodeBlock } from '@elastic/eui'; | ||
|
||
import { Loading } from '../../../shared/loading'; | ||
|
||
import { SourceEngines } from '.'; | ||
|
||
const MOCK_ACTIONS = { | ||
// SourceEnginesLogic | ||
fetchSourceEngines: jest.fn(), | ||
}; | ||
|
||
const MOCK_VALUES = { | ||
dataLoading: false, | ||
sourceEngines: [], | ||
}; | ||
|
||
describe('SourceEngines', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockActions(MOCK_ACTIONS); | ||
}); | ||
|
||
describe('non-happy-path states', () => { | ||
it('renders a loading component before data has loaded', () => { | ||
setMockValues({ ...MOCK_VALUES, dataLoading: true }); | ||
const wrapper = shallow(<SourceEngines />); | ||
|
||
expect(wrapper.find(Loading)).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe('happy-path states', () => { | ||
it('renders and calls a function to initialize data', () => { | ||
setMockValues(MOCK_VALUES); | ||
const wrapper = shallow(<SourceEngines />); | ||
|
||
expect(wrapper.find(EuiCodeBlock)).toHaveLength(1); | ||
expect(MOCK_ACTIONS.fetchSourceEngines).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
...rprise_search/public/applications/app_search/components/source_engines/source_engines.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,48 @@ | ||
/* | ||
* 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, { useEffect } from 'react'; | ||
|
||
import { useActions, useValues } from 'kea'; | ||
|
||
import { EuiCodeBlock, EuiPageHeader } from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { FlashMessages } from '../../../shared/flash_messages'; | ||
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; | ||
import { Loading } from '../../../shared/loading'; | ||
import { getEngineBreadcrumbs } from '../engine'; | ||
|
||
import { SourceEnginesLogic } from './source_engines_logic'; | ||
|
||
const SOURCE_ENGINES_TITLE = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.souceEngines.title', | ||
{ | ||
defaultMessage: 'Manage engines', | ||
} | ||
); | ||
|
||
export const SourceEngines: React.FC = () => { | ||
const { fetchSourceEngines } = useActions(SourceEnginesLogic); | ||
const { dataLoading, sourceEngines } = useValues(SourceEnginesLogic); | ||
|
||
useEffect(() => { | ||
fetchSourceEngines(); | ||
}, []); | ||
|
||
if (dataLoading) return <Loading />; | ||
|
||
return ( | ||
<> | ||
<SetPageChrome trail={getEngineBreadcrumbs([SOURCE_ENGINES_TITLE])} /> | ||
<EuiPageHeader pageTitle={SOURCE_ENGINES_TITLE} /> | ||
<FlashMessages /> | ||
<EuiCodeBlock language="json">{JSON.stringify(sourceEngines, null, 2)}</EuiCodeBlock> | ||
</> | ||
); | ||
}; |
134 changes: 134 additions & 0 deletions
134
...rch/public/applications/app_search/components/source_engines/source_engines_logic.test.ts
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,134 @@ | ||
/* | ||
* 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 { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../__mocks__'; | ||
import '../../__mocks__/engine_logic.mock'; | ||
|
||
import { nextTick } from '@kbn/test/jest'; | ||
|
||
import { EngineDetails } from '../engine/types'; | ||
|
||
import { SourceEnginesLogic } from './source_engines_logic'; | ||
|
||
const DEFAULT_VALUES = { | ||
dataLoading: true, | ||
sourceEngines: [], | ||
}; | ||
|
||
describe('SourceEnginesLogic', () => { | ||
const { http } = mockHttpValues; | ||
const { mount } = new LogicMounter(SourceEnginesLogic); | ||
const { flashAPIErrors } = mockFlashMessageHelpers; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mount(); | ||
}); | ||
|
||
it('initializes with default values', () => { | ||
expect(SourceEnginesLogic.values).toEqual(DEFAULT_VALUES); | ||
}); | ||
|
||
describe('setSourceEngines', () => { | ||
beforeEach(() => { | ||
SourceEnginesLogic.actions.onSourceEnginesFetch([ | ||
{ name: 'source-engine-1' }, | ||
{ name: 'source-engine-2' }, | ||
] as EngineDetails[]); | ||
}); | ||
|
||
it('sets the source engines', () => { | ||
expect(SourceEnginesLogic.values.sourceEngines).toEqual([ | ||
{ name: 'source-engine-1' }, | ||
{ name: 'source-engine-2' }, | ||
]); | ||
}); | ||
|
||
it('sets dataLoading to false', () => { | ||
expect(SourceEnginesLogic.values.dataLoading).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('fetchSourceEngines', () => { | ||
it('calls addSourceEngines and displayRow when it has retrieved all pages', async () => { | ||
http.get.mockReturnValueOnce( | ||
Promise.resolve({ | ||
meta: { | ||
page: { | ||
total_pages: 1, | ||
}, | ||
}, | ||
results: [{ name: 'source-engine-1' }, { name: 'source-engine-2' }], | ||
}) | ||
); | ||
jest.spyOn(SourceEnginesLogic.actions, 'onSourceEnginesFetch'); | ||
|
||
SourceEnginesLogic.actions.fetchSourceEngines(); | ||
await nextTick(); | ||
|
||
expect(http.get).toHaveBeenCalledWith('/api/app_search/engines/some-engine/source_engines', { | ||
query: { | ||
'page[current]': 1, | ||
'page[size]': 25, | ||
}, | ||
}); | ||
expect(SourceEnginesLogic.actions.onSourceEnginesFetch).toHaveBeenCalledWith([ | ||
{ name: 'source-engine-1' }, | ||
{ name: 'source-engine-2' }, | ||
]); | ||
}); | ||
|
||
it('display a flash message on error', async () => { | ||
http.get.mockReturnValueOnce(Promise.reject()); | ||
mount(); | ||
|
||
SourceEnginesLogic.actions.fetchSourceEngines(); | ||
await nextTick(); | ||
|
||
expect(flashAPIErrors).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('recursively fetches a number of pages', async () => { | ||
mount(); | ||
jest.spyOn(SourceEnginesLogic.actions, 'onSourceEnginesFetch'); | ||
|
||
// First page | ||
http.get.mockReturnValueOnce( | ||
Promise.resolve({ | ||
meta: { | ||
page: { | ||
total_pages: 2, | ||
}, | ||
}, | ||
results: [{ name: 'source-engine-1' }], | ||
}) | ||
); | ||
|
||
// Second and final page | ||
http.get.mockReturnValueOnce( | ||
Promise.resolve({ | ||
meta: { | ||
page: { | ||
total_pages: 2, | ||
}, | ||
}, | ||
results: [{ name: 'source-engine-2' }], | ||
}) | ||
); | ||
|
||
SourceEnginesLogic.actions.fetchSourceEngines(); | ||
await nextTick(); | ||
|
||
expect(SourceEnginesLogic.actions.onSourceEnginesFetch).toHaveBeenCalledWith([ | ||
// First page | ||
{ name: 'source-engine-1' }, | ||
// Second and final page | ||
{ name: 'source-engine-2' }, | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.