88 waitForAsync ,
99} from '@angular/core/testing' ;
1010import { By } from '@angular/platform-browser' ;
11+ import { ActivatedRoute } from '@angular/router' ;
12+ import { RouterTestingModule } from '@angular/router/testing' ;
1113import { APP_CONFIG } from '@dspace/config/app-config.interface' ;
1214import { buildPaginatedList } from '@dspace/core/data/paginated-list.model' ;
1315import { MetadataValue } from '@dspace/core/shared/metadata.models' ;
@@ -28,18 +30,10 @@ let comp: MetadataValuesComponent;
2830let fixture : ComponentFixture < MetadataValuesComponent > ;
2931
3032const mockMetadata = [
31- {
32- language : 'en_US' ,
33- value : '1234' ,
34- } ,
35- {
36- language : 'en_US' ,
37- value : 'a publisher' ,
38- } ,
39- {
40- language : 'en_US' ,
41- value : 'desc' ,
42- } ] as MetadataValue [ ] ;
33+ { language : 'en_US' , value : '1234' } ,
34+ { language : 'en_US' , value : 'a publisher' } ,
35+ { language : 'en_US' , value : 'desc' } ,
36+ ] as MetadataValue [ ] ;
4337const mockSeperator = '<br/>' ;
4438const mockLabel = 'fake.message' ;
4539const vocabularyServiceMock = {
@@ -58,15 +52,28 @@ const controlledMetadata = {
5852describe ( 'MetadataValuesComponent' , ( ) => {
5953 beforeEach ( waitForAsync ( ( ) => {
6054 TestBed . configureTestingModule ( {
61- imports : [ TranslateModule . forRoot ( {
62- loader : {
63- provide : TranslateLoader ,
64- useClass : TranslateLoaderMock ,
65- } ,
66- } ) , MetadataValuesComponent ] ,
55+ imports : [
56+ RouterTestingModule . withRoutes ( [ ] ) ,
57+ TranslateModule . forRoot ( {
58+ loader : {
59+ provide : TranslateLoader ,
60+ useClass : TranslateLoaderMock ,
61+ } ,
62+ } ) ,
63+ MetadataValuesComponent ,
64+ ] ,
6765 providers : [
6866 { provide : APP_CONFIG , useValue : environment } ,
6967 { provide : VocabularyService , useValue : vocabularyServiceMock } ,
68+ {
69+ provide : ActivatedRoute ,
70+ useValue : {
71+ snapshot : { } ,
72+ params : of ( { } ) ,
73+ queryParams : of ( { } ) ,
74+ data : of ( { } ) ,
75+ } ,
76+ } ,
7077 ] ,
7178 schemas : [ NO_ERRORS_SCHEMA ] ,
7279 } ) . overrideComponent ( MetadataValuesComponent , {
@@ -103,43 +110,48 @@ describe('MetadataValuesComponent', () => {
103110
104111 it ( 'should return correct target and rel for internal links' , ( ) => {
105112 spyOn ( comp , 'hasInternalLink' ) . and . returnValue ( true ) ;
106- const urlValue = '/internal-link' ;
107- const result = comp . getLinkAttributes ( urlValue ) ;
113+ const result = comp . getLinkAttributes ( '/internal-link' ) ;
108114 expect ( result . target ) . toBe ( '_self' ) ;
109115 expect ( result . rel ) . toBe ( '' ) ;
110116 } ) ;
111117
112118 it ( 'should return correct target and rel for external links' , ( ) => {
113119 spyOn ( comp , 'hasInternalLink' ) . and . returnValue ( false ) ;
114- const urlValue = 'https://www.dspace.org' ;
115- const result = comp . getLinkAttributes ( urlValue ) ;
120+ const result = comp . getLinkAttributes ( 'https://www.dspace.org' ) ;
116121 expect ( result . target ) . toBe ( '_blank' ) ;
117122 expect ( result . rel ) . toBe ( 'noopener noreferrer' ) ;
118123 } ) ;
119124
120125 it ( 'should detect controlled vocabulary metadata' , ( ) => {
121- const result = comp . isControlledVocabulary ( controlledMetadata ) ;
122- expect ( result ) . toBeTrue ( ) ;
126+ expect ( comp . isControlledVocabulary ( controlledMetadata ) ) . toBeTrue ( ) ;
123127 } ) ;
124128
125129 it ( 'should return translated vocabulary value when available' , ( done ) => {
126- const vocabEntry = {
127- display : 'Translated Value' ,
128- } ;
129-
130130 vocabularyServiceMock . getPublicVocabularyEntryByID . and . returnValue (
131- of (
132- createSuccessfulRemoteDataObject (
133- buildPaginatedList ( new PageInfo ( ) , [ vocabEntry ] ) ,
134- ) ,
135- ) ,
131+ of ( createSuccessfulRemoteDataObject (
132+ buildPaginatedList ( new PageInfo ( ) , [ { display : 'Translated Value' } ] ) ,
133+ ) ) ,
136134 ) ;
137-
138135 comp . getVocabularyValue ( controlledMetadata ) . subscribe ( ( value ) => {
139136 expect ( value ) . toBe ( 'Translated Value' ) ;
140137 done ( ) ;
141138 } ) ;
142139 } ) ;
143140
141+ it ( 'should render search link when searchFilter is present' , ( ) => {
142+ comp . searchFilter = 'subject' ;
143+ expect ( comp . hasSearchFilter ( ) ) . toBeTrue ( ) ;
144+ expect ( comp . getSearchQueryParams ( 'test' ) ) . toEqual ( { 'f.subject' : 'test,equals' } ) ;
145+ } ) ;
146+
147+ it ( 'should render browse link when browseDefinition is provided' , ( ) => {
148+ comp . browseDefinition = {
149+ id : 'subject' ,
150+ metadataKeys : [ ] ,
151+ order : 0 ,
152+ getRenderType : ( ) => 'metadata' ,
153+ } as any ;
154+ expect ( comp . hasBrowseDefinition ( ) ) . toBeTrue ( ) ;
155+ } ) ;
144156
145157} ) ;
0 commit comments