|
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | + |
| 3 | +import { RegistryProviderDetails } from '@osf/shared/models/provider/registry-provider.model'; |
| 4 | + |
| 5 | +import { MetadataRegistryInfoComponent } from './metadata-registry-info.component'; |
| 6 | + |
| 7 | +import { OSFTestingModule } from '@testing/osf.testing.module'; |
| 8 | + |
| 9 | +describe('MetadataRegistryInfoComponent', () => { |
| 10 | + let component: MetadataRegistryInfoComponent; |
| 11 | + let fixture: ComponentFixture<MetadataRegistryInfoComponent>; |
| 12 | + |
| 13 | + const mockProvider: RegistryProviderDetails = { |
| 14 | + id: 'test-provider-id', |
| 15 | + name: 'Test Registry Provider', |
| 16 | + descriptionHtml: '<p>Test description</p>', |
| 17 | + permissions: [], |
| 18 | + brand: null, |
| 19 | + iri: 'https://example.com/registry', |
| 20 | + reviewsWorkflow: 'standard', |
| 21 | + }; |
| 22 | + |
| 23 | + beforeEach(async () => { |
| 24 | + await TestBed.configureTestingModule({ |
| 25 | + imports: [MetadataRegistryInfoComponent, OSFTestingModule], |
| 26 | + }).compileComponents(); |
| 27 | + |
| 28 | + fixture = TestBed.createComponent(MetadataRegistryInfoComponent); |
| 29 | + component = fixture.componentInstance; |
| 30 | + }); |
| 31 | + |
| 32 | + it('should create', () => { |
| 33 | + expect(component).toBeTruthy(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should initialize with default values', () => { |
| 37 | + expect(component.type()).toBe(''); |
| 38 | + expect(component.provider()).toBeUndefined(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should set type input', () => { |
| 42 | + const mockType = 'Clinical Trial'; |
| 43 | + fixture.componentRef.setInput('type', mockType); |
| 44 | + fixture.detectChanges(); |
| 45 | + |
| 46 | + expect(component.type()).toBe(mockType); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should set provider input', () => { |
| 50 | + fixture.componentRef.setInput('provider', mockProvider); |
| 51 | + fixture.detectChanges(); |
| 52 | + |
| 53 | + expect(component.provider()).toEqual(mockProvider); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should handle undefined type input', () => { |
| 57 | + fixture.componentRef.setInput('type', undefined); |
| 58 | + fixture.detectChanges(); |
| 59 | + |
| 60 | + expect(component.type()).toBeUndefined(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should handle null provider input', () => { |
| 64 | + fixture.componentRef.setInput('provider', null); |
| 65 | + fixture.detectChanges(); |
| 66 | + |
| 67 | + expect(component.provider()).toBeNull(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should render type in template', () => { |
| 71 | + const mockType = 'Preprint'; |
| 72 | + fixture.componentRef.setInput('type', mockType); |
| 73 | + fixture.detectChanges(); |
| 74 | + |
| 75 | + const compiled = fixture.nativeElement; |
| 76 | + const typeElement = compiled.querySelector('[data-test-display-registry-type]'); |
| 77 | + expect(typeElement).toBeTruthy(); |
| 78 | + expect(typeElement.textContent.trim()).toBe(mockType); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should render provider name in template', () => { |
| 82 | + fixture.componentRef.setInput('provider', mockProvider); |
| 83 | + fixture.detectChanges(); |
| 84 | + |
| 85 | + const compiled = fixture.nativeElement; |
| 86 | + const providerElement = compiled.querySelector('[data-test-display-registry-provider]'); |
| 87 | + expect(providerElement).toBeTruthy(); |
| 88 | + expect(providerElement.textContent.trim()).toBe(mockProvider.name); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should display empty string when type is empty', () => { |
| 92 | + fixture.componentRef.setInput('type', ''); |
| 93 | + fixture.detectChanges(); |
| 94 | + |
| 95 | + const compiled = fixture.nativeElement; |
| 96 | + const typeElement = compiled.querySelector('[data-test-display-registry-type]'); |
| 97 | + expect(typeElement.textContent.trim()).toBe(''); |
| 98 | + }); |
| 99 | + |
| 100 | + it('should display empty string when provider is null', () => { |
| 101 | + fixture.componentRef.setInput('provider', null); |
| 102 | + fixture.detectChanges(); |
| 103 | + |
| 104 | + const compiled = fixture.nativeElement; |
| 105 | + const providerElement = compiled.querySelector('[data-test-display-registry-provider]'); |
| 106 | + expect(providerElement.textContent.trim()).toBe(''); |
| 107 | + }); |
| 108 | + |
| 109 | + it('should display both type and provider when both are set', () => { |
| 110 | + const mockType = 'Registered Report'; |
| 111 | + fixture.componentRef.setInput('type', mockType); |
| 112 | + fixture.componentRef.setInput('provider', mockProvider); |
| 113 | + fixture.detectChanges(); |
| 114 | + |
| 115 | + const compiled = fixture.nativeElement; |
| 116 | + const typeElement = compiled.querySelector('[data-test-display-registry-type]'); |
| 117 | + const providerElement = compiled.querySelector('[data-test-display-registry-provider]'); |
| 118 | + |
| 119 | + expect(typeElement.textContent.trim()).toBe(mockType); |
| 120 | + expect(providerElement.textContent.trim()).toBe(mockProvider.name); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should display translated labels', () => { |
| 124 | + fixture.detectChanges(); |
| 125 | + |
| 126 | + const compiled = fixture.nativeElement; |
| 127 | + const headings = compiled.querySelectorAll('h2'); |
| 128 | + expect(headings.length).toBe(2); |
| 129 | + }); |
| 130 | +}); |
0 commit comments