1+ import { EPerson } from '../../../core/eperson/models/eperson.model' ;
12import { ChangeDetectionStrategy , Injector , NO_ERRORS_SCHEMA } from '@angular/core' ;
23import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
34import { Router } from '@angular/router' ;
@@ -24,12 +25,16 @@ import { RequestService } from '../../../core/data/request.service';
2425import { getMockRequestService } from '../../mocks/request.service.mock' ;
2526import { getMockSearchService } from '../../mocks/search-service.mock' ;
2627import { SearchService } from '../../../core/shared/search/search.service' ;
28+ import { AuthService } from '../../../core/auth/auth.service' ;
29+ import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service' ;
2730
2831let component : WorkspaceitemActionsComponent ;
2932let fixture : ComponentFixture < WorkspaceitemActionsComponent > ;
3033
3134let mockObject : WorkspaceItem ;
3235let notificationsServiceStub : NotificationsServiceStub ;
36+ let authorizationService ;
37+ let authService ;
3338
3439const mockDataService = jasmine . createSpyObj ( 'WorkspaceitemDataService' , {
3540 delete : jasmine . createSpy ( 'delete' )
@@ -71,10 +76,91 @@ const item = Object.assign(new Item(), {
7176const rd = createSuccessfulRemoteDataObject ( item ) ;
7277mockObject = Object . assign ( new WorkspaceItem ( ) , { item : observableOf ( rd ) , id : '1234' , uuid : '1234' } ) ;
7378
74- describe ( 'WorkspaceitemActionsComponent' , ( ) => {
75- beforeEach ( waitForAsync ( ( ) => {
79+ const ePersonMock : EPerson = Object . assign ( new EPerson ( ) , {
80+ handle : null ,
81+ netid : null ,
82+ lastActive : '2023-04-27T12:15:57.054+00:00' ,
83+ canLogIn : true ,
84+ email : 'dspacedemo+submit@gmail.com' ,
85+ requireCertificate : false ,
86+ selfRegistered : false ,
87+ _name : 'dspacedemo+submit@gmail.com' ,
88+ id : '914955b1-cf2e-4884-8af7-a166aa24cf73' ,
89+ uuid : '914955b1-cf2e-4884-8af7-a166aa24cf73' ,
90+ type : 'eperson' ,
91+ metadata : {
92+ 'dspace.agreements.cookies' : [
93+ {
94+ uuid : '0a53a0f2-e168-4ed9-b4af-cba9a2d267ca' ,
95+ language : null ,
96+ value :
97+ '{"authentication":true,"preferences":true,"acknowledgement":true,"google-analytics":true}' ,
98+ place : 0 ,
99+ authority : null ,
100+ confidence : - 1 ,
101+ } ,
102+ ] ,
103+ 'dspace.agreements.end-user' : [
104+ {
105+ uuid : '0879e571-6e4a-4efe-af9b-704c755166be' ,
106+ language : null ,
107+ value : 'true' ,
108+ place : 0 ,
109+ authority : null ,
110+ confidence : - 1 ,
111+ } ,
112+ ] ,
113+ 'eperson.firstname' : [
114+ {
115+ uuid : '18052a3e-f19b-49ca-b9f9-ee4cf9c71b86' ,
116+ language : null ,
117+ value : 'Demo' ,
118+ place : 0 ,
119+ authority : null ,
120+ confidence : - 1 ,
121+ } ,
122+ ] ,
123+ 'eperson.language' : [
124+ {
125+ uuid : '98c2abdb-6a6f-4b41-b455-896bcf333ca3' ,
126+ language : null ,
127+ value : 'en' ,
128+ place : 0 ,
129+ authority : null ,
130+ confidence : - 1 ,
131+ } ,
132+ ] ,
133+ 'eperson.lastname' : [
134+ {
135+ uuid : 'df722e70-9497-468d-a92a-4038e7ef2586' ,
136+ language : null ,
137+ value : 'Submitter' ,
138+ place : 0 ,
139+ authority : null ,
140+ confidence : - 1 ,
141+ } ,
142+ ] ,
143+ } ,
144+ _links : {
145+ groups : {
146+ href : 'http://localhost:8080/server/api/eperson/epersons/914955b1-cf2e-4884-8af7-a166aa24cf73/groups' ,
147+ } ,
148+ self : {
149+ href : 'http://localhost:8080/server/api/eperson/epersons/914955b1-cf2e-4884-8af7-a166aa24cf73' ,
150+ } ,
151+ } ,
152+ } ) ;
76153
77- TestBed . configureTestingModule ( {
154+ authService = jasmine . createSpyObj ( 'authService' , {
155+ getAuthenticatedUserFromStore : jasmine . createSpy ( 'getAuthenticatedUserFromStore' )
156+ } ) ;
157+
158+ describe ( 'WorkspaceitemActionsComponent' , ( ) => {
159+ beforeEach ( waitForAsync ( async ( ) => {
160+ authorizationService = jasmine . createSpyObj ( 'authorizationService' , {
161+ isAuthorized : observableOf ( true )
162+ } ) ;
163+ await TestBed . configureTestingModule ( {
78164 imports : [
79165 NgbModule ,
80166 TranslateModule . forRoot ( {
@@ -92,6 +178,8 @@ describe('WorkspaceitemActionsComponent', () => {
92178 { provide : WorkspaceitemDataService , useValue : mockDataService } ,
93179 { provide : SearchService , useValue : searchService } ,
94180 { provide : RequestService , useValue : requestServce } ,
181+ { provide : AuthService , useValue : authService } ,
182+ { provide : AuthorizationDataService , useValue : authorizationService } ,
95183 NgbModal
96184 ] ,
97185 schemas : [ NO_ERRORS_SCHEMA ]
@@ -105,6 +193,7 @@ describe('WorkspaceitemActionsComponent', () => {
105193 component = fixture . componentInstance ;
106194 component . object = mockObject ;
107195 notificationsServiceStub = TestBed . inject ( NotificationsService as any ) ;
196+ ( authService . getAuthenticatedUserFromStore as jasmine . Spy ) . and . returnValue ( observableOf ( ePersonMock ) ) ;
108197 fixture . detectChanges ( ) ;
109198 } ) ;
110199
@@ -150,7 +239,6 @@ describe('WorkspaceitemActionsComponent', () => {
150239 confirmBtn . click ( ) ;
151240
152241 fixture . detectChanges ( ) ;
153-
154242 fixture . whenStable ( ) . then ( ( ) => {
155243 done ( ) ;
156244 } ) ;
0 commit comments