Skip to content

Commit

Permalink
chore(unit-tests): added missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Nunes committed Jul 21, 2022
1 parent 3bf444c commit ef3fd9c
Show file tree
Hide file tree
Showing 23 changed files with 525 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/AddLayerModal/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.add-layer-modal {

.ant-table-cell {
padding: 0.2rem;
}

}
9 changes: 9 additions & 0 deletions src/components/AddLayerModal/index.spec.tsx
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();
});

});
183 changes: 183 additions & 0 deletions src/components/AddLayerModal/index.tsx
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;
9 changes: 9 additions & 0 deletions src/components/ApplicationInfo/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/BasicMapComponent/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/BasicNominatimSearch/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/Footer/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/Header/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/LanguageSelector/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/Permalink/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/PrintForm/CustomFieldInput/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/PrintForm/LayoutSelect/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/PrintForm/OutputFormatSelect/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/PrintForm/ResolutionSelect/index.spec.tsx
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();
});

});
9 changes: 9 additions & 0 deletions src/components/PrintForm/index.spec.tsx
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();
});

});
Loading

0 comments on commit ef3fd9c

Please sign in to comment.