Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datahub (fix): Handle UpdateFrequency not defined #693

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 || ''
}
Loading