11import { ChangeDetectionStrategy , NO_ERRORS_SCHEMA } from '@angular/core' ;
22import { By } from '@angular/platform-browser' ;
33import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
4+ import { TranslateModule } from '@ngx-translate/core' ;
45
56import { ConfigurationDataService } from '../../../../core/data/configuration-data.service' ;
67import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model' ;
@@ -34,9 +35,12 @@ const mockOrcidWithWhitespaceRepresentation = Object.assign(new MetadatumReprese
3435} ) ;
3536
3637const mockConfigurationDataService = {
37- findByPropertyName : jasmine . createSpy ( 'findByPropertyName' ) . and . returnValue (
38- createSuccessfulRemoteDataObject$ ( { values : [ 'https://orcid.org' ] } ) ,
39- ) ,
38+ findByPropertyName : jasmine . createSpy ( 'findByPropertyName' ) . and . callFake ( ( property : string ) => {
39+ if ( property === 'orcid.author.link-target' ) {
40+ return createSuccessfulRemoteDataObject$ ( { values : [ 'browse' ] } ) ;
41+ }
42+ return createSuccessfulRemoteDataObject$ ( { values : [ 'https://orcid.org' ] } ) ;
43+ } ) ,
4044} ;
4145
4246describe ( 'PlainTextMetadataListElementComponent' , ( ) => {
@@ -45,7 +49,7 @@ describe('PlainTextMetadataListElementComponent', () => {
4549
4650 beforeEach ( waitForAsync ( ( ) => {
4751 TestBed . configureTestingModule ( {
48- imports : [ ] ,
52+ imports : [ TranslateModule . forRoot ( ) ] ,
4953 declarations : [ PlainTextMetadataListElementComponent ] ,
5054 providers : [
5155 { provide : ConfigurationDataService , useValue : mockConfigurationDataService } ,
@@ -74,6 +78,7 @@ describe('PlainTextMetadataListElementComponent', () => {
7478 describe ( 'when metadata has ORCID authority' , ( ) => {
7579 beforeEach ( ( ) => {
7680 comp . mdRepresentation = mockOrcidRepresentation ;
81+ comp . authorOrcidLinkTarget$ . next ( 'orcid' ) ;
7782 fixture . detectChanges ( ) ;
7883 } ) ;
7984
@@ -90,11 +95,11 @@ describe('PlainTextMetadataListElementComponent', () => {
9095 } ) ;
9196
9297 it ( 'isOrcidAuthority should return true' , ( ) => {
93- expect ( comp . isOrcidAuthority ( comp . orcidDomainUrl$ . value ) ) . toBeTrue ( ) ;
98+ expect ( comp . isOrcidAuthority ( ) ) . toBeTrue ( ) ;
9499 } ) ;
95100
96101 it ( 'getOrcidUrl should return full ORCID URL' , ( ) => {
97- expect ( comp . getOrcidUrl ( comp . orcidDomainUrl$ . value ) ) . toBe ( 'https://orcid.org/1234-5678-9012-3456' ) ;
102+ expect ( comp . getOrcidUrl ( ) ) . toBe ( 'https://orcid.org/1234-5678-9012-3456' ) ;
98103 } ) ;
99104 } ) ;
100105
@@ -116,21 +121,21 @@ describe('PlainTextMetadataListElementComponent', () => {
116121 } ) ;
117122
118123 it ( 'isOrcidAuthority should return false' , ( ) => {
119- expect ( comp . isOrcidAuthority ( comp . orcidDomainUrl$ . value ) ) . toBeFalse ( ) ;
124+ expect ( comp . isOrcidAuthority ( ) ) . toBeFalse ( ) ;
120125 } ) ;
121126 } ) ;
122127
123128 describe ( 'getOrcidUrl with trailing slash handling' , ( ) => {
124129 it ( 'should not double-slash when domain URL ends with /' , ( ) => {
125130 comp . orcidDomainUrl$ . next ( 'https://orcid.org/' ) ;
126131 comp . mdRepresentation = mockOrcidRepresentation ;
127- expect ( comp . getOrcidUrl ( 'https://orcid.org/' ) ) . toBe ( 'https://orcid.org/1234-5678-9012-3456' ) ;
132+ expect ( comp . getOrcidUrl ( ) ) . toBe ( 'https://orcid.org/1234-5678-9012-3456' ) ;
128133 } ) ;
129134
130135 it ( 'should add slash when domain URL does not end with /' , ( ) => {
131136 comp . orcidDomainUrl$ . next ( 'https://sandbox.orcid.org' ) ;
132137 comp . mdRepresentation = mockOrcidRepresentation ;
133- expect ( comp . getOrcidUrl ( 'https://sandbox.orcid.org' ) ) . toBe ( 'https://sandbox.orcid.org/1234-5678-9012-3456' ) ;
138+ expect ( comp . getOrcidUrl ( ) ) . toBe ( 'https://sandbox.orcid.org/1234-5678-9012-3456' ) ;
134139 } ) ;
135140 } ) ;
136141
@@ -147,25 +152,25 @@ describe('PlainTextMetadataListElementComponent', () => {
147152 } ) ;
148153
149154 it ( 'isOrcidAuthority should return false' , ( ) => {
150- expect ( comp . isOrcidAuthority ( comp . orcidDomainUrl$ . value ) ) . toBeFalse ( ) ;
155+ expect ( comp . isOrcidAuthority ( ) ) . toBeFalse ( ) ;
151156 } ) ;
152157
153158 it ( 'getOrcidUrl should return empty string' , ( ) => {
154- expect ( comp . getOrcidUrl ( comp . orcidDomainUrl$ . value ) ) . toBe ( '' ) ;
159+ expect ( comp . getOrcidUrl ( ) ) . toBe ( '' ) ;
155160 } ) ;
156161 } ) ;
157162
158163 describe ( 'getOrcidUrl defensive behavior' , ( ) => {
159164 it ( 'should return empty string when orcidDomainUrl is null' , ( ) => {
160165 comp . orcidDomainUrl$ . next ( null ) ;
161166 comp . mdRepresentation = mockOrcidRepresentation ;
162- expect ( comp . getOrcidUrl ( null ) ) . toBe ( '' ) ;
167+ expect ( comp . getOrcidUrl ( ) ) . toBe ( '' ) ;
163168 } ) ;
164169
165170 it ( 'should return empty string when mdRepresentation has no authority' , ( ) => {
166171 comp . orcidDomainUrl$ . next ( 'https://orcid.org' ) ;
167172 comp . mdRepresentation = mockMetadataRepresentation ;
168- expect ( comp . getOrcidUrl ( 'https://orcid.org' ) ) . toBe ( '' ) ;
173+ expect ( comp . getOrcidUrl ( ) ) . toBe ( '' ) ;
169174 } ) ;
170175 } ) ;
171176
@@ -177,11 +182,11 @@ describe('PlainTextMetadataListElementComponent', () => {
177182 } ) ;
178183
179184 it ( 'isOrcidAuthority should return true after trimming' , ( ) => {
180- expect ( comp . isOrcidAuthority ( comp . orcidDomainUrl$ . value ) ) . toBeTrue ( ) ;
185+ expect ( comp . isOrcidAuthority ( ) ) . toBeTrue ( ) ;
181186 } ) ;
182187
183188 it ( 'getOrcidUrl should return trimmed ORCID URL' , ( ) => {
184- expect ( comp . getOrcidUrl ( comp . orcidDomainUrl$ . value ) ) . toBe ( 'https://orcid.org/1234-5678-9012-3456' ) ;
189+ expect ( comp . getOrcidUrl ( ) ) . toBe ( 'https://orcid.org/1234-5678-9012-3456' ) ;
185190 } ) ;
186191 } ) ;
187192} ) ;
0 commit comments