mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
Initial tests added (Still failing)
This commit is contained in:
@@ -4,7 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
import { of as observableOf } from 'rxjs/internal/observable/of';
|
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import { DynamicFormControlModel, DynamicFormService } from '@ng-dynamic-forms/core';
|
import { DynamicFormControlModel, DynamicFormService } from '@ng-dynamic-forms/core';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { BitstreamDataService } from '../../core/data/bitstream-data.service';
|
import { BitstreamDataService } from '../../core/data/bitstream-data.service';
|
||||||
@@ -22,6 +22,12 @@ import { PageInfo } from '../../core/shared/page-info.model';
|
|||||||
import { FileSizePipe } from '../../shared/utils/file-size-pipe';
|
import { FileSizePipe } from '../../shared/utils/file-size-pipe';
|
||||||
import { RestResponse } from '../../core/cache/response.models';
|
import { RestResponse } from '../../core/cache/response.models';
|
||||||
import { VarDirective } from '../../shared/utils/var.directive';
|
import { VarDirective } from '../../shared/utils/var.directive';
|
||||||
|
import {
|
||||||
|
createFailedRemoteDataObject$,
|
||||||
|
createSuccessfulRemoteDataObject$
|
||||||
|
} from "../../shared/remote-data.utils";
|
||||||
|
import {getItemPageRoute} from "../../+item-page/item-page-routing.module";
|
||||||
|
import {RouterStub} from "../../shared/testing/router.stub";
|
||||||
|
|
||||||
const infoNotification: INotification = new Notification('id', NotificationType.Info, 'info');
|
const infoNotification: INotification = new Notification('id', NotificationType.Info, 'info');
|
||||||
const warningNotification: INotification = new Notification('id', NotificationType.Warning, 'warning');
|
const warningNotification: INotification = new Notification('id', NotificationType.Warning, 'warning');
|
||||||
@@ -34,6 +40,8 @@ let bitstreamFormatService: BitstreamFormatDataService;
|
|||||||
let bitstream: Bitstream;
|
let bitstream: Bitstream;
|
||||||
let selectedFormat: BitstreamFormat;
|
let selectedFormat: BitstreamFormat;
|
||||||
let allFormats: BitstreamFormat[];
|
let allFormats: BitstreamFormat[];
|
||||||
|
let router: Router;
|
||||||
|
let routerStub;
|
||||||
|
|
||||||
describe('EditBitstreamPageComponent', () => {
|
describe('EditBitstreamPageComponent', () => {
|
||||||
let comp: EditBitstreamPageComponent;
|
let comp: EditBitstreamPageComponent;
|
||||||
@@ -105,7 +113,12 @@ describe('EditBitstreamPageComponent', () => {
|
|||||||
format: observableOf(new RemoteData(false, false, true, null, selectedFormat)),
|
format: observableOf(new RemoteData(false, false, true, null, selectedFormat)),
|
||||||
_links: {
|
_links: {
|
||||||
self: 'bitstream-selflink'
|
self: 'bitstream-selflink'
|
||||||
}
|
},
|
||||||
|
bundle: createFailedRemoteDataObject$({
|
||||||
|
item: createSuccessfulRemoteDataObject$({
|
||||||
|
uuid: 'some-uuid'
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
bitstreamService = jasmine.createSpyObj('bitstreamService', {
|
bitstreamService = jasmine.createSpyObj('bitstreamService', {
|
||||||
findById: observableOf(new RemoteData(false, false, true, null, bitstream)),
|
findById: observableOf(new RemoteData(false, false, true, null, bitstream)),
|
||||||
@@ -118,6 +131,10 @@ describe('EditBitstreamPageComponent', () => {
|
|||||||
findAll: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), allFormats)))
|
findAll: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), allFormats)))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const itemPageUrl = `fake-url/some-uuid`;
|
||||||
|
routerStub = Object.assign(new RouterStub(), {
|
||||||
|
url: `${itemPageUrl}`
|
||||||
|
});
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), RouterTestingModule],
|
imports: [TranslateModule.forRoot(), RouterTestingModule],
|
||||||
declarations: [EditBitstreamPageComponent, FileSizePipe, VarDirective],
|
declarations: [EditBitstreamPageComponent, FileSizePipe, VarDirective],
|
||||||
@@ -127,6 +144,7 @@ describe('EditBitstreamPageComponent', () => {
|
|||||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ bitstream: new RemoteData(false, false, true, null, bitstream) }), snapshot: { queryParams: {} } } },
|
{ provide: ActivatedRoute, useValue: { data: observableOf({ bitstream: new RemoteData(false, false, true, null, bitstream) }), snapshot: { queryParams: {} } } },
|
||||||
{ provide: BitstreamDataService, useValue: bitstreamService },
|
{ provide: BitstreamDataService, useValue: bitstreamService },
|
||||||
{ provide: BitstreamFormatDataService, useValue: bitstreamFormatService },
|
{ provide: BitstreamFormatDataService, useValue: bitstreamFormatService },
|
||||||
|
{ provide: Router, useValue: routerStub },
|
||||||
ChangeDetectorRef
|
ChangeDetectorRef
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
@@ -138,6 +156,7 @@ describe('EditBitstreamPageComponent', () => {
|
|||||||
fixture = TestBed.createComponent(EditBitstreamPageComponent);
|
fixture = TestBed.createComponent(EditBitstreamPageComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
router = (comp as any).router;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('on startup', () => {
|
describe('on startup', () => {
|
||||||
@@ -213,4 +232,11 @@ describe('EditBitstreamPageComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('when the cancel button is clicked', () => {
|
||||||
|
it('should redirect to the item page', () => {
|
||||||
|
comp.onCancel();
|
||||||
|
spyOn(routerStub, 'navigate');
|
||||||
|
expect(routerStub.navigate).toHaveBeenCalledWith([getItemPageRoute('some-uuid')]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user