-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmetadata-registry-info.component.spec.ts
More file actions
130 lines (100 loc) · 4.27 KB
/
metadata-registry-info.component.spec.ts
File metadata and controls
130 lines (100 loc) · 4.27 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
119
120
121
122
123
124
125
126
127
128
129
130
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RegistryProviderDetails } from '@osf/shared/models/provider/registry-provider.model';
import { MetadataRegistryInfoComponent } from './metadata-registry-info.component';
import { OSFTestingModule } from '@testing/osf.testing.module';
describe('MetadataRegistryInfoComponent', () => {
let component: MetadataRegistryInfoComponent;
let fixture: ComponentFixture<MetadataRegistryInfoComponent>;
const mockProvider: RegistryProviderDetails = {
id: 'test-provider-id',
name: 'Test Registry Provider',
descriptionHtml: '<p>Test description</p>',
permissions: [],
brand: null,
iri: 'https://example.com/registry',
reviewsWorkflow: 'standard',
};
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataRegistryInfoComponent, OSFTestingModule],
}).compileComponents();
fixture = TestBed.createComponent(MetadataRegistryInfoComponent);
component = fixture.componentInstance;
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should initialize with default values', () => {
expect(component.type()).toBe('');
expect(component.provider()).toBeUndefined();
});
it('should set type input', () => {
const mockType = 'Clinical Trial';
fixture.componentRef.setInput('type', mockType);
fixture.detectChanges();
expect(component.type()).toBe(mockType);
});
it('should set provider input', () => {
fixture.componentRef.setInput('provider', mockProvider);
fixture.detectChanges();
expect(component.provider()).toEqual(mockProvider);
});
it('should handle undefined type input', () => {
fixture.componentRef.setInput('type', undefined);
fixture.detectChanges();
expect(component.type()).toBeUndefined();
});
it('should handle null provider input', () => {
fixture.componentRef.setInput('provider', null);
fixture.detectChanges();
expect(component.provider()).toBeNull();
});
it('should render type in template', () => {
const mockType = 'Preprint';
fixture.componentRef.setInput('type', mockType);
fixture.detectChanges();
const compiled = fixture.nativeElement;
const typeElement = compiled.querySelector('[data-test-display-registry-type]');
expect(typeElement).toBeTruthy();
expect(typeElement.textContent.trim()).toBe(mockType);
});
it('should render provider name in template', () => {
fixture.componentRef.setInput('provider', mockProvider);
fixture.detectChanges();
const compiled = fixture.nativeElement;
const providerElement = compiled.querySelector('[data-test-display-registry-provider]');
expect(providerElement).toBeTruthy();
expect(providerElement.textContent.trim()).toBe(mockProvider.name);
});
it('should display empty string when type is empty', () => {
fixture.componentRef.setInput('type', '');
fixture.detectChanges();
const compiled = fixture.nativeElement;
const typeElement = compiled.querySelector('[data-test-display-registry-type]');
expect(typeElement.textContent.trim()).toBe('');
});
it('should display empty string when provider is null', () => {
fixture.componentRef.setInput('provider', null);
fixture.detectChanges();
const compiled = fixture.nativeElement;
const providerElement = compiled.querySelector('[data-test-display-registry-provider]');
expect(providerElement.textContent.trim()).toBe('');
});
it('should display both type and provider when both are set', () => {
const mockType = 'Registered Report';
fixture.componentRef.setInput('type', mockType);
fixture.componentRef.setInput('provider', mockProvider);
fixture.detectChanges();
const compiled = fixture.nativeElement;
const typeElement = compiled.querySelector('[data-test-display-registry-type]');
const providerElement = compiled.querySelector('[data-test-display-registry-provider]');
expect(typeElement.textContent.trim()).toBe(mockType);
expect(providerElement.textContent.trim()).toBe(mockProvider.name);
});
it('should display translated labels', () => {
fixture.detectChanges();
const compiled = fixture.nativeElement;
const headings = compiled.querySelectorAll('h2');
expect(headings.length).toBe(2);
});
});