forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[controls] Refactor control group settings functional tests (elastic#…
…190999) Refactor control group settings tests 1. move non-functional test cases to unit tests 2. use pre-built dashboard to avoid time of building dashboard in test ### Before Tests take 4 minutes to run locally <img width="400" alt="Screenshot 2024-08-21 at 3 12 31 PM" src="https://github.com/user-attachments/assets/96cf584c-2b32-4281-86ee-9791544bd5fa"> ### After Tests take 1 minute to run locally <img width="400" alt="Screenshot 2024-08-21 at 2 53 37 PM" src="https://github.com/user-attachments/assets/853a6f3a-74c5-4ca8-a488-99dd24477b1e"> --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
b6ce155
commit 79051d4
Showing
8 changed files
with
221 additions
and
140 deletions.
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 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 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 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 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.