-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:opensearch-project/dashboards-maps …
…into binary-install
- Loading branch information
Showing
31 changed files
with
588 additions
and
125 deletions.
There are no files selected for viewing
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
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
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
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
113 changes: 113 additions & 0 deletions
113
public/components/layer_config/layer_basic_settings.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,113 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { LayerBasicSettings } from './layer_basic_settings'; | ||
import { MapLayerSpecification } from '../../model/mapLayerType'; | ||
import { DASHBOARDS_MAPS_LAYER_TYPE, MAX_LAYER_NAME_LIMIT } from '../../../common'; | ||
import { shallow } from 'enzyme'; | ||
import { EuiDualRange, EuiFieldText, EuiFormRow, EuiRange, EuiTextArea } from '@elastic/eui'; | ||
|
||
describe('LayerBasicSettings', () => { | ||
let wrapper: any; | ||
const mockLayerConfig: MapLayerSpecification = { | ||
name: 'Test Layer', | ||
id: 'test-layer', | ||
type: DASHBOARDS_MAPS_LAYER_TYPE.OPENSEARCH_MAP, | ||
description: 'Some description', | ||
zoomRange: [1, 20], | ||
visibility: 'visible', | ||
opacity: 80, | ||
}; | ||
|
||
const mockProps = { | ||
selectedLayerConfig: mockLayerConfig, | ||
setSelectedLayerConfig: jest.fn(), | ||
setIsUpdateDisabled: jest.fn(), | ||
isLayerExists: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<LayerBasicSettings {...mockProps} />); | ||
}); | ||
|
||
it('should render with correct props', () => { | ||
expect(wrapper.find(EuiFieldText).prop('value')).toBe(mockLayerConfig.name); | ||
expect(wrapper.find(EuiTextArea).prop('value')).toBe(mockLayerConfig.description); | ||
expect(wrapper.find(EuiDualRange).prop('value')).toEqual(mockLayerConfig.zoomRange); | ||
expect(wrapper.find(EuiRange).prop('value')).toEqual(mockLayerConfig.opacity); | ||
}); | ||
|
||
it('should call setSelectedLayerConfig with updated zoom range on zoom level change', () => { | ||
const newZoomRange = [2, 15]; | ||
wrapper.find(EuiDualRange).simulate('change', newZoomRange); | ||
|
||
expect(mockProps.setSelectedLayerConfig).toHaveBeenCalledWith({ | ||
...mockLayerConfig, | ||
zoomRange: newZoomRange, | ||
}); | ||
}); | ||
|
||
it('should call setSelectedLayerConfig with updated opacity on opacity change', () => { | ||
const newOpacity = 50; | ||
wrapper.find(EuiRange).simulate('change', { target: { value: newOpacity.toString() } }); | ||
|
||
expect(mockProps.setSelectedLayerConfig).toHaveBeenCalledWith({ | ||
...mockLayerConfig, | ||
opacity: newOpacity, | ||
}); | ||
}); | ||
|
||
it('should call setSelectedLayerConfig with updated name on name change', () => { | ||
const newName = 'Updated Test Layer'; | ||
wrapper.find(EuiFieldText).simulate('change', { target: { value: newName } }); | ||
|
||
expect(mockProps.setSelectedLayerConfig).toHaveBeenCalledWith({ | ||
...mockLayerConfig, | ||
name: newName, | ||
}); | ||
}); | ||
|
||
it('should call setSelectedLayerConfig with updated description on description change', () => { | ||
const newDescription = 'Updated description'; | ||
wrapper.find(EuiTextArea).simulate('change', { target: { value: newDescription } }); | ||
|
||
expect(mockProps.setSelectedLayerConfig).toHaveBeenCalledWith({ | ||
...mockLayerConfig, | ||
description: newDescription, | ||
}); | ||
}); | ||
|
||
it('should display an error for an empty name', () => { | ||
mockProps.isLayerExists.mockReturnValue(false); // Ensure this returns false for this test | ||
const emptyName = ''; | ||
wrapper.find(EuiFieldText).simulate('change', { target: { value: emptyName } }); | ||
|
||
wrapper.update(); | ||
|
||
expect(wrapper.find(EuiFormRow).first().prop('error')).toContain('Name cannot be empty'); | ||
}); | ||
|
||
it('should display an error for a name exceeding the maximum length', () => { | ||
const longName = 'a'.repeat(MAX_LAYER_NAME_LIMIT + 1); // Create a name longer than MAX_LAYER_NAME_LIMIT | ||
wrapper.find(EuiFieldText).simulate('change', { target: { value: longName } }); | ||
|
||
wrapper.update(); | ||
|
||
expect(wrapper.find(EuiFormRow).first().prop('error')).toContain( | ||
`Name should be less than ${MAX_LAYER_NAME_LIMIT} characters` | ||
); | ||
}); | ||
|
||
it('should display an error for a name that already exists', () => { | ||
mockProps.isLayerExists.mockReturnValue(true); // Simulate that the name already exists | ||
const existingName = 'Existing Layer Name'; | ||
wrapper.find(EuiFieldText).simulate('change', { target: { value: existingName } }); | ||
|
||
wrapper.update(); | ||
|
||
expect(wrapper.find(EuiFormRow).first().prop('error')).toContain('Name already exists'); | ||
}); | ||
}); |
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
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.