-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[App Search] Migrate Create Engine view #89816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
byronhulcher
merged 42 commits into
elastic:master
from
byronhulcher:create-engine-view
Feb 11, 2021
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
1b3083d
New CreateEngine view component
byronhulcher 9d92b03
Add CreateEngine to index router
byronhulcher cad6494
Add Layout-level components for CreateEngine
byronhulcher 4cc79b2
Static create engine view
byronhulcher 3886740
Add new POST route for engines API endpoint
byronhulcher 7dae33b
Logic for Create Engine view WIP tests failing
byronhulcher 714fca7
Fix enterpriseSearchRequestHandler path
byronhulcher efc7de3
Use setQueuedSuccessMessage after engine has been created
byronhulcher 49e7693
Use exact path for CREATE_ENGINES_PATH (but EngineRouter logic is sti…
byronhulcher 6f7f512
Add TODO note
byronhulcher 35b107f
Put CreateEngine inside the common App Search Layout
byronhulcher 120c749
Fix CreateEngineLogic jest tests
byronhulcher be7a3df
Move create engine view to /create_engine from /engines/new
byronhulcher 8737c69
Add Create an Engine button to Engines Overview
byronhulcher 3820860
Missing FlashMessages on EngineOverview
byronhulcher e9382fc
Fix test for CreateEngine route
byronhulcher 66dc0b6
Fix strong'd text in santized name note
byronhulcher 207f8b6
Use local constant for Supported Languages
byronhulcher 2ac0a29
Disable submit button when name is empty
byronhulcher 60bb55f
Bad conflict fix
byronhulcher dabe026
Lint nits
byronhulcher d2fccf4
Improve CreateEngineLogic tests
byronhulcher 0c743fd
Improve EngineOverview tests
byronhulcher 7cf8842
Disable EnginesOverview header responsiveness
byronhulcher c50b0ac
Moving CreateEngine route
byronhulcher e6eb59c
create_engine/CreateEngine -> engine_creation/EngineCreation
byronhulcher 4857d56
Use static values for tests
byronhulcher 1f62ee5
Fixing constants, better casing, better ID names, i18ning dropdown la…
byronhulcher 272666d
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher b6828de
Removing unused imports
byronhulcher 339afda
Fix EngineCreation tests
byronhulcher 3a9aba7
Fix Engines EmptyState tests
byronhulcher 31501a7
Fix EnginesOverview tests
byronhulcher affd7d1
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher 5bdb4d8
Lint fixes
byronhulcher 6aed5c7
Reset mocks after tests
byronhulcher 822d342
Update MockRouter properties
byronhulcher 34bf6cf
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher 4b6c281
Revert newline change
byronhulcher 3313354
Lint fix
byronhulcher 2ffcb6e
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher 0bbbfa9
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
215 changes: 215 additions & 0 deletions
215
.../enterprise_search/public/applications/app_search/components/engine_creation/constants.ts
This file contains hidden or 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,215 @@ | ||
| /* | ||
| * 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 DEFAULT_LANGUAGE = 'Universal'; | ||
|
|
||
| export const ENGINE_CREATION_TITLE = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.title', | ||
| { | ||
| defaultMessage: 'Create an engine', | ||
| } | ||
| ); | ||
|
|
||
| export const ENGINE_CREATION_FORM_TITLE = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.form.title', | ||
| { | ||
| defaultMessage: 'Name your engine', | ||
| } | ||
| ); | ||
|
|
||
| export const ENGINE_CREATION_FORM_ENGINE_NAME_LABEL = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.form.engineName.label', | ||
| { | ||
| defaultMessage: 'Engine name', | ||
| } | ||
| ); | ||
|
|
||
| export const ALLOWED_CHARS_NOTE = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.form.engineName.allowedCharactersHelpText', | ||
| { | ||
| defaultMessage: 'Engine names can only contain lowercase letters, numbers, and hyphens', | ||
| } | ||
| ); | ||
|
|
||
| export const SANITIZED_NAME_NOTE = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.form.engineName.sanitizedNameHelpText', | ||
| { | ||
| defaultMessage: 'Your engine will be named', | ||
| } | ||
| ); | ||
|
|
||
| export const ENGINE_CREATION_FORM_ENGINE_NAME_PLACEHOLDER = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.form.engineName.placeholder', | ||
| { | ||
| defaultMessage: 'i.e., my-search-engine', | ||
| } | ||
| ); | ||
|
|
||
| export const ENGINE_CREATION_FORM_ENGINE_LANGUAGE_LABEL = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.form.engineLanguage.label', | ||
| { | ||
| defaultMessage: 'Engine language', | ||
| } | ||
| ); | ||
|
|
||
| export const ENGINE_CREATION_FORM_SUBMIT_BUTTON_LABEL = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.form.submitButton.buttonLabel', | ||
| { | ||
| defaultMessage: 'Create engine', | ||
| } | ||
| ); | ||
|
|
||
| export const ENGINE_CREATION_SUCCESS_MESSAGE = i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.successMessage', | ||
| { | ||
| defaultMessage: 'Successfully created engine.', | ||
| } | ||
| ); | ||
|
|
||
| export const SUPPORTED_LANGUAGES = [ | ||
| { | ||
| value: 'Universal', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.universalDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Universal', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| text: '—', | ||
| disabled: true, | ||
| }, | ||
| { | ||
| value: 'zh', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.chineseDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Chinese', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'da', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.danishDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Danish', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'nl', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.dutchDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Dutch', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'en', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.englishDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'English', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'fr', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.frenchDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'French', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'de', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.germanDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'German', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'it', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.italianDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Italian', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'ja', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.japaneseDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Japanese', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'ko', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.koreanDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Korean', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'pt', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.portugueseDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Portuguese', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'pt-br', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.portugueseBrazilDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Portuguese (Brazil)', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'ru', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.russianDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Russian', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'es', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.spanishDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Spanish', | ||
| } | ||
| ), | ||
| }, | ||
| { | ||
| value: 'th', | ||
| text: i18n.translate( | ||
| 'xpack.enterpriseSearch.appSearch.engineCreation.supportedLanguages.thaiDropDownOptionLabel', | ||
| { | ||
| defaultMessage: 'Thai', | ||
| } | ||
| ), | ||
| }, | ||
| ]; |
119 changes: 119 additions & 0 deletions
119
...search/public/applications/app_search/components/engine_creation/engine_creation.test.tsx
This file contains hidden or 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,119 @@ | ||||||
| /* | ||||||
| * 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 { setMockActions, setMockValues } from '../../../__mocks__'; | ||||||
|
|
||||||
| import React from 'react'; | ||||||
|
|
||||||
| import { shallow } from 'enzyme'; | ||||||
|
|
||||||
| import { EngineCreation } from './'; | ||||||
|
|
||||||
| describe('EngineCreation', () => { | ||||||
| const DEFAULT_VALUES = { | ||||||
| name: '', | ||||||
| rawName: '', | ||||||
| language: 'Universal', | ||||||
| }; | ||||||
|
|
||||||
| const MOCK_ACTIONS = { | ||||||
| setRawName: jest.fn(), | ||||||
| setLanguage: jest.fn(), | ||||||
| submitEngine: jest.fn(), | ||||||
| }; | ||||||
|
|
||||||
| beforeEach(() => { | ||||||
| jest.clearAllMocks(); | ||||||
| setMockValues(DEFAULT_VALUES); | ||||||
| setMockActions(MOCK_ACTIONS); | ||||||
| }); | ||||||
|
|
||||||
| it('renders', () => { | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
| expect(wrapper.find('[data-test-subj="EngineCreation"]')).toHaveLength(1); | ||||||
| }); | ||||||
|
|
||||||
| it('EngineCreationForm calls submitEngine on form submit', () => { | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
| const simulatedEvent = { | ||||||
| preventDefault: jest.fn(), | ||||||
| }; | ||||||
| wrapper.find('[data-test-subj="EngineCreationForm"]').simulate('submit', simulatedEvent); | ||||||
|
|
||||||
| expect(MOCK_ACTIONS.submitEngine).toHaveBeenCalledTimes(1); | ||||||
| }); | ||||||
|
|
||||||
| it('EngineCreationNameInput calls setRawName on change', () => { | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
| const simulatedEvent = { | ||||||
| currentTarget: { value: 'new-raw-name' }, | ||||||
| }; | ||||||
| wrapper.find('[data-test-subj="EngineCreationNameInput"]').simulate('change', simulatedEvent); | ||||||
|
|
||||||
| expect(MOCK_ACTIONS.setRawName).toHaveBeenCalledWith('new-raw-name'); | ||||||
| }); | ||||||
|
|
||||||
| it('EngineCreationLanguageInput calls setLanguage on change', () => { | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
| const simulatedEvent = { | ||||||
| currentTarget: { value: 'English' }, | ||||||
| }; | ||||||
| wrapper | ||||||
| .find('[data-test-subj="EngineCreationLanguageInput"]') | ||||||
| .simulate('change', simulatedEvent); | ||||||
|
|
||||||
| expect(MOCK_ACTIONS.setLanguage).toHaveBeenCalledWith('English'); | ||||||
| }); | ||||||
|
|
||||||
| describe('NewEngineSubmitButton', () => { | ||||||
| it('is disabled when name is empty', () => { | ||||||
| setMockValues({ ...DEFAULT_VALUES, name: '', rawName: '' }); | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
|
|
||||||
| expect(wrapper.find('[data-test-subj="NewEngineSubmitButton"]').prop('disabled')).toEqual( | ||||||
| true | ||||||
| ); | ||||||
| }); | ||||||
|
|
||||||
| it('is enabled when name has a value', () => { | ||||||
| setMockValues({ ...DEFAULT_VALUES, name: 'test', rawName: 'test' }); | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
|
|
||||||
| expect(wrapper.find('[data-test-subj="NewEngineSubmitButton"]').prop('disabled')).toEqual( | ||||||
| false | ||||||
| ); | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| describe('EngineCreationNameFormRow', () => { | ||||||
| it('renders sanitized name helptext when the raw name is being sanitized', () => { | ||||||
| setMockValues({ | ||||||
| ...DEFAULT_VALUES, | ||||||
| name: 'un-sanitized-name', | ||||||
| rawName: 'un-----sanitized-------name', | ||||||
| }); | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
| const formRow = wrapper.find('[data-test-subj="EngineCreationNameFormRow"]').dive(); | ||||||
|
|
||||||
| expect(formRow.contains('Your engine will be named')).toBeTruthy(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion feels like it's missing the actual name? Is there any way we can assert on that?
Suggested change
not sure if the DOM works out that way, but that would make the test make a lot more sense when reading it. If it takes more than 5 minutes to do or it's a pain than no worries. |
||||||
| }); | ||||||
|
|
||||||
| it('renders allowed character helptext when rawName and sanitizedName match', () => { | ||||||
| setMockValues({ | ||||||
| ...DEFAULT_VALUES, | ||||||
| name: 'pre-sanitized-name', | ||||||
| rawName: 'pre-sanitized-name', | ||||||
| }); | ||||||
| const wrapper = shallow(<EngineCreation />); | ||||||
| const formRow = wrapper.find('[data-test-subj="EngineCreationNameFormRow"]').dive(); | ||||||
|
|
||||||
| expect( | ||||||
| formRow.contains('Engine names can only contain lowercase letters, numbers, and hyphens') | ||||||
| ).toBeTruthy(); | ||||||
| }); | ||||||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| }); | ||||||
| }); | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] If we're defining preventDefault in a referenceable var, we might as well check that it was called at the end of the test, e.g.
While I'm here also,
.toHaveBeenCalledTimes(1);(vs. just.toHaveBeenCalled()) is a little more specific than we're doing in other files. I don't feel super strongly either way we go, but it would be nice to be consistent across files vs writing things slightly differently across the codebase.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the specificity personally