forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplain-text-metadata-list-element.component.spec.ts
More file actions
118 lines (105 loc) · 4.61 KB
/
Copy pathplain-text-metadata-list-element.component.spec.ts
File metadata and controls
118 lines (105 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import {
ChangeDetectionStrategy,
NO_ERRORS_SCHEMA,
} from '@angular/core';
import {
ComponentFixture,
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
import { ActivatedRouteStub } from '../../../testing/active-router.stub';
import { mockData } from '../../../testing/browse-definition-data-service.stub';
import { PlainTextMetadataListElementComponent } from './plain-text-metadata-list-element.component';
// Render the mock representation with the default mock author browse definition so it is also rendered as a link
// without affecting other tests
const mockMetadataRepresentation = Object.assign(new MetadatumRepresentation('type', mockData[1]), {
key: 'dc.contributor.author',
value: 'Test Author',
});
describe('PlainTextMetadataListElementComponent', () => {
let comp: PlainTextMetadataListElementComponent;
let fixture: ComponentFixture<PlainTextMetadataListElementComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [PlainTextMetadataListElementComponent],
providers: [{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() }],
schemas: [NO_ERRORS_SCHEMA],
}).overrideComponent(PlainTextMetadataListElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default },
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(PlainTextMetadataListElementComponent);
comp = fixture.componentInstance;
comp.mdRepresentation = mockMetadataRepresentation;
fixture.detectChanges();
}));
it('should contain the value as plain text', () => {
expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentation.value);
});
it('should contain the browse link as plain text', () => {
expect(fixture.debugElement.query(By.css('a.ds-browse-link')).nativeElement.innerHTML).toContain(mockMetadataRepresentation.value);
});
it('should correctly detect ORCID authority', () => {
const orcidRepresentation = Object.assign(new MetadatumRepresentation('type'), {
key: 'dc.contributor.author',
value: 'John Doe',
authority: '0000-0002-1825-0097',
confidence: 600,
});
comp.mdRepresentation = orcidRepresentation;
expect(comp.isOrcidAuthority()).toBe(true);
});
it('should return false for non-ORCID authority', () => {
const nonOrcidRepresentation = Object.assign(new MetadatumRepresentation('type'), {
key: 'dc.contributor.author',
value: 'Jane Smith',
authority: 'not-an-orcid',
confidence: 600,
});
comp.mdRepresentation = nonOrcidRepresentation;
expect(comp.isOrcidAuthority()).toBe(false);
});
it('should generate correct ORCID profile URL', () => {
const orcidRepresentation = Object.assign(new MetadatumRepresentation('type'), {
key: 'dc.contributor.author',
value: 'John Doe',
authority: '0000-0002-1825-0097',
confidence: 600,
});
comp.mdRepresentation = orcidRepresentation;
expect(comp.getOrcidUrl()).toBe('https://orcid.org/0000-0002-1825-0097');
});
it('should render ORCID link and badge for authority controlled metadata with ORCID', () => {
const orcidRepresentation = Object.assign(new MetadatumRepresentation('type'), {
key: 'dc.contributor.author',
value: 'John Doe',
authority: '0000-0002-1825-0097',
confidence: 600,
});
comp.mdRepresentation = orcidRepresentation;
fixture.detectChanges();
const orcidLink = fixture.debugElement.query(By.css('a.orcid-link'));
expect(orcidLink).toBeTruthy();
expect(orcidLink.nativeElement.getAttribute('href')).toBe('https://orcid.org/0000-0002-1825-0097');
expect(orcidLink.nativeElement.textContent).toContain('John Doe');
const orcidBadge = fixture.debugElement.query(By.css('a.orcid-badge'));
expect(orcidBadge).toBeTruthy();
});
it('should render plain text for authority controlled metadata without ORCID', () => {
const nonOrcidRepresentation = Object.assign(new MetadatumRepresentation('type'), {
key: 'dc.contributor.author',
value: 'Jane Smith',
authority: 'some-other-authority',
confidence: 600,
});
comp.mdRepresentation = nonOrcidRepresentation;
fixture.detectChanges();
const orcidLink = fixture.debugElement.query(By.css('a.orcid-link'));
expect(orcidLink).toBeFalsy();
expect(fixture.nativeElement.textContent).toContain('Jane Smith');
});
});