Skip to content

Commit fa42c51

Browse files
Merge pull request #1506 from geonetwork/backport/2.8.x/pr-1493
[2.8.x] Merge pull request #1493 from geonetwork/dh-reuse-contacts-for-resource
2 parents c7f35f0 + 5ce1a18 commit fa42c51

File tree

3 files changed

+85
-53
lines changed

3 files changed

+85
-53
lines changed

libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
class="!w-5 !h-5 !text-[20px] opacity-75 shrink-0"
8383
name="matPersonOutline"
8484
></ng-icon>
85-
<div class="flex flex-col ml-2">
85+
<div class="flex flex-col ml-2" data-cy="contact-full-name">
8686
<p class="text-sm">
8787
{{ contacts[0]?.firstName || '' }}
8888
{{ contacts[0]?.lastName || '' }}

libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.spec.ts

Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,99 @@ describe('MetadataContactComponent', () => {
1818
beforeEach(() => {
1919
fixture = TestBed.createComponent(MetadataContactComponent)
2020
component = fixture.componentInstance
21-
component.metadata = {
22-
kind: 'dataset',
23-
ownerOrganization: {
24-
name: 'Worldcorp',
25-
website: new URL('https://john.world.co'),
26-
},
27-
contactsForResource: [
28-
{
29-
name: 'john',
30-
organization: 'Worldcorp',
31-
email: 'john@world.co',
32-
website: 'https://john.world.co',
33-
},
34-
{
35-
name: 'billy',
36-
organization: 'small corp',
37-
email: 'billy@small.co',
38-
website: 'https://billy.small.co',
39-
},
40-
],
41-
} as any
42-
fixture.detectChanges()
4321
})
4422

4523
it('should create', () => {
4624
expect(component).toBeTruthy()
4725
})
48-
describe('on contact click', () => {
26+
describe('kind dataset', () => {
4927
beforeEach(() => {
50-
jest.resetAllMocks()
51-
jest.spyOn(component.organizationClick, 'emit')
28+
component.metadata = {
29+
kind: 'dataset',
30+
ownerOrganization: {
31+
name: 'Worldcorp',
32+
website: new URL('https://john.world.co'),
33+
},
34+
contactsForResource: [
35+
{
36+
firstName: 'john',
37+
lastName: 'doe',
38+
organization: 'Worldcorp',
39+
email: 'john@world.co',
40+
website: 'https://john.world.co',
41+
},
42+
{
43+
firstName: 'billy',
44+
lastName: 'smith',
45+
organization: 'small corp',
46+
email: 'billy@small.co',
47+
website: 'https://billy.small.co',
48+
},
49+
],
50+
} as any
51+
fixture.detectChanges()
5252
})
53-
it('emit contact click with contact name', () => {
54-
const el = fixture.debugElement.query(
55-
By.css('[data-cy="organization-name-link"]')
56-
).nativeElement
57-
el.click()
58-
expect(component.organizationClick.emit).toHaveBeenCalledWith({
59-
name: 'Worldcorp',
60-
website: new URL('https://john.world.co'),
53+
describe('on organization click', () => {
54+
beforeEach(() => {
55+
jest.resetAllMocks()
56+
jest.spyOn(component.organizationClick, 'emit')
57+
})
58+
it('emit organization click with organization name', () => {
59+
const el = fixture.debugElement.query(
60+
By.css('[data-cy="organization-name-link"]')
61+
).nativeElement
62+
el.click()
63+
expect(component.organizationClick.emit).toHaveBeenCalledWith({
64+
name: 'Worldcorp',
65+
website: new URL('https://john.world.co'),
66+
})
67+
})
68+
})
69+
describe('content', () => {
70+
let email
71+
beforeEach(() => {
72+
email = fixture.debugElement.queryAll(By.css('a'))[1]
73+
})
74+
it('displays the organization name', () => {
75+
const el = fixture.debugElement.query(
76+
By.css('[data-cy="organization-name-link"]')
77+
).nativeElement
78+
expect(el.innerHTML).toBe(' Worldcorp ')
79+
})
80+
it('displays the contact email', () => {
81+
expect(email.attributes.href).toBe('mailto:john@world.co')
82+
})
83+
it('displays a link to the contact website', () => {
84+
const a = fixture.debugElement.query(By.css('.contact-website'))
85+
expect(a.attributes.href).toBe('https://john.world.co/')
86+
expect(a.attributes.target).toBe('_blank')
6187
})
6288
})
6389
})
64-
describe('content', () => {
65-
let email
90+
91+
describe('kind service', () => {
6692
beforeEach(() => {
67-
email = fixture.debugElement.queryAll(By.css('a'))[1]
68-
})
69-
it('displays the contact name', () => {
70-
const el = fixture.debugElement.query(
71-
By.css('[data-cy="organization-name-link"]')
72-
).nativeElement
73-
expect(el.innerHTML).toBe(' Worldcorp ')
74-
})
75-
it('displays the contact email', () => {
76-
expect(email.attributes.href).toBe('mailto:john@world.co')
93+
component.metadata = {
94+
kind: 'service',
95+
ownerOrganization: {
96+
name: 'Service Corp',
97+
},
98+
contacts: [
99+
{
100+
firstName: 'samantha',
101+
lastName: 'smith',
102+
},
103+
],
104+
} as any
105+
fixture.detectChanges()
77106
})
78-
it('displays a link to the contact website', () => {
79-
const a = fixture.debugElement.query(By.css('.contact-website'))
80-
expect(a.attributes.href).toBe('https://john.world.co/')
81-
expect(a.attributes.target).toBe('_blank')
107+
describe('content', () => {
108+
it('displays the contact name', () => {
109+
const el = fixture.debugElement.query(
110+
By.css('[data-cy="contact-full-name"] > p')
111+
).nativeElement
112+
expect(el.innerHTML).toBe(' samantha smith ')
113+
})
82114
})
83115
})
84116
})

libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export class MetadataContactComponent {
5252

5353
get contacts() {
5454
return (
55-
(this.metadata.kind === 'dataset'
56-
? this.metadata.contactsForResource
57-
: this.metadata.contacts) || []
55+
(this.metadata.kind === 'service'
56+
? this.metadata.contacts
57+
: this.metadata.contactsForResource) || []
5858
)
5959
}
6060

0 commit comments

Comments
 (0)