From 59635922d19e9630a71113085f7d8a2c69741d5e Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Sat, 17 Oct 2026 11:50:25 +0200 Subject: [PATCH 1/2] Add specs for the Share submission button in workspace item actions Co-Authored-By: Claude Fable 5.1 --- .../workspaceitem-actions.component.spec.ts | 36 +++++++++++++++++++ .../testing/hal-endpoint-service.stub.ts | 3 ++ 2 files changed, 39 insertions(+) diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts index 3159299ab2b..ce981346ef0 100644 --- a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts @@ -261,6 +261,42 @@ describe('WorkspaceitemActionsComponent', () => { expect(btn).not.toBeNull(); }); + it('should display share button', () => { + const btn = fixture.debugElement.query(By.css('#share_1234')); + + expect(btn).not.toBeNull(); + }); + + it('should request the share link and open the share-submission page', () => { + const router = TestBed.inject(Router); + const rdbService = TestBed.inject(RemoteDataBuildService); + const shareLink = 'https://ui/share-submission?change-token=abc'; + spyOn(rdbService, 'buildFromRequestUUID').and.returnValue(createSuccessfulRemoteDataObject$({ shareLink })); + + fixture.debugElement.query(By.css('#share_1234')).nativeElement.click(); + + expect(requestServce.send).toHaveBeenCalledWith(jasmine.objectContaining({ + href: 'https://rest.api/server/api/submission/share?workspaceitemid=1234', + })); + expect(notificationsServiceStub.success).toHaveBeenCalled(); + expect(router.navigate).toHaveBeenCalledWith(['/share-submission'], { + queryParams: { changeSubmitterLink: shareLink }, + }); + expect(component.shareSubmissionSpinner).toBeFalse(); + }); + + it('should show an error notification when the share link request fails', () => { + const router = TestBed.inject(Router); + const rdbService = TestBed.inject(RemoteDataBuildService); + spyOn(rdbService, 'buildFromRequestUUID').and.returnValue(createFailedRemoteDataObject$('Error', 500)); + + fixture.debugElement.query(By.css('#share_1234')).nativeElement.click(); + + expect(notificationsServiceStub.error).toHaveBeenCalled(); + expect(router.navigate).not.toHaveBeenCalled(); + expect(component.shareSubmissionSpinner).toBeFalse(); + }); + it('should display add URL bitstream button when script is executable', () => { const btn = fixture.debugElement.query(By.css('#add_url_bitstream_1234')); diff --git a/src/app/shared/testing/hal-endpoint-service.stub.ts b/src/app/shared/testing/hal-endpoint-service.stub.ts index e5d26f4b69c..65f2dcdcfa2 100644 --- a/src/app/shared/testing/hal-endpoint-service.stub.ts +++ b/src/app/shared/testing/hal-endpoint-service.stub.ts @@ -5,6 +5,9 @@ import { hasValue } from '../empty.util'; export class HALEndpointServiceStub { constructor(private url: string) {} + getRootHref(): string { + return this.url; + } getEndpoint(path: string, startHref?: string) { if (hasValue(startHref)) { return of(startHref + '/' + path); From d2dddcee6242d59c27ccf494915a5a92f709aeba Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Thu, 26 Nov 2026 23:15:22 +0100 Subject: [PATCH 2/2] Check the share request, its response id and the spinner in the spec The success spec now checks that a GET is sent, that its id is used to read the response, and that the spinner is on until the response arrives. Co-Authored-By: Claude Opus 5.5 --- .../workspaceitem-actions.component.spec.ts | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts index ce981346ef0..13c939f1706 100644 --- a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts @@ -21,13 +21,18 @@ import { TranslateLoader, TranslateModule, } from '@ngx-translate/core'; -import { of } from 'rxjs'; +import { + of, + Subject, +} from 'rxjs'; import { AuthService } from '../../../core/auth/auth.service'; import { RemoteDataBuildService } from '../../../core/cache/builders/remote-data-build.service'; import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; import { ScriptDataService } from '../../../core/data/processes/script-data.service'; +import { RemoteData } from '../../../core/data/remote-data'; import { RequestService } from '../../../core/data/request.service'; +import { RestRequestMethod } from '../../../core/data/rest-request-method'; import { EPerson } from '../../../core/eperson/models/eperson.model'; import { HALEndpointService } from '../../../core/shared/hal-endpoint.service'; import { Item } from '../../../core/shared/item.model'; @@ -49,7 +54,10 @@ import { ActivatedRouteStub } from '../../testing/active-router.stub'; import { HALEndpointServiceStub } from '../../testing/hal-endpoint-service.stub'; import { NotificationsServiceStub } from '../../testing/notifications-service.stub'; import { RouterStub } from '../../testing/router.stub'; -import { WorkspaceitemActionsComponent } from './workspaceitem-actions.component'; +import { + ShareSubmissionLink, + WorkspaceitemActionsComponent, +} from './workspaceitem-actions.component'; let component: WorkspaceitemActionsComponent; let fixture: ComponentFixture; @@ -271,16 +279,22 @@ describe('WorkspaceitemActionsComponent', () => { const router = TestBed.inject(Router); const rdbService = TestBed.inject(RemoteDataBuildService); const shareLink = 'https://ui/share-submission?change-token=abc'; - spyOn(rdbService, 'buildFromRequestUUID').and.returnValue(createSuccessfulRemoteDataObject$({ shareLink })); + const response$ = new Subject>(); + spyOn(rdbService, 'buildFromRequestUUID').and.returnValue(response$); fixture.debugElement.query(By.css('#share_1234')).nativeElement.click(); - expect(requestServce.send).toHaveBeenCalledWith(jasmine.objectContaining({ - href: 'https://rest.api/server/api/submission/share?workspaceitemid=1234', - })); + const request = requestServce.send.calls.mostRecent().args[0]; + expect(request.method).toBe(RestRequestMethod.GET); + expect(request.href).toBe('https://rest.api/server/api/submission/share?workspaceitemid=1234'); + expect(rdbService.buildFromRequestUUID).toHaveBeenCalledWith(request.uuid); + expect(component.shareSubmissionSpinner).toBeTrue(); + + response$.next(createSuccessfulRemoteDataObject({ shareLink })); + expect(notificationsServiceStub.success).toHaveBeenCalled(); expect(router.navigate).toHaveBeenCalledWith(['/share-submission'], { - queryParams: { changeSubmitterLink: shareLink }, + queryParams: jasmine.objectContaining({ changeSubmitterLink: shareLink }), }); expect(component.shareSubmissionSpinner).toBeFalse(); });