Skip to content

Commit

Permalink
Make URL for reponsible office optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeininger committed Dec 4, 2023
1 parent 1beeeaa commit 4c74f33
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ const OerebResponsibleOffice = function (props) {
const officeElements = offices.map((office, key) => {
const localizedName = getLocalizedText(office['Name'], currentLanguage, defaultLanguage);
const localizedUrl = getLocalizedText(office['OfficeAtWeb'], currentLanguage, defaultLanguage);
return (
<dd key={key} className="ms-2">
<a href={localizedUrl} target="_blank" rel="noreferrer">
if (localizedUrl === null) {
return (
<dd key={key} className="ms-2">
{localizedName}
</a>
</dd>
);
</dd>
);
}
else {
return (
<dd key={key} className="ms-2">
<a href={localizedUrl} target="_blank" rel="noreferrer">
{localizedName}
</a>
</dd>
);
}
});

return (
Expand Down
6 changes: 4 additions & 2 deletions oereb_client/static/src/util/language.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {isArray} from "lodash";

export const getLocalizedText = function (multilingualText, language, defaultLanguage) {
if (multilingualText.length > 0) {
if (isArray(multilingualText) && multilingualText.length > 0) {
let defaultValue = null;
for (let i = 0; i < multilingualText.length; i++) {
if (multilingualText[i]['Language'] === language) {
Expand All @@ -18,7 +20,7 @@ export const getLocalizedText = function (multilingualText, language, defaultLan
};

export const getLocalizedUrl = function (multilingualUrl, language, defaultLanguage) {
if (multilingualUrl.length > 0) {
if (isArray(multilingualUrl) && multilingualUrl.length > 0) {
let defaultValue = null;
for (let i = 0; i < multilingualUrl.length; i++) {
if (multilingualUrl[i]['Language'] === language) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ exports[`responsible office component > should render responsible office 1`] = `
</dl>
</DocumentFragment>
`;

exports[`responsible office component > should render responsible office without url 1`] = `
<DocumentFragment>
<dl
class="oereb-client-responsible-office border-top pt-2 mb-2"
>
<dt>
extract.topic.responsible_office
</dt>
<dd
class="ms-2"
>
Bundesamt für Verkehr BAV
</dd>
</dl>
</DocumentFragment>
`;
22 changes: 18 additions & 4 deletions test/js/component/responsible_office/responsible_office.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,41 @@ import extract from "../../../../samples/extract.json";

describe('responsible office component', () => {

let component;

beforeEach(() => {
act(() => {
MainStore.dispatch(initLanguages({
default: 'de',
available: ['de']
}));
});
});

it('should render responsible office', () => {
const restrictions = groupRestrictionsByTopic(
extract.GetExtractByIdResponse.extract.RealEstate.RestrictionOnLandownership,
extract.GetExtractByIdResponse.extract.ConcernedTheme
)['chStatischeWaldgrenzen']['inForce'];
component = render(
const component = render(
<Provider store={MainStore}>
<OerebResponsibleOffice restrictions={restrictions} />
</Provider>
);
expect(component.asFragment()).toMatchSnapshot();
});

it('should render responsible office', () => {
it('should render responsible office without url', () => {
const restrictions = groupRestrictionsByTopic(
extract.GetExtractByIdResponse.extract.RealEstate.RestrictionOnLandownership,
extract.GetExtractByIdResponse.extract.ConcernedTheme
)['chStatischeWaldgrenzen']['inForce'];
restrictions.forEach((restriction) => {
restriction['ResponsibleOffice']['OfficeAtWeb'] = null;
});
const component = render(
<Provider store={MainStore}>
<OerebResponsibleOffice restrictions={restrictions} />
</Provider>
);
expect(component.asFragment()).toMatchSnapshot();
});

Expand Down
20 changes: 18 additions & 2 deletions test/js/util/language.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ describe('getLocalizedText', () => {
}
];

it('should return null', () => {
it('should return null for undefined input value', () => {
expect(getLocalizedText(undefined, 'en', 'en')).toBe(null);
});

it('should return null for null as input value', () => {
expect(getLocalizedText(null, 'en', 'en')).toBe(null);
});

it('should return null for empty list', () => {
expect(getLocalizedText([], 'en', 'en')).toBe(null);
});

Expand Down Expand Up @@ -41,7 +49,15 @@ describe('getLocalizedUrl', () => {
}
];

it('should return null', () => {
it('should return null for undefined input value', () => {
expect(getLocalizedUrl(undefined, 'en', 'en')).toBe(null);
});

it('should return null for null as input value', () => {
expect(getLocalizedUrl(null, 'en', 'en')).toBe(null);
});

it('should return null for emtpy list', () => {
expect(getLocalizedUrl([], 'en', 'en')).toBe(null);
});

Expand Down

0 comments on commit 4c74f33

Please sign in to comment.