diff --git a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts index 4fefa85b20..6a96feee92 100644 --- a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts +++ b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.spec.ts @@ -96,7 +96,6 @@ describe('Gn4MetadataMapper', () => { website: new URL('http://my.org'), }, status: null, - updateFrequency: null, lineage: null, recordUpdated: null, distributions: [], @@ -136,7 +135,6 @@ describe('Gn4MetadataMapper', () => { website: new URL('http://my.org'), }, status: null, - updateFrequency: null, lineage: null, recordUpdated: null, distributions: [], diff --git a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts index 9f782429fe..2870353baf 100644 --- a/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts +++ b/libs/api/metadata-converter/src/lib/gn4/gn4.metadata.mapper.ts @@ -22,7 +22,6 @@ export class Gn4MetadataMapper extends MetadataBaseMapper { const emptyRecord: Partial = { kind: 'dataset', status: null, - updateFrequency: null, lineage: null, recordUpdated: null, ownerOrganization: null, diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts index effeced84f..a1800f59e0 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.spec.ts @@ -93,6 +93,22 @@ describe('MetadataInfoComponent', () => { }) }) describe('updateFrequency', () => { + describe('updateFrequency is not defined', () => { + beforeEach(() => { + fixture = TestBed.createComponent(MetadataInfoComponent) + component = fixture.componentInstance + component.metadata = { + ...DATASET_RECORDS[0], + updateFrequency: undefined, + } + fixture.detectChanges() + }) + it('should not display the updateFrequency section', () => { + const displayedElement = + fixture.nativeElement.querySelector('.updateFrequency') + expect(displayedElement).toBeFalsy() + }) + }) describe('updateFrequency as UpdateFrequencyCode', () => { beforeEach(() => { fixture = TestBed.createComponent(MetadataInfoComponent) diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts index 18b1990b20..f74ea4df78 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts @@ -42,8 +42,10 @@ export class MetadataInfoComponent { if (this.metadata.updateFrequency instanceof Object) { this.updatedTimes = this.metadata.updateFrequency.updatedTimes return `domain.record.updateFrequency.${this.metadata.updateFrequency.per}` - } else { + } else if (typeof this.metadata.updateFrequency === 'string') { return `domain.record.updateFrequency.${this.metadata.updateFrequency}` + } else { + return undefined } } diff --git a/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts b/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts index 20b5459045..4f21470524 100644 --- a/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts +++ b/libs/util/shared/src/lib/utils/remove-whitespace.spec.ts @@ -1,6 +1,10 @@ import { removeWhitespace } from './remove-whitespace' describe('#removeWhitespace', () => { + it('returns undefined input is not defined', () => { + const html = null + expect(removeWhitespace(html)).toBe(undefined) + }) it('removes superfluent whitespace for a single word', () => { const html = ' hello ' expect(removeWhitespace(html)).toBe('hello') diff --git a/libs/util/shared/src/lib/utils/remove-whitespace.ts b/libs/util/shared/src/lib/utils/remove-whitespace.ts index c9dffa3aa5..053514cd52 100644 --- a/libs/util/shared/src/lib/utils/remove-whitespace.ts +++ b/libs/util/shared/src/lib/utils/remove-whitespace.ts @@ -1,3 +1,3 @@ export const removeWhitespace = function (str: string): string { - return str.replace(/\s+/g, ' ').trim() + return str?.replace(/\s+/g, ' ').trim() } diff --git a/libs/util/shared/src/lib/utils/strip-html.spec.ts b/libs/util/shared/src/lib/utils/strip-html.spec.ts index 1e0a44cf15..c72b4ee071 100644 --- a/libs/util/shared/src/lib/utils/strip-html.spec.ts +++ b/libs/util/shared/src/lib/utils/strip-html.spec.ts @@ -7,6 +7,12 @@ describe('strip HTML', () => { expect(stripHtml(html)).toBe('hello') }) }) + describe('when HTML not defined', () => { + it('returns undefined', () => { + const html = null + expect(stripHtml(html)).toBe(undefined) + }) + }) describe('when no HTML tags', () => { it('return same string', () => { const html = 'hello' diff --git a/libs/util/shared/src/lib/utils/strip-html.ts b/libs/util/shared/src/lib/utils/strip-html.ts index 5e5b8bf527..14170efd71 100644 --- a/libs/util/shared/src/lib/utils/strip-html.ts +++ b/libs/util/shared/src/lib/utils/strip-html.ts @@ -1,4 +1,5 @@ export const stripHtml = function (html: string): string { + if (!html) return undefined const doc = new DOMParser().parseFromString(html, 'text/html') return doc.body.textContent || '' }