-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[controls] Refactor control group settings functional tests #190999
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d27d646
Refactor control settings functional tests into unit tests
nreese b3b581c
Merge remote-tracking branch 'upstream/main' into control_settings_test
nreese 0c7067f
revert changes to control group factory
nreese 7e96c24
test artifacts
nreese 1f3749b
stub out control group editor tests
nreese ff03326
ControlGroupEditor test
nreese bd35621
finish test clean up
nreese d7d2a2e
remove .only
nreese 24956cf
Merge branch 'main' into control_settings_test
elasticmachine 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
50 changes: 50 additions & 0 deletions
50
...ins/controls/public/react_controls/control_group/components/control_group_editor.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,50 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { BehaviorSubject } from 'rxjs'; | ||
| import { render } from '@testing-library/react'; | ||
| import { ControlGroupEditor } from './control_group_editor'; | ||
| import { ControlGroupApi, ControlStyle, ParentIgnoreSettings } from '../../..'; | ||
| import { ControlGroupChainingSystem, DEFAULT_CONTROL_STYLE } from '../../../../common'; | ||
| import { DefaultControlApi } from '../../controls/types'; | ||
|
|
||
| describe('render', () => { | ||
| const children$ = new BehaviorSubject<{ [key: string]: DefaultControlApi }>({}); | ||
| const props = { | ||
| api: { | ||
| children$, | ||
| } as unknown as ControlGroupApi, | ||
| onCancel: () => {}, | ||
| onSave: () => {}, | ||
| onDeleteAll: () => {}, | ||
| stateManager: { | ||
| chainingSystem: new BehaviorSubject<ControlGroupChainingSystem>('HIERARCHICAL'), | ||
| labelPosition: new BehaviorSubject<ControlStyle>(DEFAULT_CONTROL_STYLE), | ||
| autoApplySelections: new BehaviorSubject<boolean>(true), | ||
| ignoreParentSettings: new BehaviorSubject<ParentIgnoreSettings | undefined>(undefined), | ||
| }, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| children$.next({}); | ||
| }); | ||
|
|
||
| test('should not display delete all controls button when there are no controls', () => { | ||
| const editor = render(<ControlGroupEditor {...props} />); | ||
| expect(editor.queryByTestId('delete-all-controls-button')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('should display delete all controls button when there are controls', () => { | ||
| children$.next({ | ||
| alpha: {} as unknown as DefaultControlApi, | ||
| }); | ||
| const editor = render(<ControlGroupEditor {...props} />); | ||
| expect(editor.queryByTestId('delete-all-controls-button')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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
106 changes: 106 additions & 0 deletions
106
src/plugins/controls/public/react_controls/control_group/components/control_panel.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,106 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import React, { useImperativeHandle } from 'react'; | ||
| import { BehaviorSubject } from 'rxjs'; | ||
| import { render, waitFor } from '@testing-library/react'; | ||
| import { ControlPanel } from './control_panel'; | ||
| import { registry as presentationUtilServicesRegistry } from '@kbn/presentation-util-plugin/public/services/plugin_services.story'; | ||
| import { pluginServices as presentationUtilPluginServices } from '@kbn/presentation-util-plugin/public/services'; | ||
| import { ControlStyle, ControlWidth } from '../../..'; | ||
|
|
||
| describe('render', () => { | ||
| let mockApi = {}; | ||
| const Component = React.forwardRef((_, ref) => { | ||
| // expose the api into the imperative handle | ||
| useImperativeHandle(ref, () => mockApi, []); | ||
|
|
||
| return <div />; | ||
| }) as any; | ||
|
|
||
| beforeAll(() => { | ||
| presentationUtilServicesRegistry.start({}); | ||
| presentationUtilPluginServices.setRegistry(presentationUtilServicesRegistry); | ||
| presentationUtilPluginServices.getServices().uiActions.getTriggerCompatibleActions = jest | ||
| .fn() | ||
| .mockImplementation(() => { | ||
| return [ | ||
| { | ||
| isCompatible: jest.fn().mockResolvedValue(true), | ||
| id: 'testAction', | ||
| MenuItem: () => <div>test1</div>, | ||
| }, | ||
| ]; | ||
| }); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| mockApi = {}; | ||
| }); | ||
|
|
||
| describe('control width', () => { | ||
| test('defaults to medium and grow enabled', async () => { | ||
| const controlPanel = render(<ControlPanel uuid="control1" Component={Component} />); | ||
| await waitFor(() => { | ||
| const controlFrame = controlPanel.getByTestId('control-frame'); | ||
| expect(controlFrame.getAttribute('class')).toContain('controlFrameWrapper--medium'); | ||
| expect(controlFrame.getAttribute('class')).toContain('controlFrameWrapper--grow'); | ||
| }); | ||
| }); | ||
|
|
||
| test('should use small class when using small width', async () => { | ||
| mockApi = { | ||
| uuid: 'control1', | ||
| width: new BehaviorSubject<ControlWidth>('small'), | ||
| }; | ||
| const controlPanel = render(<ControlPanel uuid="control1" Component={Component} />); | ||
| await waitFor(() => { | ||
| const controlFrame = controlPanel.getByTestId('control-frame'); | ||
| expect(controlFrame.getAttribute('class')).toContain('controlFrameWrapper--small'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('label position', () => { | ||
| test('should use one line layout class when using one line layout', async () => { | ||
| mockApi = { | ||
| uuid: 'control1', | ||
| parentApi: { | ||
| labelPosition: new BehaviorSubject<ControlStyle>('oneLine'), | ||
| }, | ||
| }; | ||
| const controlPanel = render(<ControlPanel uuid="control1" Component={Component} />); | ||
| await waitFor(() => { | ||
| const floatingActions = controlPanel.getByTestId( | ||
| 'presentationUtil__floatingActions__control1' | ||
| ); | ||
| expect(floatingActions.getAttribute('class')).toContain( | ||
| 'controlFrameFloatingActions--oneLine' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test('should use two line layout class when using two line layout', async () => { | ||
| mockApi = { | ||
| uuid: 'control1', | ||
| parentApi: { | ||
| labelPosition: new BehaviorSubject<ControlStyle>('twoLine'), | ||
| }, | ||
| }; | ||
| const controlPanel = render(<ControlPanel uuid="control1" Component={Component} />); | ||
| await waitFor(() => { | ||
| const floatingActions = controlPanel.getByTestId( | ||
| 'presentationUtil__floatingActions__control1' | ||
| ); | ||
| expect(floatingActions.getAttribute('class')).toContain( | ||
| 'controlFrameFloatingActions--twoLine' | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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
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
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.
nit: if this type isn't exported or used more than once - why not inline it?