Skip to content
Merged
Show file tree
Hide file tree
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 Jan 20, 2021
9d92b03
Add CreateEngine to index router
byronhulcher Jan 20, 2021
cad6494
Add Layout-level components for CreateEngine
byronhulcher Jan 20, 2021
4cc79b2
Static create engine view
byronhulcher Jan 26, 2021
3886740
Add new POST route for engines API endpoint
byronhulcher Jan 27, 2021
7dae33b
Logic for Create Engine view WIP tests failing
byronhulcher Jan 26, 2021
714fca7
Fix enterpriseSearchRequestHandler path
byronhulcher Jan 27, 2021
efc7de3
Use setQueuedSuccessMessage after engine has been created
byronhulcher Jan 27, 2021
49e7693
Use exact path for CREATE_ENGINES_PATH (but EngineRouter logic is sti…
byronhulcher Jan 27, 2021
6f7f512
Add TODO note
byronhulcher Jan 27, 2021
35b107f
Put CreateEngine inside the common App Search Layout
byronhulcher Jan 27, 2021
120c749
Fix CreateEngineLogic jest tests
byronhulcher Jan 27, 2021
be7a3df
Move create engine view to /create_engine from /engines/new
byronhulcher Jan 27, 2021
8737c69
Add Create an Engine button to Engines Overview
byronhulcher Jan 27, 2021
3820860
Missing FlashMessages on EngineOverview
byronhulcher Jan 30, 2021
e9382fc
Fix test for CreateEngine route
byronhulcher Jan 30, 2021
66dc0b6
Fix strong'd text in santized name note
byronhulcher Jan 30, 2021
207f8b6
Use local constant for Supported Languages
byronhulcher Jan 30, 2021
2ac0a29
Disable submit button when name is empty
byronhulcher Jan 30, 2021
60bb55f
Bad conflict fix
byronhulcher Jan 30, 2021
dabe026
Lint nits
byronhulcher Feb 3, 2021
d2fccf4
Improve CreateEngineLogic tests
byronhulcher Feb 3, 2021
0c743fd
Improve EngineOverview tests
byronhulcher Feb 3, 2021
7cf8842
Disable EnginesOverview header responsiveness
byronhulcher Feb 3, 2021
c50b0ac
Moving CreateEngine route
byronhulcher Feb 3, 2021
e6eb59c
create_engine/CreateEngine -> engine_creation/EngineCreation
byronhulcher Feb 3, 2021
4857d56
Use static values for tests
byronhulcher Feb 3, 2021
1f62ee5
Fixing constants, better casing, better ID names, i18ning dropdown la…
byronhulcher Feb 3, 2021
272666d
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher Feb 3, 2021
b6828de
Removing unused imports
byronhulcher Feb 8, 2021
339afda
Fix EngineCreation tests
byronhulcher Feb 8, 2021
3a9aba7
Fix Engines EmptyState tests
byronhulcher Feb 8, 2021
31501a7
Fix EnginesOverview tests
byronhulcher Feb 8, 2021
affd7d1
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher Feb 8, 2021
5bdb4d8
Lint fixes
byronhulcher Feb 8, 2021
6aed5c7
Reset mocks after tests
byronhulcher Feb 8, 2021
822d342
Update MockRouter properties
byronhulcher Feb 8, 2021
34bf6cf
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher Feb 9, 2021
4b6c281
Revert newline change
byronhulcher Feb 9, 2021
3313354
Lint fix
byronhulcher Feb 9, 2021
2ffcb6e
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher Feb 9, 2021
0bbbfa9
Merge remote-tracking branch 'origin/master' into create-engine-view
byronhulcher Feb 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
}
),
},
];
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(),
Copy link
Copy Markdown
Contributor

@cee-chen cee-chen Feb 9, 2021

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.

expect(simulatedEvent.preventDefault).toHaveBeenCalledTimes(1);
expect(MOCK_ACTIONS.submitEngine).toHaveBeenCalledTimes(1);

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.

Copy link
Copy Markdown
Contributor Author

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

};
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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
expect(formRow.contains('Your engine will be named')).toBeTruthy();
expect(formRow.contains('Your engine will be named un-sanitized-name')).toBeTruthy();

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();
});
});
});
Loading