Skip to content

Commit

Permalink
Merge pull request geonetwork#693 from geonetwork/updateFrequency-und…
Browse files Browse the repository at this point in the history
…efined

Datahub (fix): Handle UpdateFrequency not defined
  • Loading branch information
tkohr authored Nov 22, 2023
2 parents bd29f62 + fa4dc70 commit 36a3f6c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ describe('Gn4MetadataMapper', () => {
website: new URL('http://my.org'),
},
status: null,
updateFrequency: null,
lineage: null,
recordUpdated: null,
distributions: [],
Expand Down Expand Up @@ -136,7 +135,6 @@ describe('Gn4MetadataMapper', () => {
website: new URL('http://my.org'),
},
status: null,
updateFrequency: null,
lineage: null,
recordUpdated: null,
distributions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class Gn4MetadataMapper extends MetadataBaseMapper<Gn4Record> {
const emptyRecord: Partial<CatalogRecord> = {
kind: 'dataset',
status: null,
updateFrequency: null,
lineage: null,
recordUpdated: null,
ownerOrganization: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 4 additions & 0 deletions libs/util/shared/src/lib/utils/remove-whitespace.spec.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion libs/util/shared/src/lib/utils/remove-whitespace.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const removeWhitespace = function (str: string): string {
return str.replace(/\s+/g, ' ').trim()
return str?.replace(/\s+/g, ' ').trim()
}
6 changes: 6 additions & 0 deletions libs/util/shared/src/lib/utils/strip-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions libs/util/shared/src/lib/utils/strip-html.ts
Original file line number Diff line number Diff line change
@@ -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 || ''
}

0 comments on commit 36a3f6c

Please sign in to comment.