1- import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
1+ import { ComponentFixture , fakeAsync , TestBed , waitForAsync } from '@angular/core/testing' ;
22
33import { CrisLayoutRelationBoxComponent } from './cris-layout-relation-box.component' ;
44import { NO_ERRORS_SCHEMA } from '@angular/core' ;
55import { TranslateLoader , TranslateModule } from '@ngx-translate/core' ;
66import { CommonModule } from '@angular/common' ;
77import { SharedModule } from '../../../../../shared/shared.module' ;
88import { Item } from '../../../../../core/shared/item.model' ;
9- import { of } from 'rxjs' ;
9+ import { of as observableOf , of } from 'rxjs' ;
1010import { CrisLayoutBox } from '../../../../../core/layout/models/box.model' ;
1111import { TranslateLoaderMock } from '../../../../../shared/mocks/translate-loader.mock' ;
12+ import { MetadataValue } from '../../../../../core/shared/metadata.models' ;
13+ import { Person } from '@angular/cli/utilities/package-json' ;
14+ import { AuthService } from '../../../../../core/auth/auth.service' ;
15+ import { cold } from 'jasmine-marbles' ;
16+ import { EPersonMock , EPersonMock2 } from '../../../../../shared/testing/eperson.mock' ;
1217
1318describe ( 'CrisLayoutRelationBoxComponent' , ( ) => {
1419 let component : CrisLayoutRelationBoxComponent ;
@@ -25,7 +30,37 @@ describe('CrisLayoutRelationBoxComponent', () => {
2530 collapsed : false ,
2631 header : 'CrisLayoutBox Header' ,
2732 shortname : 'test-box' ,
28- configuration : of ( { configuration : 'box-configuration-id' } )
33+ configuration : { 'discovery-configuration' : 'box-configuration-id' }
34+ } ) ;
35+
36+ const relationPublicationsBox = Object . assign ( new CrisLayoutBox ( ) , {
37+ id : '2' ,
38+ collapsed : false ,
39+ header : 'Publications' ,
40+ shortname : 'publications' ,
41+ configuration : { 'discovery-configuration' : 'RELATION.Person.researchoutputs' }
42+ } ) ;
43+
44+ const personItem = Object . assign ( new Item ( ) , {
45+ id : '1234-65487-12354-1235' ,
46+ bundles : of ( { } ) ,
47+ metadata : {
48+ 'dspace.entity.type' : [ { value : 'Person' } ] as MetadataValue [ ] ,
49+ 'dspace.object.owner' : [ { value : 'not Owner' , authority : EPersonMock2 . id } ] as MetadataValue [ ] ,
50+ }
51+ } ) ;
52+
53+ const ownerItem = Object . assign ( new Item ( ) , {
54+ id : '1234-65487-12354-1235' ,
55+ bundles : of ( { } ) ,
56+ metadata : {
57+ 'dspace.entity.type' : [ { value : 'Person' } ] as MetadataValue [ ] ,
58+ 'dspace.object.owner' : [ { value : 'Owner' , authority : EPersonMock . id } ] as MetadataValue [ ] ,
59+ }
60+ } ) ;
61+
62+ const authService = jasmine . createSpyObj ( 'authService' , {
63+ getAuthenticatedUserFromStore : observableOf ( null )
2964 } ) ;
3065
3166 beforeEach ( waitForAsync ( ( ) => {
@@ -40,25 +75,96 @@ describe('CrisLayoutRelationBoxComponent', () => {
4075 CommonModule ,
4176 SharedModule
4277 ] ,
43- declarations : [ CrisLayoutRelationBoxComponent ] ,
78+ declarations : [ CrisLayoutRelationBoxComponent ] ,
4479 schemas : [ NO_ERRORS_SCHEMA ] ,
4580 providers : [
46- { provide : 'boxProvider' , useClass : testBox } ,
47- { provide : 'itemProvider' , useClass : testItem } ,
81+ { provide : 'boxProvider' , useValue : testBox } ,
82+ { provide : 'itemProvider' , useValue : testItem } ,
83+ { provide : AuthService , useValue : authService } ,
4884 ]
4985 } )
50- . compileComponents ( ) ;
86+ . compileComponents ( ) ;
5187 } ) ) ;
5288
5389 beforeEach ( ( ) => {
5490 fixture = TestBed . createComponent ( CrisLayoutRelationBoxComponent ) ;
5591 component = fixture . componentInstance ;
56- component . box = testBox ;
57- component . item = testItem ;
58- fixture . detectChanges ( ) ;
5992 } ) ;
6093
61- xit ( 'should have set scope in searchFilter' , ( ) => {
62- expect ( component . searchFilter ) . toContain ( 'scope=' + testItem . id ) ;
94+ describe ( 'When item is not a Person' , ( ) => {
95+ beforeEach ( ( ) => {
96+ component . box = testBox ;
97+ component . item = testItem ;
98+ fixture . detectChanges ( ) ;
99+ } ) ;
100+
101+ it ( 'should create CrisLayoutRelationBoxComponent' , ( ) => {
102+ expect ( component ) . toBeDefined ( ) ;
103+ } ) ;
104+
105+ it ( 'should have set scope in searchFilter' , ( ) => {
106+ expect ( component . searchFilter ) . toContain ( 'scope=' + testItem . id ) ;
107+ } ) ;
108+
109+ it ( 'info message cannot be shown' , fakeAsync ( ( ) => {
110+ expect ( component . showSearchResultNotice$ ) . toBeObservable ( cold ( 'a' , { a : false } ) ) ;
111+ } ) ) ;
112+
113+ it ( 'info message has no value' , fakeAsync ( ( ) => {
114+ expect ( component . searchResultNotice ) . toBeUndefined ( ) ;
115+ } ) ) ;
116+ } ) ;
117+
118+ describe ( 'When item is a Person' , ( ) => {
119+
120+ describe ( 'When relation-box of researchoutputs is shown' , ( ) => {
121+ beforeEach ( ( ) => {
122+ component . box = relationPublicationsBox ;
123+ } ) ;
124+
125+ describe ( 'Whenever the personItem is the researcher profile of the logged user' , ( ) => {
126+ beforeEach ( ( ) => {
127+ ( authService . getAuthenticatedUserFromStore as jasmine . Spy ) . and . returnValue ( observableOf ( { id : EPersonMock . id } as Person ) ) ;
128+ component . item = ownerItem ;
129+ fixture . detectChanges ( ) ;
130+ } ) ;
131+ it ( 'info message can be shown' , fakeAsync ( ( ) => {
132+ expect ( component . showSearchResultNotice$ ) . toBeObservable ( cold ( 'a' , { a : true } ) ) ;
133+ } ) ) ;
134+ it ( 'info message has value' , fakeAsync ( ( ) => {
135+ expect ( component . searchResultNotice ) . not . toBeUndefined ( ) ;
136+ } ) ) ;
137+ } ) ;
138+
139+ describe ( 'Whenever the personItem is not the researcher profile of the logged user' , ( ) => {
140+ beforeEach ( ( ) => {
141+ ( authService . getAuthenticatedUserFromStore as jasmine . Spy ) . and . returnValue ( observableOf ( { id : 'fake-uuid' } as Person ) ) ;
142+ component . item = personItem ;
143+ fixture . detectChanges ( ) ;
144+ } ) ;
145+ it ( 'info message cannot be shown' , fakeAsync ( ( ) => {
146+ expect ( component . showSearchResultNotice$ ) . toBeObservable ( cold ( 'a' , { a : false } ) ) ;
147+ } ) ) ;
148+ it ( 'info message has no value' , fakeAsync ( ( ) => {
149+ expect ( component . searchResultNotice ) . not . toBeUndefined ( ) ;
150+ } ) ) ;
151+ } ) ;
152+
153+ describe ( 'no one is logged' , ( ) => {
154+ beforeEach ( ( ) => {
155+ ( authService . getAuthenticatedUserFromStore as jasmine . Spy ) . and . returnValue ( observableOf ( null as Person ) ) ;
156+ fixture . detectChanges ( ) ;
157+ } ) ;
158+ it ( 'info message has no value' , fakeAsync ( ( ) => {
159+ // component.showSearchResultNotice$.subscribe(value => expect(value).toBeUndefined());
160+ expect ( component . showSearchResultNotice$ ) . toBeObservable ( cold ( 'a' , { a : false } ) ) ;
161+ } ) ) ;
162+ it ( 'info message has no value' , fakeAsync ( ( ) => {
163+ expect ( component . searchResultNotice ) . toBeUndefined ( ) ;
164+ } ) ) ;
165+ } ) ;
166+
167+ } ) ;
63168 } ) ;
169+
64170} ) ;
0 commit comments