-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
643 additions
and
413 deletions.
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
.../plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_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,169 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { | ||
createMockVisualization, | ||
createMockFramePublicAPI, | ||
createMockDatasource, | ||
DatasourceMock, | ||
} from '../../mocks'; | ||
import { Visualization } from '../../../types'; | ||
import { mountWithIntl } from '@kbn/test/jest'; | ||
import { LayerPanels } from './config_panel'; | ||
import { LayerPanel } from './layer_panel'; | ||
import { coreMock } from 'src/core/public/mocks'; | ||
import { generateId } from '../../../id_generator'; | ||
|
||
jest.mock('../../../id_generator'); | ||
|
||
describe('ConfigPanel', () => { | ||
let mockVisualization: jest.Mocked<Visualization>; | ||
let mockVisualization2: jest.Mocked<Visualization>; | ||
let mockDatasource: DatasourceMock; | ||
const frame = createMockFramePublicAPI(); | ||
|
||
function getDefaultProps() { | ||
frame.datasourceLayers = { | ||
first: mockDatasource.publicAPIMock, | ||
}; | ||
return { | ||
activeVisualizationId: 'vis1', | ||
visualizationMap: { | ||
vis1: mockVisualization, | ||
vis2: mockVisualization2, | ||
}, | ||
activeDatasourceId: 'ds1', | ||
datasourceMap: { | ||
ds1: mockDatasource, | ||
}, | ||
activeVisualization: ({ | ||
...mockVisualization, | ||
getLayerIds: () => Object.keys(frame.datasourceLayers), | ||
appendLayer: true, | ||
} as unknown) as Visualization, | ||
datasourceStates: { | ||
ds1: { | ||
isLoading: false, | ||
state: 'state', | ||
}, | ||
}, | ||
visualizationState: 'state', | ||
updateVisualization: jest.fn(), | ||
updateDatasource: jest.fn(), | ||
updateAll: jest.fn(), | ||
framePublicAPI: frame, | ||
dispatch: jest.fn(), | ||
core: coreMock.createStart(), | ||
}; | ||
} | ||
|
||
beforeEach(() => { | ||
mockVisualization = { | ||
...createMockVisualization(), | ||
id: 'testVis', | ||
visualizationTypes: [ | ||
{ | ||
icon: 'empty', | ||
id: 'testVis', | ||
label: 'TEST1', | ||
}, | ||
], | ||
}; | ||
|
||
mockVisualization2 = { | ||
...createMockVisualization(), | ||
|
||
id: 'testVis2', | ||
visualizationTypes: [ | ||
{ | ||
icon: 'empty', | ||
id: 'testVis2', | ||
label: 'TEST2', | ||
}, | ||
], | ||
}; | ||
|
||
mockVisualization.getLayerIds.mockReturnValue(Object.keys(frame.datasourceLayers)); | ||
mockDatasource = createMockDatasource('ds1'); | ||
}); | ||
|
||
describe('focus behavior when adding or removing layers', () => { | ||
it('should focus the only layer when resetting the layer', () => { | ||
const component = mountWithIntl(<LayerPanels {...getDefaultProps()} />); | ||
const firstLayerFocusable = component | ||
.find(LayerPanel) | ||
.first() | ||
.find('section') | ||
.first() | ||
.instance(); | ||
act(() => { | ||
component.find('[data-test-subj="lnsLayerRemove"]').first().simulate('click'); | ||
}); | ||
const focusedEl = document.activeElement; | ||
expect(focusedEl).toEqual(firstLayerFocusable); | ||
}); | ||
|
||
it('should focus the second layer when removing the first layer', () => { | ||
const defaultProps = getDefaultProps(); | ||
// overwriting datasourceLayers to test two layers | ||
frame.datasourceLayers = { | ||
first: mockDatasource.publicAPIMock, | ||
second: mockDatasource.publicAPIMock, | ||
}; | ||
const component = mountWithIntl(<LayerPanels {...defaultProps} />); | ||
const secondLayerFocusable = component | ||
.find(LayerPanel) | ||
.at(1) | ||
.find('section') | ||
.first() | ||
.instance(); | ||
act(() => { | ||
component.find('[data-test-subj="lnsLayerRemove"]').at(0).simulate('click'); | ||
}); | ||
const focusedEl = document.activeElement; | ||
expect(focusedEl).toEqual(secondLayerFocusable); | ||
}); | ||
|
||
it('should focus the first layer when removing the second layer', () => { | ||
const defaultProps = getDefaultProps(); | ||
// overwriting datasourceLayers to test two layers | ||
frame.datasourceLayers = { | ||
first: mockDatasource.publicAPIMock, | ||
second: mockDatasource.publicAPIMock, | ||
}; | ||
const component = mountWithIntl(<LayerPanels {...defaultProps} />); | ||
const firstLayerFocusable = component | ||
.find(LayerPanel) | ||
.first() | ||
.find('section') | ||
.first() | ||
.instance(); | ||
act(() => { | ||
component.find('[data-test-subj="lnsLayerRemove"]').at(2).simulate('click'); | ||
}); | ||
const focusedEl = document.activeElement; | ||
expect(focusedEl).toEqual(firstLayerFocusable); | ||
}); | ||
|
||
it('should focus the added layer', () => { | ||
(generateId as jest.Mock).mockReturnValue(`second`); | ||
const dispatch = jest.fn((x) => { | ||
if (x.subType === 'ADD_LAYER') { | ||
frame.datasourceLayers.second = mockDatasource.publicAPIMock; | ||
} | ||
}); | ||
|
||
const component = mountWithIntl(<LayerPanels {...getDefaultProps()} dispatch={dispatch} />); | ||
act(() => { | ||
component.find('[data-test-subj="lnsLayerAddButton"]').first().simulate('click'); | ||
}); | ||
const focusedEl = document.activeElement; | ||
expect(focusedEl?.children[0].getAttribute('data-test-subj')).toEqual('lns-layerPanel-1'); | ||
}); | ||
}); | ||
}); |
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
5 changes: 5 additions & 0 deletions
5
x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.scss
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.