Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<WorkspaceitemActionsComponent>;
Expand Down Expand Up @@ -261,6 +269,48 @@ 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';
const response$ = new Subject<RemoteData<ShareSubmissionLink>>();
spyOn(rdbService, 'buildFromRequestUUID').and.returnValue(response$);

fixture.debugElement.query(By.css('#share_1234')).nativeElement.click();

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: jasmine.objectContaining({ 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'));

Expand Down
3 changes: 3 additions & 0 deletions src/app/shared/testing/hal-endpoint-service.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading