-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(unit-tests): added missing files
- Loading branch information
Rui Nunes
committed
Jul 21, 2022
1 parent
3bf444c
commit ef3fd9c
Showing
23 changed files
with
525 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.add-layer-modal { | ||
|
||
.ant-table-cell { | ||
padding: 0.2rem; | ||
} | ||
|
||
} |
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,9 @@ | ||
import AddLayerModal from './index'; | ||
|
||
describe('<AddLayerModal />', () => { | ||
|
||
it('is defined', () => { | ||
expect(AddLayerModal).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,183 @@ | ||
import React, { | ||
useState | ||
} from 'react'; | ||
|
||
import { | ||
Button, | ||
Input, | ||
Modal, | ||
ModalProps, | ||
notification, | ||
Table | ||
} from 'antd'; | ||
|
||
import { | ||
getUid | ||
} from 'ol'; | ||
import OlLayerGroup from 'ol/layer/Group'; | ||
|
||
import { | ||
useTranslation | ||
} from 'react-i18next'; | ||
|
||
import { | ||
CapabilitiesUtil, | ||
MapUtil | ||
} from '@terrestris/ol-util'; | ||
import { | ||
WMSLayer | ||
} from '@terrestris/ol-util/dist/types'; | ||
|
||
import { | ||
useMap | ||
} from '@terrestris/react-geo/dist/Hook/useMap'; | ||
|
||
import useAppDispatch from '../../hooks/useAppDispatch'; | ||
import useAppSelector from '../../hooks/useAppSelector'; | ||
import { | ||
hide | ||
} from '../../store/addLayerModal'; | ||
import { | ||
unsetSelectedKey | ||
} from '../../store/toolMenu'; | ||
|
||
import './index.less'; | ||
|
||
export type AddLayerModalProps = {} & Partial<ModalProps>; | ||
|
||
export const AddLayerModal: React.FC<AddLayerModalProps> = ({ | ||
...restProps | ||
}): JSX.Element => { | ||
const [loading, setLoading] = useState(false); | ||
const [layers, setLayers] = useState<WMSLayer[]>([]); | ||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]); | ||
const [url, setUrl] = useState( | ||
'https://sgx.geodatenzentrum.de/wms_topplus_open?request=GetCapabilities&service=wms' | ||
); | ||
|
||
const isModalVisible = useAppSelector(state => state.addLayerModal.visible); | ||
|
||
const dispatch = useAppDispatch(); | ||
|
||
const map = useMap(); | ||
|
||
const { | ||
t | ||
} = useTranslation(); | ||
|
||
const getCapabilities = async (capabilitiesUrl: string) => { | ||
try { | ||
setLoading(true); | ||
|
||
const capabilities = await CapabilitiesUtil.getWmsCapabilities(capabilitiesUrl); | ||
const externalLayers = CapabilitiesUtil.getLayersFromWmsCapabilities(capabilities, 'Title'); | ||
|
||
setLayers(externalLayers); | ||
} catch (error) { | ||
notification.error({ | ||
message: t('AddLayerModal.errorMessage'), | ||
description: t('AddLayerModal.errorDescription') | ||
}); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const closeModal = () => { | ||
setSelectedRowKeys([]); | ||
setLayers([]); | ||
dispatch(hide()); | ||
dispatch(unsetSelectedKey('addLayer')); | ||
}; | ||
|
||
const onAddSelected = () => { | ||
const layersToAdd = layers.filter(layer => selectedRowKeys.includes(getUid(layer))); | ||
addLayers(layersToAdd); | ||
}; | ||
|
||
const onAddAll = () => { | ||
addLayers(layers); | ||
}; | ||
|
||
const addLayers = (layersToAdd: WMSLayer[]) => { | ||
if (!map) { | ||
return; | ||
} | ||
|
||
const targetFolderName = t('AddLayerModal.externalWmsFolder'); | ||
let targetGroup = MapUtil.getLayerByName(map, targetFolderName) as OlLayerGroup; | ||
if (!targetGroup) { | ||
targetGroup = new OlLayerGroup(); | ||
targetGroup.set('name', targetFolderName); | ||
const existingGroups = map.getLayerGroup().getLayers(); | ||
existingGroups.insertAt(existingGroups?.getLength() || 0, targetGroup); | ||
} | ||
|
||
layersToAdd.forEach(layerToAdd => { | ||
if (!targetGroup.getLayers().getArray().includes(layerToAdd)) { | ||
layerToAdd.set('isExternalLayer', true); | ||
targetGroup.getLayers().push(layerToAdd); | ||
} | ||
}); | ||
|
||
targetGroup.set('hideInLayerTree', targetGroup.getLayers().getLength() < 1); | ||
|
||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
className="add-layer-modal" | ||
title={t('AddLayerModal.title')} | ||
visible={isModalVisible} | ||
onCancel={closeModal} | ||
footer={[ | ||
<Button | ||
key="add-selected" | ||
disabled={selectedRowKeys?.length < 1} | ||
onClick={onAddSelected} | ||
> | ||
{t('AddLayerModal.addSelectedLayers')} | ||
</Button>, | ||
<Button | ||
key="add-all" | ||
disabled={layers?.length < 1} | ||
onClick={onAddAll} | ||
> | ||
{t('AddLayerModal.addAllLayers')} | ||
</Button> | ||
]} | ||
{...restProps} | ||
> | ||
<Input.Search | ||
placeholder={t('AddLayerModal.inputPlaceholder')} | ||
value={url} | ||
onChange={(event) => { | ||
setUrl(event.target.value); | ||
}} | ||
onSearch={getCapabilities} | ||
enterButton={true} | ||
/> | ||
<Table | ||
loading={loading} | ||
columns={[ | ||
{ | ||
title: t('AddLayerModal.columnTitle'), | ||
render: (text: any, record: any) => { | ||
return record.get('title'); | ||
} | ||
} | ||
]} | ||
rowKey={(record: any) => getUid(record)} | ||
rowSelection={{ | ||
selectedRowKeys, | ||
onChange: setSelectedRowKeys | ||
}} | ||
pagination={false} | ||
dataSource={layers} | ||
/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default AddLayerModal; |
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,9 @@ | ||
import ApplicationInfo from './index'; | ||
|
||
describe('<ApplicationInfo />', () => { | ||
|
||
it('is defined', () => { | ||
expect(ApplicationInfo).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import BasicMapComponent from './index'; | ||
|
||
describe('<BasicMapComponent />', () => { | ||
|
||
it('is defined', () => { | ||
expect(BasicMapComponent).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import BasicNominatimSearch from './index'; | ||
|
||
describe('<BasicNominatimSearch />', () => { | ||
|
||
it('is defined', () => { | ||
expect(BasicNominatimSearch).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import Footer from './index'; | ||
|
||
describe('<Footer />', () => { | ||
|
||
it('is defined', () => { | ||
expect(Footer).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import Header from './index'; | ||
|
||
describe('<Header />', () => { | ||
|
||
it('is defined', () => { | ||
expect(Header).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import LanguageSelector from './index'; | ||
|
||
describe('<LanguageSelector />', () => { | ||
|
||
it('is defined', () => { | ||
expect(LanguageSelector).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import Permalink from './index'; | ||
|
||
describe('<Permalink />', () => { | ||
|
||
it('is defined', () => { | ||
expect(Permalink).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import CustomFieldInput from './index'; | ||
|
||
describe('<CustomFieldInput />', () => { | ||
|
||
it('is defined', () => { | ||
expect(CustomFieldInput).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import LayoutSelect from './index'; | ||
|
||
describe('<LayoutSelect />', () => { | ||
|
||
it('is defined', () => { | ||
expect(LayoutSelect).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import OutputFormatSelect from './index'; | ||
|
||
describe('<OutputFormatSelect />', () => { | ||
|
||
it('is defined', () => { | ||
expect(OutputFormatSelect).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import ResolutionSelect from './index'; | ||
|
||
describe('<ResolutionSelect />', () => { | ||
|
||
it('is defined', () => { | ||
expect(ResolutionSelect).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
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,9 @@ | ||
import PrintForm from './index'; | ||
|
||
describe('<PrintForm />', () => { | ||
|
||
it('is defined', () => { | ||
expect(PrintForm).not.toBeUndefined(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.