-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Component template] Details flyout #68732
Merged
alisonelizabeth
merged 15 commits into
elastic:master
from
alisonelizabeth:feature/component_template_details
Jun 17, 2020
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
641a843
add details flyout
alisonelizabeth 899643a
cleanup
alisonelizabeth ef9734f
refactor
alisonelizabeth 9c8e183
refactor: make actions optional + create separate component for conte…
alisonelizabeth 4d214ef
add component integration tests
alisonelizabeth 115a816
fix linter
alisonelizabeth 39e18e4
remove unused appBasePath
alisonelizabeth 65b4c11
remove unused import
alisonelizabeth 5ae31f6
Merge branch 'master' into feature/component_template_details
elasticmachine cf77c7e
Merge branch 'master' of github.com:elastic/kibana into feature/compo…
alisonelizabeth 27ff24f
move tab content to shared directory
alisonelizabeth 1f485b6
cleanup
alisonelizabeth c1b9cba
Merge branch 'master' into feature/component_template_details
elasticmachine 57bbc8f
Merge branch 'master' into feature/component_template_details
elasticmachine 7f02d72
address review feedback
alisonelizabeth 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
220 changes: 220 additions & 0 deletions
220
...onents/component_templates/__jest__/client_integration/component_template_details.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,220 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { setupEnvironment, pageHelpers } from './helpers'; | ||
import { ComponentTemplateDetailsTestBed } from './helpers/component_template_details.helpers'; | ||
import { ComponentTemplateDeserialized } from '../../shared_imports'; | ||
|
||
const { setup } = pageHelpers.componentTemplateDetails; | ||
|
||
jest.mock('ui/i18n', () => { | ||
const I18nContext = ({ children }: any) => children; | ||
return { I18nContext }; | ||
}); | ||
|
||
const COMPONENT_TEMPLATE: ComponentTemplateDeserialized = { | ||
name: 'comp-1', | ||
template: { | ||
mappings: { properties: { ip_address: { type: 'ip' } } }, | ||
aliases: { mydata: {} }, | ||
settings: { number_of_shards: 1 }, | ||
}, | ||
version: 1, | ||
_meta: { description: 'component template test' }, | ||
_kbnMeta: { usedBy: ['template_1'] }, | ||
}; | ||
|
||
const COMPONENT_TEMPLATE_ONLY_REQUIRED_FIELDS: ComponentTemplateDeserialized = { | ||
name: 'comp-base', | ||
template: {}, | ||
_kbnMeta: { usedBy: [] }, | ||
}; | ||
|
||
describe('<ComponentTemplateDetails />', () => { | ||
const { server, httpRequestsMockHelpers } = setupEnvironment(); | ||
let testBed: ComponentTemplateDetailsTestBed; | ||
|
||
afterAll(() => { | ||
server.restore(); | ||
}); | ||
|
||
describe('With component template details', () => { | ||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadComponentTemplateResponse(COMPONENT_TEMPLATE); | ||
|
||
await act(async () => { | ||
testBed = setup({ | ||
componentTemplateName: COMPONENT_TEMPLATE.name, | ||
onClose: () => {}, | ||
}); | ||
}); | ||
|
||
testBed.component.update(); | ||
}); | ||
|
||
test('renders the details flyout', () => { | ||
const { exists, find, actions, component } = testBed; | ||
|
||
// Verify flyout exists with correct title | ||
expect(exists('componentTemplateDetails')).toBe(true); | ||
expect(find('componentTemplateDetails.title').text()).toBe(COMPONENT_TEMPLATE.name); | ||
|
||
// Verify footer does not display since "actions" prop was not provided | ||
expect(exists('componentTemplateDetails.footer')).toBe(false); | ||
|
||
// Verify tabs exist | ||
expect(exists('settingsTab')).toBe(true); | ||
expect(exists('mappingsTab')).toBe(true); | ||
expect(exists('aliasesTab')).toBe(true); | ||
// Summary tab should be active by default | ||
expect(find('summaryTab').props()['aria-selected']).toBe(true); | ||
|
||
// [Summary tab] Verify description list items | ||
expect(exists('summaryTabContent.usedByTitle')).toBe(true); | ||
expect(exists('summaryTabContent.versionTitle')).toBe(true); | ||
expect(exists('summaryTabContent.metaTitle')).toBe(true); | ||
|
||
// [Settings tab] Navigate to tab and verify content | ||
act(() => { | ||
actions.clickSettingsTab(); | ||
}); | ||
|
||
component.update(); | ||
|
||
expect(exists('settingsTabContent')).toBe(true); | ||
|
||
// [Mappings tab] Navigate to tab and verify content | ||
act(() => { | ||
actions.clickMappingsTab(); | ||
}); | ||
|
||
component.update(); | ||
expect(exists('mappingsTabContent')).toBe(true); | ||
|
||
// [Aliases tab] Navigate to tab and verify content | ||
act(() => { | ||
actions.clickAliasesTab(); | ||
}); | ||
|
||
component.update(); | ||
expect(exists('aliasesTabContent')).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('With only required component template fields', () => { | ||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadComponentTemplateResponse( | ||
COMPONENT_TEMPLATE_ONLY_REQUIRED_FIELDS | ||
); | ||
|
||
await act(async () => { | ||
testBed = setup({ | ||
componentTemplateName: COMPONENT_TEMPLATE_ONLY_REQUIRED_FIELDS.name, | ||
onClose: () => {}, | ||
}); | ||
}); | ||
|
||
testBed.component.update(); | ||
}); | ||
|
||
test('renders the details flyout', () => { | ||
const { exists, actions, component } = testBed; | ||
|
||
// [Summary tab] Verify optional description list items do not display | ||
expect(exists('summaryTabContent.usedByTitle')).toBe(false); | ||
expect(exists('summaryTabContent.versionTitle')).toBe(false); | ||
expect(exists('summaryTabContent.metaTitle')).toBe(false); | ||
// Verify callout renders indicating the component template is not in use | ||
expect(exists('notInUseCallout')).toBe(true); | ||
|
||
// [Settings tab] Navigate to tab and verify info callout | ||
act(() => { | ||
actions.clickSettingsTab(); | ||
}); | ||
|
||
component.update(); | ||
|
||
expect(exists('noSettingsCallout')).toBe(true); | ||
|
||
// [Mappings tab] Navigate to tab and verify info callout | ||
act(() => { | ||
actions.clickMappingsTab(); | ||
}); | ||
|
||
component.update(); | ||
expect(exists('noMappingsCallout')).toBe(true); | ||
|
||
// [Aliases tab] Navigate to tab and verify info callout | ||
act(() => { | ||
actions.clickAliasesTab(); | ||
}); | ||
|
||
component.update(); | ||
expect(exists('noAliasesCallout')).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('With actions', () => { | ||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadComponentTemplateResponse(COMPONENT_TEMPLATE); | ||
|
||
await act(async () => { | ||
testBed = setup({ | ||
componentTemplateName: COMPONENT_TEMPLATE.name, | ||
onClose: () => {}, | ||
actions: [ | ||
{ | ||
name: 'Test', | ||
icon: 'info', | ||
closePopoverOnClick: true, | ||
handleActionClick: () => {}, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
testBed.component.update(); | ||
}); | ||
|
||
test('should render a footer with context menu', () => { | ||
const { exists } = testBed; | ||
|
||
// Verify footer exists | ||
expect(exists('componentTemplateDetails.footer')).toBe(true); | ||
expect(exists('manageComponentTemplateButton')).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('Error handling', () => { | ||
const error = { | ||
status: 500, | ||
error: 'Internal server error', | ||
message: 'Internal server error', | ||
}; | ||
|
||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadComponentTemplateResponse(undefined, { body: error }); | ||
|
||
await act(async () => { | ||
testBed = setup({ | ||
componentTemplateName: COMPONENT_TEMPLATE.name, | ||
onClose: () => {}, | ||
}); | ||
}); | ||
|
||
testBed.component.update(); | ||
}); | ||
|
||
test('should render an error message if error fetching pipelines', async () => { | ||
const { exists, find } = testBed; | ||
|
||
expect(exists('sectionError')).toBe(true); | ||
expect(find('sectionError').text()).toContain('Error loading component template'); | ||
}); | ||
}); | ||
}); |
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
79 changes: 79 additions & 0 deletions
79
...onent_templates/__jest__/client_integration/helpers/component_template_details.helpers.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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { registerTestBed, TestBed } from '../../../../../../../../../test_utils'; | ||
import { WithAppDependencies } from './setup_environment'; | ||
import { ComponentTemplateDetailsFlyout } from '../../../component_template_details'; | ||
|
||
export type ComponentTemplateDetailsTestBed = TestBed<ComponentTemplateDetailsTestSubjects> & { | ||
actions: ReturnType<typeof createActions>; | ||
}; | ||
|
||
const createActions = (testBed: TestBed<ComponentTemplateDetailsTestSubjects>) => { | ||
const { find } = testBed; | ||
|
||
/** | ||
* User Actions | ||
*/ | ||
const clickSettingsTab = () => { | ||
find('settingsTab').simulate('click'); | ||
}; | ||
|
||
const clickMappingsTab = () => { | ||
find('mappingsTab').simulate('click'); | ||
}; | ||
|
||
const clickAliasesTab = () => { | ||
find('aliasesTab').simulate('click'); | ||
}; | ||
|
||
return { | ||
clickSettingsTab, | ||
clickAliasesTab, | ||
clickMappingsTab, | ||
}; | ||
}; | ||
|
||
export const setup = (props: any): ComponentTemplateDetailsTestBed => { | ||
const setupTestBed = registerTestBed<ComponentTemplateDetailsTestSubjects>( | ||
WithAppDependencies(ComponentTemplateDetailsFlyout), | ||
{ | ||
memoryRouter: { | ||
wrapComponent: false, | ||
}, | ||
defaultProps: props, | ||
} | ||
); | ||
|
||
const testBed = setupTestBed() as ComponentTemplateDetailsTestBed; | ||
|
||
return { | ||
...testBed, | ||
actions: createActions(testBed), | ||
}; | ||
}; | ||
|
||
export type ComponentTemplateDetailsTestSubjects = | ||
| 'componentTemplateDetails' | ||
| 'componentTemplateDetails.title' | ||
| 'componentTemplateDetails.footer' | ||
| 'summaryTab' | ||
| 'mappingsTab' | ||
| 'settingsTab' | ||
| 'aliasesTab' | ||
| 'sectionError' | ||
| 'summaryTabContent' | ||
| 'summaryTabContent.usedByTitle' | ||
| 'summaryTabContent.versionTitle' | ||
| 'summaryTabContent.metaTitle' | ||
| 'notInUseCallout' | ||
| 'aliasesTabContent' | ||
| 'noAliasesCallout' | ||
| 'mappingsTabContent' | ||
| 'noMappingsCallout' | ||
| 'settingsTabContent' | ||
| 'noSettingsCallout' | ||
| 'manageComponentTemplateButton'; |
7 changes: 7 additions & 0 deletions
7
...plication/components/component_templates/__jest__/client_integration/helpers/constants.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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export const API_BASE_PATH = '/api/index_management'; |
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.
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.
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.
Should we add a test that clicks on the manageComponentTemplateButton and list the same number of items that the actions provided?
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.
Done