From 881eb92fa10bbc471da2569ca1de39bd419d229a Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Thu, 7 Oct 2021 13:53:02 +0200 Subject: [PATCH] 83635: Feedback and test cases --- .../data/item-request-data.service.spec.ts | 95 ++++++++++ src/app/core/shared/item-request.model.ts | 2 +- .../deny-request-copy.component.spec.ts | 177 ++++++++++++++++++ .../email-request-copy.component.spec.ts | 47 +++++ .../grant-deny-request-copy.component.html | 2 +- .../grant-deny-request-copy.component.spec.ts | 123 ++++++++++++ .../grant-deny-request-copy.component.ts | 10 + .../grant-request-copy.component.spec.ts | 177 ++++++++++++++++++ src/assets/i18n/en.json5 | 8 +- 9 files changed, 635 insertions(+), 6 deletions(-) create mode 100644 src/app/core/data/item-request-data.service.spec.ts create mode 100644 src/app/request-copy/deny-request-copy/deny-request-copy.component.spec.ts create mode 100644 src/app/request-copy/email-request-copy/email-request-copy.component.spec.ts create mode 100644 src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts create mode 100644 src/app/request-copy/grant-request-copy/grant-request-copy.component.spec.ts diff --git a/src/app/core/data/item-request-data.service.spec.ts b/src/app/core/data/item-request-data.service.spec.ts new file mode 100644 index 0000000000..0d99ca5cd4 --- /dev/null +++ b/src/app/core/data/item-request-data.service.spec.ts @@ -0,0 +1,95 @@ +import { ItemRequestDataService } from './item-request-data.service'; +import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { RequestService } from './request.service'; +import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; +import { of as observableOf } from 'rxjs'; +import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; +import { ItemRequest } from '../shared/item-request.model'; +import { PostRequest } from './request.models'; +import { RequestCopyEmail } from '../../request-copy/email-request-copy/request-copy-email.model'; +import { RestRequestMethod } from './rest-request-method'; + +describe('ItemRequestDataService', () => { + let service: ItemRequestDataService; + + let requestService: RequestService; + let rdbService: RemoteDataBuildService; + let halService: HALEndpointService; + + const restApiEndpoint = 'rest/api/endpoint/'; + const requestId = 'request-id'; + let itemRequest: ItemRequest; + + beforeEach(() => { + itemRequest = Object.assign(new ItemRequest(), { + token: 'item-request-token', + }); + requestService = jasmine.createSpyObj('requestService', { + generateRequestId: requestId, + send: '', + }); + rdbService = jasmine.createSpyObj('rdbService', { + buildFromRequestUUID: createSuccessfulRemoteDataObject$(itemRequest), + }); + halService = jasmine.createSpyObj('halService', { + getEndpoint: observableOf(restApiEndpoint), + }); + + service = new ItemRequestDataService(requestService, rdbService, null, null, halService, null, null, null); + }); + + describe('requestACopy', () => { + it('should send a POST request containing the provided item request', (done) => { + service.requestACopy(itemRequest).subscribe(() => { + expect(requestService.send).toHaveBeenCalledWith(new PostRequest(requestId, restApiEndpoint, itemRequest)); + done(); + }); + }); + }); + + describe('grant', () => { + let email: RequestCopyEmail; + + beforeEach(() => { + email = new RequestCopyEmail('subject', 'message'); + }); + + it('should send a PUT request containing the correct properties', (done) => { + service.grant(itemRequest.token, email, true).subscribe(() => { + expect(requestService.send).toHaveBeenCalledWith(jasmine.objectContaining({ + method: RestRequestMethod.PUT, + body: JSON.stringify({ + acceptRequest: true, + responseMessage: email.message, + subject: email.subject, + suggestOpenAccess: true, + }), + })); + done(); + }); + }); + }); + + describe('deny', () => { + let email: RequestCopyEmail; + + beforeEach(() => { + email = new RequestCopyEmail('subject', 'message'); + }); + + it('should send a PUT request containing the correct properties', (done) => { + service.deny(itemRequest.token, email).subscribe(() => { + expect(requestService.send).toHaveBeenCalledWith(jasmine.objectContaining({ + method: RestRequestMethod.PUT, + body: JSON.stringify({ + acceptRequest: false, + responseMessage: email.message, + subject: email.subject, + suggestOpenAccess: false, + }), + })); + done(); + }); + }); + }); +}); diff --git a/src/app/core/shared/item-request.model.ts b/src/app/core/shared/item-request.model.ts index da9c4c9e08..08b65abebf 100644 --- a/src/app/core/shared/item-request.model.ts +++ b/src/app/core/shared/item-request.model.ts @@ -7,7 +7,7 @@ import { CacheableObject } from '../cache/object-cache.reducer'; import { HALLink } from './hal-link.model'; /** - * Model class for a Configuration Property + * Model class for an ItemRequest */ @typedObject export class ItemRequest implements CacheableObject { diff --git a/src/app/request-copy/deny-request-copy/deny-request-copy.component.spec.ts b/src/app/request-copy/deny-request-copy/deny-request-copy.component.spec.ts new file mode 100644 index 0000000000..c88bfd3b5e --- /dev/null +++ b/src/app/request-copy/deny-request-copy/deny-request-copy.component.spec.ts @@ -0,0 +1,177 @@ +import { DenyRequestCopyComponent } from './deny-request-copy.component'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { VarDirective } from '../../shared/utils/var.directive'; +import { TranslateModule, TranslateService } from '@ngx-translate/core'; +import { RouterTestingModule } from '@angular/router/testing'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { AuthService } from '../../core/auth/auth.service'; +import { ItemDataService } from '../../core/data/item-data.service'; +import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; +import { ItemRequestDataService } from '../../core/data/item-request-data.service'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; +import { of as observableOf } from 'rxjs'; +import { + createFailedRemoteDataObject$, + createSuccessfulRemoteDataObject, + createSuccessfulRemoteDataObject$ +} from '../../shared/remote-data.utils'; +import { ItemRequest } from '../../core/shared/item-request.model'; +import { EPerson } from '../../core/eperson/models/eperson.model'; +import { Item } from '../../core/shared/item.model'; +import { RequestCopyEmail } from '../email-request-copy/request-copy-email.model'; + +describe('DenyRequestCopyComponent', () => { + let component: DenyRequestCopyComponent; + let fixture: ComponentFixture; + + let router: Router; + let route: ActivatedRoute; + let authService: AuthService; + let translateService: TranslateService; + let itemDataService: ItemDataService; + let nameService: DSONameService; + let itemRequestService: ItemRequestDataService; + let notificationsService: NotificationsService; + + let itemRequest: ItemRequest; + let user: EPerson; + let item: Item; + let itemName: string; + let itemUrl: string; + + beforeEach(waitForAsync(() => { + itemRequest = Object.assign(new ItemRequest(), { + token: 'item-request-token', + requestName: 'requester name' + }); + user = Object.assign(new EPerson(), { + metadata: { + 'eperson.firstname': [ + { + value: 'first' + } + ], + 'eperson.lastname': [ + { + value: 'last' + } + ] + }, + email: 'user-email', + }); + itemName = 'item-name'; + itemUrl = 'item-url'; + item = Object.assign(new Item(), { + id: 'item-id', + metadata: { + 'dc.identifier.uri': [ + { + value: itemUrl + } + ], + 'dc.title': [ + { + value: itemName + } + ] + } + }); + + router = jasmine.createSpyObj('router', { + navigateByUrl: jasmine.createSpy('navigateByUrl'), + }); + route = jasmine.createSpyObj('route', {}, { + data: observableOf({ + request: createSuccessfulRemoteDataObject(itemRequest), + }), + }); + authService = jasmine.createSpyObj('authService', { + isAuthenticated: observableOf(true), + getAuthenticatedUserFromStore: observableOf(user), + }); + itemDataService = jasmine.createSpyObj('itemDataService', { + findById: createSuccessfulRemoteDataObject$(item), + }); + nameService = jasmine.createSpyObj('nameService', { + getName: itemName, + }); + itemRequestService = jasmine.createSpyObj('itemRequestService', { + deny: createSuccessfulRemoteDataObject$(itemRequest), + }); + notificationsService = jasmine.createSpyObj('notificationsService', ['success', 'error']); + + TestBed.configureTestingModule({ + declarations: [DenyRequestCopyComponent, VarDirective], + imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], + providers: [ + { provide: Router, useValue: router }, + { provide: ActivatedRoute, useValue: route }, + { provide: AuthService, useValue: authService }, + { provide: ItemDataService, useValue: itemDataService }, + { provide: DSONameService, useValue: nameService }, + { provide: ItemRequestDataService, useValue: itemRequestService }, + { provide: NotificationsService, useValue: notificationsService }, + ], + schemas: [NO_ERRORS_SCHEMA] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DenyRequestCopyComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + + translateService = (component as any).translateService; + spyOn(translateService, 'get').and.returnValue(observableOf('translated-message')); + }); + + it('message$ should be parameterized correctly', (done) => { + component.message$.subscribe(() => { + expect(translateService.get).toHaveBeenCalledWith(jasmine.anything(), Object.assign({ + recipientName: itemRequest.requestName, + itemUrl: itemUrl, + itemName: itemName, + authorName: user.name, + authorEmail: user.email, + })); + done(); + }); + }); + + describe('deny', () => { + let email: RequestCopyEmail; + + describe('when the request is successful', () => { + beforeEach(() => { + email = new RequestCopyEmail('subject', 'message'); + (itemRequestService.deny as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(itemRequest)); + component.deny(email); + }); + + it('should display a success notification', () => { + expect(notificationsService.success).toHaveBeenCalled(); + }); + + it('should navigate to the homepage', () => { + expect(router.navigateByUrl).toHaveBeenCalledWith('/'); + }); + }); + + describe('when the request is unsuccessful', () => { + beforeEach(() => { + email = new RequestCopyEmail('subject', 'message'); + (itemRequestService.deny as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$()); + component.deny(email); + }); + + it('should display a success notification', () => { + expect(notificationsService.error).toHaveBeenCalled(); + }); + + it('should not navigate', () => { + expect(router.navigateByUrl).not.toHaveBeenCalled(); + }); + }); + }); +}); diff --git a/src/app/request-copy/email-request-copy/email-request-copy.component.spec.ts b/src/app/request-copy/email-request-copy/email-request-copy.component.spec.ts new file mode 100644 index 0000000000..3857c0d91b --- /dev/null +++ b/src/app/request-copy/email-request-copy/email-request-copy.component.spec.ts @@ -0,0 +1,47 @@ +import { EmailRequestCopyComponent } from './email-request-copy.component'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { VarDirective } from '../../shared/utils/var.directive'; +import { TranslateModule } from '@ngx-translate/core'; +import { RouterTestingModule } from '@angular/router/testing'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { Location } from '@angular/common'; +import { RequestCopyEmail } from './request-copy-email.model'; + +describe('EmailRequestCopyComponent', () => { + let component: EmailRequestCopyComponent; + let fixture: ComponentFixture; + + let location: Location; + + beforeEach(waitForAsync(() => { + location = jasmine.createSpyObj('location', ['back']); + + TestBed.configureTestingModule({ + declarations: [EmailRequestCopyComponent, VarDirective], + imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], + providers: [ + { provide: Location, useValue: location }, + ], + schemas: [NO_ERRORS_SCHEMA] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EmailRequestCopyComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('return should navigate to the previous page', () => { + component.return(); + expect(location.back).toHaveBeenCalled(); + }); + + it('submit should emit an email object', () => { + spyOn(component.send, 'emit').and.stub(); + component.subject = 'test-subject'; + component.message = 'test-message'; + component.submit(); + expect(component.send.emit).toHaveBeenCalledWith(new RequestCopyEmail('test-subject', 'test-message')); + }); +}); diff --git a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.html b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.html index 5be182c4cb..abd013f9a1 100644 --- a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.html +++ b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.html @@ -1,7 +1,7 @@

{{'grant-deny-request-copy.header' | translate}}

-

{{'grant-deny-request-copy.intro1' | translate:{ name: (itemName$ | async) } }}

+

{{'grant-deny-request-copy.intro2' | translate}}

diff --git a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts new file mode 100644 index 0000000000..3a0817b3b0 --- /dev/null +++ b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts @@ -0,0 +1,123 @@ +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { VarDirective } from '../../shared/utils/var.directive'; +import { TranslateModule } from '@ngx-translate/core'; +import { RouterTestingModule } from '@angular/router/testing'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { AuthService } from '../../core/auth/auth.service'; +import { ItemDataService } from '../../core/data/item-data.service'; +import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; +import { of as observableOf } from 'rxjs'; +import { + createSuccessfulRemoteDataObject, + createSuccessfulRemoteDataObject$ +} from '../../shared/remote-data.utils'; +import { ItemRequest } from '../../core/shared/item-request.model'; +import { Item } from '../../core/shared/item.model'; +import { GrantDenyRequestCopyComponent } from './grant-deny-request-copy.component'; +import { getItemPageRoute } from '../../item-page/item-page-routing-paths'; +import { getRequestCopyDenyRoute, getRequestCopyGrantRoute } from '../request-copy-routing-paths'; + +describe('GrantDenyRequestCopyComponent', () => { + let component: GrantDenyRequestCopyComponent; + let fixture: ComponentFixture; + + let router: Router; + let route: ActivatedRoute; + let authService: AuthService; + let itemDataService: ItemDataService; + let nameService: DSONameService; + + let itemRequest: ItemRequest; + let item: Item; + let itemName: string; + let itemUrl: string; + + beforeEach(waitForAsync(() => { + itemRequest = Object.assign(new ItemRequest(), { + token: 'item-request-token', + requestName: 'requester name' + }); + itemName = 'item-name'; + item = Object.assign(new Item(), { + id: 'item-id', + metadata: { + 'dc.identifier.uri': [ + { + value: itemUrl + } + ], + 'dc.title': [ + { + value: itemName + } + ] + } + }); + itemUrl = getItemPageRoute(item); + + route = jasmine.createSpyObj('route', {}, { + data: observableOf({ + request: createSuccessfulRemoteDataObject(itemRequest), + }), + }); + authService = jasmine.createSpyObj('authService', { + isAuthenticated: observableOf(true), + }); + itemDataService = jasmine.createSpyObj('itemDataService', { + findById: createSuccessfulRemoteDataObject$(item), + }); + nameService = jasmine.createSpyObj('nameService', { + getName: itemName, + }); + + TestBed.configureTestingModule({ + declarations: [GrantDenyRequestCopyComponent, VarDirective], + imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], + providers: [ + { provide: ActivatedRoute, useValue: route }, + { provide: AuthService, useValue: authService }, + { provide: ItemDataService, useValue: itemDataService }, + { provide: DSONameService, useValue: nameService }, + ], + schemas: [NO_ERRORS_SCHEMA] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(GrantDenyRequestCopyComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + + router = (component as any).router; + spyOn(router, 'navigateByUrl').and.stub(); + }); + + it('should initialise itemName$', (done) => { + component.itemName$.subscribe((result) => { + expect(result).toEqual(itemName); + done(); + }); + }); + + it('should initialise itemUrl$', (done) => { + component.itemUrl$.subscribe((result) => { + expect(result).toEqual(itemUrl); + done(); + }); + }); + + it('should initialise denyRoute$', (done) => { + component.denyRoute$.subscribe((result) => { + expect(result).toEqual(getRequestCopyDenyRoute(itemRequest.token)); + done(); + }); + }); + + it('should initialise grantRoute$', (done) => { + component.grantRoute$.subscribe((result) => { + expect(result).toEqual(getRequestCopyGrantRoute(itemRequest.token)); + done(); + }); + }); +}); diff --git a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts index fba2e3f4d0..5ba81e991b 100644 --- a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts +++ b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts @@ -14,6 +14,7 @@ import { getRequestCopyDenyRoute, getRequestCopyGrantRoute } from '../request-co import { Item } from '../../core/shared/item.model'; import { ItemDataService } from '../../core/data/item-data.service'; import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; +import { getItemPageRoute } from '../../item-page/item-page-routing-paths'; @Component({ selector: 'ds-grant-deny-request-copy', @@ -39,6 +40,11 @@ export class GrantDenyRequestCopyComponent implements OnInit { */ itemName$: Observable; + /** + * The url of the item + */ + itemUrl$: Observable; + /** * The route to the page for denying access to the item */ @@ -73,6 +79,10 @@ export class GrantDenyRequestCopyComponent implements OnInit { getFirstSucceededRemoteDataPayload(), map((item) => this.nameService.getName(item)), ); + this.itemUrl$ = this.itemRD$.pipe( + getFirstSucceededRemoteDataPayload(), + map((item) => getItemPageRoute(item)), + ); this.denyRoute$ = this.itemRequestRD$.pipe( getFirstSucceededRemoteDataPayload(), diff --git a/src/app/request-copy/grant-request-copy/grant-request-copy.component.spec.ts b/src/app/request-copy/grant-request-copy/grant-request-copy.component.spec.ts new file mode 100644 index 0000000000..b6ccb8557e --- /dev/null +++ b/src/app/request-copy/grant-request-copy/grant-request-copy.component.spec.ts @@ -0,0 +1,177 @@ +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { VarDirective } from '../../shared/utils/var.directive'; +import { TranslateModule, TranslateService } from '@ngx-translate/core'; +import { RouterTestingModule } from '@angular/router/testing'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { AuthService } from '../../core/auth/auth.service'; +import { ItemDataService } from '../../core/data/item-data.service'; +import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; +import { ItemRequestDataService } from '../../core/data/item-request-data.service'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; +import { of as observableOf } from 'rxjs'; +import { + createFailedRemoteDataObject$, + createSuccessfulRemoteDataObject, + createSuccessfulRemoteDataObject$ +} from '../../shared/remote-data.utils'; +import { ItemRequest } from '../../core/shared/item-request.model'; +import { EPerson } from '../../core/eperson/models/eperson.model'; +import { Item } from '../../core/shared/item.model'; +import { RequestCopyEmail } from '../email-request-copy/request-copy-email.model'; +import { GrantRequestCopyComponent } from './grant-request-copy.component'; + +describe('GrantRequestCopyComponent', () => { + let component: GrantRequestCopyComponent; + let fixture: ComponentFixture; + + let router: Router; + let route: ActivatedRoute; + let authService: AuthService; + let translateService: TranslateService; + let itemDataService: ItemDataService; + let nameService: DSONameService; + let itemRequestService: ItemRequestDataService; + let notificationsService: NotificationsService; + + let itemRequest: ItemRequest; + let user: EPerson; + let item: Item; + let itemName: string; + let itemUrl: string; + + beforeEach(waitForAsync(() => { + itemRequest = Object.assign(new ItemRequest(), { + token: 'item-request-token', + requestName: 'requester name' + }); + user = Object.assign(new EPerson(), { + metadata: { + 'eperson.firstname': [ + { + value: 'first' + } + ], + 'eperson.lastname': [ + { + value: 'last' + } + ] + }, + email: 'user-email', + }); + itemName = 'item-name'; + itemUrl = 'item-url'; + item = Object.assign(new Item(), { + id: 'item-id', + metadata: { + 'dc.identifier.uri': [ + { + value: itemUrl + } + ], + 'dc.title': [ + { + value: itemName + } + ] + } + }); + + router = jasmine.createSpyObj('router', { + navigateByUrl: jasmine.createSpy('navigateByUrl'), + }); + route = jasmine.createSpyObj('route', {}, { + data: observableOf({ + request: createSuccessfulRemoteDataObject(itemRequest), + }), + }); + authService = jasmine.createSpyObj('authService', { + isAuthenticated: observableOf(true), + getAuthenticatedUserFromStore: observableOf(user), + }); + itemDataService = jasmine.createSpyObj('itemDataService', { + findById: createSuccessfulRemoteDataObject$(item), + }); + nameService = jasmine.createSpyObj('nameService', { + getName: itemName, + }); + itemRequestService = jasmine.createSpyObj('itemRequestService', { + grant: createSuccessfulRemoteDataObject$(itemRequest), + }); + notificationsService = jasmine.createSpyObj('notificationsService', ['success', 'error']); + + TestBed.configureTestingModule({ + declarations: [GrantRequestCopyComponent, VarDirective], + imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], + providers: [ + { provide: Router, useValue: router }, + { provide: ActivatedRoute, useValue: route }, + { provide: AuthService, useValue: authService }, + { provide: ItemDataService, useValue: itemDataService }, + { provide: DSONameService, useValue: nameService }, + { provide: ItemRequestDataService, useValue: itemRequestService }, + { provide: NotificationsService, useValue: notificationsService }, + ], + schemas: [NO_ERRORS_SCHEMA] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(GrantRequestCopyComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + + translateService = (component as any).translateService; + spyOn(translateService, 'get').and.returnValue(observableOf('translated-message')); + }); + + it('message$ should be parameterized correctly', (done) => { + component.message$.subscribe(() => { + expect(translateService.get).toHaveBeenCalledWith(jasmine.anything(), Object.assign({ + recipientName: itemRequest.requestName, + itemUrl: itemUrl, + itemName: itemName, + authorName: user.name, + authorEmail: user.email, + })); + done(); + }); + }); + + describe('grant', () => { + let email: RequestCopyEmail; + + describe('when the request is successful', () => { + beforeEach(() => { + email = new RequestCopyEmail('subject', 'message'); + (itemRequestService.grant as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$(itemRequest)); + component.grant(email); + }); + + it('should display a success notification', () => { + expect(notificationsService.success).toHaveBeenCalled(); + }); + + it('should navigate to the homepage', () => { + expect(router.navigateByUrl).toHaveBeenCalledWith('/'); + }); + }); + + describe('when the request is unsuccessful', () => { + beforeEach(() => { + email = new RequestCopyEmail('subject', 'message'); + (itemRequestService.grant as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$()); + component.grant(email); + }); + + it('should display a success notification', () => { + expect(notificationsService.error).toHaveBeenCalled(); + }); + + it('should not navigate', () => { + expect(router.navigateByUrl).not.toHaveBeenCalled(); + }); + }); + }); +}); diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 6d9ae075a2..fb3c27883b 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1206,7 +1206,7 @@ - "deny-request-copy.email.message": "Dear {{ recipientName }},\nIn response to your request I regret to inform you that it's not possible to send you a copy of the file(s) you have requested, concerning the document: \"{{ itemUrl }}\" ({{ itemName }}), of which I am author (or co-author).\n\nBest regards,\n{{ authorName }} <{{ authorEmail }}>", + "deny-request-copy.email.message": "Dear {{ recipientName }},\nIn response to your request I regret to inform you that it's not possible to send you a copy of the file(s) you have requested, concerning the document: \"{{ itemUrl }}\" ({{ itemName }}), of which I am an author.\n\nBest regards,\n{{ authorName }} <{{ authorEmail }}>", "deny-request-copy.email.subject": "Request copy of document", @@ -1467,13 +1467,13 @@ "grant-deny-request-copy.header": "Document copy request", - "grant-deny-request-copy.intro1": "IF YOU ARE THE AUTHOR (OR AN AUTHOR) OF DOCUMENT \"{{ name }}\" use the buttons to answer the user's request.", + "grant-deny-request-copy.intro1": "If you are one of the authors of the document {{ name }}, then please use one of the options below to respond to the user's request.", - "grant-deny-request-copy.intro2": "This repository will propose an appropriate model reply, which you may edit.", + "grant-deny-request-copy.intro2": "After choosing an option, you will be presented with a suggested email reply which you may edit.", - "grant-request-copy.email.message": "Dear {{ recipientName }},\nIn response to your request I have the pleasure to send you in attachment a copy of the file(s) concerning the document: \"{{ itemUrl }}\" ({{ itemName }}), of which I am author (or co-author).\n\nBest regards,\n{{ authorName }} <{{ authorEmail }}>", + "grant-request-copy.email.message": "Dear {{ recipientName }},\nIn response to your request I have the pleasure to send you in attachment a copy of the file(s) concerning the document: \"{{ itemUrl }}\" ({{ itemName }}), of which I am an author.\n\nBest regards,\n{{ authorName }} <{{ authorEmail }}>", "grant-request-copy.email.subject": "Request copy of document",