-
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] Add a Sample Engine CTA panel to the engines table when …
…empty (#94647) * Added new onboarding complete route for App Search * Allow responses without JSON bodies in Enterprise Search * New SampleEngineCreationCtaLogic * New SampleEngineCreationCta component * Add SampleEngineCreationCTA to engines EmptyState * Improve SampleEngineCreationCta * Fix spelling error in Enterprise Search request handler test * Improve SampleEngineCreationCtaLogic * Fix types * Fix tests after origin/master merge * Turns out I 'fixed' my tests by removing this test Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
5b69278
commit e91d0d4
Showing
13 changed files
with
451 additions
and
32 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
29 changes: 29 additions & 0 deletions
29
...prise_search/public/applications/app_search/components/sample_engine_creation_cta/i18n.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,29 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const SAMPLE_ENGINE_CREATION_CTA_TITLE = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.sampleEngineCreationCta.title', | ||
{ | ||
defaultMessage: 'Just kicking the tires?', | ||
} | ||
); | ||
|
||
export const SAMPLE_ENGINE_CREATION_CTA_DESCRIPTION = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.sampleEngineCreationCta.description', | ||
{ | ||
defaultMessage: 'Test an engine with sample data.', | ||
} | ||
); | ||
|
||
export const SAMPLE_ENGINE_CREATION_CTA_BUTTON_LABEL = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.sampleEngineCreationCta.buttonLabel', | ||
{ | ||
defaultMessage: 'Try a sample engine', | ||
} | ||
); |
8 changes: 8 additions & 0 deletions
8
...rise_search/public/applications/app_search/components/sample_engine_creation_cta/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 { SampleEngineCreationCta } from './sample_engine_creation_cta'; |
57 changes: 57 additions & 0 deletions
57
...ions/app_search/components/sample_engine_creation_cta/sample_engine_creation_cta.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,57 @@ | ||
/* | ||
* 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__/enterprise_search_url.mock'; | ||
import { setMockActions, setMockValues } from '../../../__mocks__'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { EuiButton } from '@elastic/eui'; | ||
|
||
import { SampleEngineCreationCta } from './sample_engine_creation_cta'; | ||
|
||
describe('SampleEngineCTA', () => { | ||
describe('CTA button', () => { | ||
const MOCK_VALUES = { | ||
isLoading: false, | ||
}; | ||
|
||
const MOCK_ACTIONS = { | ||
createSampleEngine: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockActions(MOCK_ACTIONS); | ||
setMockValues(MOCK_VALUES); | ||
}); | ||
|
||
it('calls createSampleEngine on click', () => { | ||
const wrapper = shallow(<SampleEngineCreationCta />); | ||
const ctaButton = wrapper.find(EuiButton); | ||
|
||
expect(ctaButton.props().onClick).toEqual(MOCK_ACTIONS.createSampleEngine); | ||
}); | ||
|
||
it('is enabled by default', () => { | ||
const wrapper = shallow(<SampleEngineCreationCta />); | ||
const ctaButton = wrapper.find(EuiButton); | ||
|
||
expect(ctaButton.props().isLoading).toEqual(false); | ||
}); | ||
|
||
it('is disabled while loading', () => { | ||
setMockValues({ ...MOCK_VALUES, isLoading: true }); | ||
const wrapper = shallow(<SampleEngineCreationCta />); | ||
const ctaButton = wrapper.find(EuiButton); | ||
|
||
expect(ctaButton.props().isLoading).toEqual(true); | ||
}); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
...lications/app_search/components/sample_engine_creation_cta/sample_engine_creation_cta.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,44 @@ | ||
/* | ||
* 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 { useActions, useValues } from 'kea'; | ||
|
||
import { EuiPanel, EuiFlexGroup, EuiFlexItem, EuiTitle, EuiText, EuiButton } from '@elastic/eui'; | ||
|
||
import { | ||
SAMPLE_ENGINE_CREATION_CTA_TITLE, | ||
SAMPLE_ENGINE_CREATION_CTA_DESCRIPTION, | ||
SAMPLE_ENGINE_CREATION_CTA_BUTTON_LABEL, | ||
} from './i18n'; | ||
import { SampleEngineCreationCtaLogic } from './sample_engine_creation_cta_logic'; | ||
|
||
export const SampleEngineCreationCta: React.FC = () => { | ||
const { isLoading } = useValues(SampleEngineCreationCtaLogic); | ||
const { createSampleEngine } = useActions(SampleEngineCreationCtaLogic); | ||
|
||
return ( | ||
<EuiPanel> | ||
<EuiFlexGroup alignItems="center"> | ||
<EuiFlexItem> | ||
<EuiTitle size="s"> | ||
<h3>{SAMPLE_ENGINE_CREATION_CTA_TITLE}</h3> | ||
</EuiTitle> | ||
<EuiText size="s"> | ||
<p>{SAMPLE_ENGINE_CREATION_CTA_DESCRIPTION}</p> | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton onClick={createSampleEngine} isLoading={isLoading}> | ||
{SAMPLE_ENGINE_CREATION_CTA_BUTTON_LABEL} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
}; |
92 changes: 92 additions & 0 deletions
92
...app_search/components/sample_engine_creation_cta/sample_engine_creation_cta_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,92 @@ | ||
/* | ||
* 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, | ||
mockHttpValues, | ||
mockKibanaValues, | ||
mockFlashMessageHelpers, | ||
} from '../../../__mocks__'; | ||
|
||
import { nextTick } from '@kbn/test/jest'; | ||
|
||
import { SampleEngineCreationCtaLogic } from './sample_engine_creation_cta_logic'; | ||
|
||
describe('SampleEngineCreationCtaLogic', () => { | ||
const { mount } = new LogicMounter(SampleEngineCreationCtaLogic); | ||
const { http } = mockHttpValues; | ||
const { navigateToUrl } = mockKibanaValues; | ||
const { setQueuedSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers; | ||
|
||
const DEFAULT_VALUES = { | ||
isLoading: false, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mount(); | ||
}); | ||
|
||
it('has expected default values', () => { | ||
expect(SampleEngineCreationCtaLogic.values).toEqual(DEFAULT_VALUES); | ||
}); | ||
|
||
describe('actions', () => { | ||
it('onSampleEngineCreationFailure sets isLoading to false', () => { | ||
mount({ isLoading: true }); | ||
|
||
SampleEngineCreationCtaLogic.actions.onSampleEngineCreationFailure(); | ||
|
||
expect(SampleEngineCreationCtaLogic.values.isLoading).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('listeners', () => { | ||
describe('createSampleEngine', () => { | ||
it('POSTS to /api/app_search/engines', () => { | ||
const body = JSON.stringify({ | ||
seed_sample_engine: true, | ||
}); | ||
SampleEngineCreationCtaLogic.actions.createSampleEngine(); | ||
|
||
expect(http.post).toHaveBeenCalledWith('/api/app_search/onboarding_complete', { body }); | ||
}); | ||
|
||
it('calls onSampleEngineCreationSuccess on valid submission', async () => { | ||
jest.spyOn(SampleEngineCreationCtaLogic.actions, 'onSampleEngineCreationSuccess'); | ||
http.post.mockReturnValueOnce(Promise.resolve({})); | ||
|
||
SampleEngineCreationCtaLogic.actions.createSampleEngine(); | ||
await nextTick(); | ||
|
||
expect( | ||
SampleEngineCreationCtaLogic.actions.onSampleEngineCreationSuccess | ||
).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('calls onSampleEngineCreationFailure and flashAPIErrors on API Error', async () => { | ||
jest.spyOn(SampleEngineCreationCtaLogic.actions, 'onSampleEngineCreationFailure'); | ||
http.post.mockReturnValueOnce(Promise.reject()); | ||
|
||
SampleEngineCreationCtaLogic.actions.createSampleEngine(); | ||
await nextTick(); | ||
|
||
expect(flashAPIErrors).toHaveBeenCalledTimes(1); | ||
expect( | ||
SampleEngineCreationCtaLogic.actions.onSampleEngineCreationFailure | ||
).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
it('onSampleEngineCreationSuccess should set a success message and navigate the user to the engine page', () => { | ||
SampleEngineCreationCtaLogic.actions.onSampleEngineCreationSuccess(); | ||
|
||
expect(setQueuedSuccessMessage).toHaveBeenCalledWith('Successfully created engine.'); | ||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/national-parks-demo'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.