Commits

Tim Donohue authored and GitHub committed 418fe5c5cef Merge
Merge pull request #881 from jonas-atmire/w2p-72326-Back-link-on-bitstream-edit-page

Back link on bitstream edit page
No tags
gidlmaster

src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.spec.ts

Modified
1 1 import { EditBitstreamPageComponent } from './edit-bitstream-page.component';
2 2 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 3 import { TranslateModule } from '@ngx-translate/core';
4 4 import { RouterTestingModule } from '@angular/router/testing';
5 5 import { RemoteData } from '../../core/data/remote-data';
6 6 import { of as observableOf } from 'rxjs/internal/observable/of';
7 -import { ActivatedRoute } from '@angular/router';
7 +import {ActivatedRoute, Router} from '@angular/router';
8 8 import { DynamicFormControlModel, DynamicFormService } from '@ng-dynamic-forms/core';
9 9 import { NotificationsService } from '../../shared/notifications/notifications.service';
10 10 import { BitstreamDataService } from '../../core/data/bitstream-data.service';
11 11 import { ChangeDetectorRef, NO_ERRORS_SCHEMA } from '@angular/core';
12 12 import { BitstreamFormatDataService } from '../../core/data/bitstream-format-data.service';
13 13 import { Bitstream } from '../../core/shared/bitstream.model';
14 14 import { NotificationType } from '../../shared/notifications/models/notification-type';
15 15 import { INotification, Notification } from '../../shared/notifications/models/notification.model';
16 16 import { BitstreamFormat } from '../../core/shared/bitstream-format.model';
17 17 import { BitstreamFormatSupportLevel } from '../../core/shared/bitstream-format-support-level';
18 18 import { hasValue } from '../../shared/empty.util';
19 19 import { FormControl, FormGroup } from '@angular/forms';
20 20 import { PaginatedList } from '../../core/data/paginated-list';
21 21 import { PageInfo } from '../../core/shared/page-info.model';
22 22 import { FileSizePipe } from '../../shared/utils/file-size-pipe';
23 23 import { RestResponse } from '../../core/cache/response.models';
24 24 import { VarDirective } from '../../shared/utils/var.directive';
25 +import {
26 + createSuccessfulRemoteDataObject$
27 +} from '../../shared/remote-data.utils';
28 +import {RouterStub} from '../../shared/testing/router.stub';
29 +import { getItemEditRoute } from '../../+item-page/item-page-routing-paths';
25 30
26 31 const infoNotification: INotification = new Notification('id', NotificationType.Info, 'info');
27 32 const warningNotification: INotification = new Notification('id', NotificationType.Warning, 'warning');
28 33 const successNotification: INotification = new Notification('id', NotificationType.Success, 'success');
29 34
30 35 let notificationsService: NotificationsService;
31 36 let formService: DynamicFormService;
32 37 let bitstreamService: BitstreamDataService;
33 38 let bitstreamFormatService: BitstreamFormatDataService;
34 39 let bitstream: Bitstream;
35 40 let selectedFormat: BitstreamFormat;
36 41 let allFormats: BitstreamFormat[];
42 +let router: Router;
43 +let routerStub;
37 44
38 45 describe('EditBitstreamPageComponent', () => {
39 46 let comp: EditBitstreamPageComponent;
40 47 let fixture: ComponentFixture<EditBitstreamPageComponent>;
41 48
42 49 beforeEach(async(() => {
43 50 allFormats = [
44 51 Object.assign({
45 52 id: '1',
46 53 shortDescription: 'Unknown',
98 105 ],
99 106 'dc.title': [
100 107 {
101 108 value: 'Bitstream title'
102 109 }
103 110 ]
104 111 },
105 112 format: observableOf(new RemoteData(false, false, true, null, selectedFormat)),
106 113 _links: {
107 114 self: 'bitstream-selflink'
108 - }
115 + },
116 + bundle: createSuccessfulRemoteDataObject$({
117 + item: createSuccessfulRemoteDataObject$({
118 + uuid: 'some-uuid'
119 + })
120 + })
109 121 });
110 122 bitstreamService = jasmine.createSpyObj('bitstreamService', {
111 123 findById: observableOf(new RemoteData(false, false, true, null, bitstream)),
112 124 update: observableOf(new RemoteData(false, false, true, null, bitstream)),
113 125 updateFormat: observableOf(new RestResponse(true, 200, 'OK')),
114 126 commitUpdates: {},
115 127 patch: {}
116 128 });
117 129 bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', {
118 130 findAll: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), allFormats)))
119 131 });
120 132
133 + const itemPageUrl = `fake-url/some-uuid`;
134 + routerStub = Object.assign(new RouterStub(), {
135 + url: `${itemPageUrl}`
136 + });
121 137 TestBed.configureTestingModule({
122 138 imports: [TranslateModule.forRoot(), RouterTestingModule],
123 139 declarations: [EditBitstreamPageComponent, FileSizePipe, VarDirective],
124 140 providers: [
125 141 { provide: NotificationsService, useValue: notificationsService },
126 142 { provide: DynamicFormService, useValue: formService },
127 143 { provide: ActivatedRoute, useValue: { data: observableOf({ bitstream: new RemoteData(false, false, true, null, bitstream) }), snapshot: { queryParams: {} } } },
128 144 { provide: BitstreamDataService, useValue: bitstreamService },
129 145 { provide: BitstreamFormatDataService, useValue: bitstreamFormatService },
146 + { provide: Router, useValue: routerStub },
130 147 ChangeDetectorRef
131 148 ],
132 149 schemas: [NO_ERRORS_SCHEMA]
133 150 }).compileComponents();
134 151
135 152 }));
136 153
137 154 beforeEach(() => {
138 155 fixture = TestBed.createComponent(EditBitstreamPageComponent);
139 156 comp = fixture.componentInstance;
140 157 fixture.detectChanges();
158 + router = (comp as any).router;
141 159 });
142 160
143 161 describe('on startup', () => {
144 162 let rawForm;
145 163
146 164 beforeEach(() => {
147 165 rawForm = comp.formGroup.getRawValue();
148 166 });
149 167
150 168 it('should fill in the bitstream\'s title', () => {
206 224
207 225 it('should call updateFormat', () => {
208 226 expect(bitstreamService.updateFormat).toHaveBeenCalled();
209 227 });
210 228
211 229 it('should commit the updates', () => {
212 230 expect(bitstreamService.commitUpdates).toHaveBeenCalled();
213 231 });
214 232 });
215 233 });
234 + describe('when the cancel button is clicked', () => {
235 + it('should call navigateToItemEditBitstreams method', () => {
236 + spyOn(comp, 'navigateToItemEditBitstreams');
237 + comp.onCancel();
238 + expect(comp.navigateToItemEditBitstreams).toHaveBeenCalled();
239 + });
240 + });
241 + describe('when navigateToItemEditBitstreams is called, and the component has an itemId', () => {
242 + it('should redirect to the item edit page on the bitstreams tab with the itemId from the component', () => {
243 + comp.itemId = 'some-uuid1'
244 + comp.navigateToItemEditBitstreams();
245 + expect(routerStub.navigate).toHaveBeenCalledWith([getItemEditRoute('some-uuid1'), 'bitstreams']);
246 + });
247 + });
248 + describe('when navigateToItemEditBitstreams is called, and the component does not have an itemId', () => {
249 + it('should redirect to the item edit page on the bitstreams tab with the itemId from the bundle links ', () => {
250 + comp.itemId = undefined;
251 + comp.navigateToItemEditBitstreams();
252 + expect(routerStub.navigate).toHaveBeenCalledWith([getItemEditRoute('some-uuid'), 'bitstreams']);
253 + });
254 + });
216 255 });

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut