mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
68346: Test cases
This commit is contained in:
@@ -23,18 +23,43 @@ import { VarDirective } from '../../../shared/utils/var.directive';
|
|||||||
import { Bitstream } from '../../../core/shared/bitstream.model';
|
import { Bitstream } from '../../../core/shared/bitstream.model';
|
||||||
import { BundleDataService } from '../../../core/data/bundle-data.service';
|
import { BundleDataService } from '../../../core/data/bundle-data.service';
|
||||||
import { Bundle } from '../../../core/shared/bundle.model';
|
import { Bundle } from '../../../core/shared/bundle.model';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
describe('UploadBistreamComponent', () => {
|
fdescribe('UploadBistreamComponent', () => {
|
||||||
let comp: UploadBitstreamComponent;
|
let comp: UploadBitstreamComponent;
|
||||||
let fixture: ComponentFixture<UploadBitstreamComponent>;
|
let fixture: ComponentFixture<UploadBitstreamComponent>;
|
||||||
|
|
||||||
const bundle = Object.assign(new Bundle(), {
|
const bundle = Object.assign(new Bundle(), {
|
||||||
id: 'bundle',
|
id: 'bundle',
|
||||||
uuid: 'bundle',
|
uuid: 'bundle',
|
||||||
|
metadata: {
|
||||||
|
'dc.title': [
|
||||||
|
{
|
||||||
|
value: 'bundleName',
|
||||||
|
language: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
_links: {
|
_links: {
|
||||||
self: { href: 'bundle-selflink' }
|
self: { href: 'bundle-selflink' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const customName = 'Custom Name';
|
||||||
|
const createdBundle = Object.assign(new Bundle(), {
|
||||||
|
id: 'created-bundle',
|
||||||
|
uuid: 'created-bundle',
|
||||||
|
metadata: {
|
||||||
|
'dc.title': [
|
||||||
|
{
|
||||||
|
value: customName,
|
||||||
|
language: null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
_links: {
|
||||||
|
self: { href: 'created-bundle-selflink' }
|
||||||
|
}
|
||||||
|
});
|
||||||
const itemName = 'fake-name';
|
const itemName = 'fake-name';
|
||||||
const mockItem = Object.assign(new Item(), {
|
const mockItem = Object.assign(new Item(), {
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
@@ -53,16 +78,19 @@ describe('UploadBistreamComponent', () => {
|
|||||||
const routerStub = new RouterStub();
|
const routerStub = new RouterStub();
|
||||||
const restEndpoint = 'fake-rest-endpoint';
|
const restEndpoint = 'fake-rest-endpoint';
|
||||||
const mockItemDataService = jasmine.createSpyObj('mockItemDataService', {
|
const mockItemDataService = jasmine.createSpyObj('mockItemDataService', {
|
||||||
getBitstreamsEndpoint: observableOf(restEndpoint)
|
getBitstreamsEndpoint: observableOf(restEndpoint),
|
||||||
|
createBundle: createSuccessfulRemoteDataObject$(createdBundle)
|
||||||
});
|
});
|
||||||
const bundleService = jasmine.createSpyObj('bundleService', {
|
const bundleService = jasmine.createSpyObj('bundleService', {
|
||||||
getBitstreamsEndpoint: observableOf(restEndpoint)
|
getBitstreamsEndpoint: observableOf(restEndpoint),
|
||||||
|
findById: createSuccessfulRemoteDataObject$(bundle)
|
||||||
});
|
});
|
||||||
const authToken = 'fake-auth-token';
|
const authToken = 'fake-auth-token';
|
||||||
const authServiceStub = Object.assign(new AuthServiceStub(), {
|
const authServiceStub = Object.assign(new AuthServiceStub(), {
|
||||||
buildAuthHeader: () => authToken
|
buildAuthHeader: () => authToken
|
||||||
});
|
});
|
||||||
const notificationsServiceStub = new NotificationsServiceStub();
|
const notificationsServiceStub = new NotificationsServiceStub();
|
||||||
|
const uploaderComponent = jasmine.createSpyObj('uploaderComponent', ['ngOnInit']);
|
||||||
|
|
||||||
describe('when a file is uploaded', () => {
|
describe('when a file is uploaded', () => {
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
@@ -98,6 +126,65 @@ describe('UploadBistreamComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when a bundle url parameter is present', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
createUploadBitstreamTestingModule({
|
||||||
|
bundle: bundle.id
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
loadFixtureAndComp();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the selected id to the bundle\'s id', () => {
|
||||||
|
expect(comp.selectedBundleId).toEqual(bundle.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the selected name to the bundle\'s name', () => {
|
||||||
|
expect(comp.selectedBundleName).toEqual(bundle.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and bundle name changed', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
comp.bundleNameChange();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should clear out the selected id', () => {
|
||||||
|
expect(comp.selectedBundleId).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when a name is filled in, but no ID is selected', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
createUploadBitstreamTestingModule({});
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
loadFixtureAndComp();
|
||||||
|
comp.selectedBundleName = customName;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('createBundle', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
comp.createBundle();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new bundle', () => {
|
||||||
|
expect(mockItemDataService.createBundle).toHaveBeenCalledWith(mockItem.id, customName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the selected id to the id of the new bundle', () => {
|
||||||
|
expect(comp.selectedBundleId).toEqual(createdBundle.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display a success notification', () => {
|
||||||
|
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup an UploadBitstreamComponent testing module with custom queryParams for the route
|
* Setup an UploadBitstreamComponent testing module with custom queryParams for the route
|
||||||
* @param queryParams
|
* @param queryParams
|
||||||
@@ -109,7 +196,10 @@ describe('UploadBistreamComponent', () => {
|
|||||||
}),
|
}),
|
||||||
queryParams: observableOf(queryParams),
|
queryParams: observableOf(queryParams),
|
||||||
snapshot: {
|
snapshot: {
|
||||||
queryParams: queryParams
|
queryParams: queryParams,
|
||||||
|
params: {
|
||||||
|
id: mockItem.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,6 +225,7 @@ describe('UploadBistreamComponent', () => {
|
|||||||
function loadFixtureAndComp() {
|
function loadFixtureAndComp() {
|
||||||
fixture = TestBed.createComponent(UploadBitstreamComponent);
|
fixture = TestBed.createComponent(UploadBitstreamComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
|
comp.uploaderComponent = uploaderComponent;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,6 +47,9 @@ describe('ItemDataService', () => {
|
|||||||
return cold('a', { a: itemEndpoint });
|
return cold('a', { a: itemEndpoint });
|
||||||
}
|
}
|
||||||
} as HALEndpointService;
|
} as HALEndpointService;
|
||||||
|
const bundleService = jasmine.createSpyObj('bundleService', {
|
||||||
|
findByHref: {}
|
||||||
|
});
|
||||||
|
|
||||||
const scopeID = '4af28e99-6a9c-4036-a199-e1b587046d39';
|
const scopeID = '4af28e99-6a9c-4036-a199-e1b587046d39';
|
||||||
const options = Object.assign(new FindListOptions(), {
|
const options = Object.assign(new FindListOptions(), {
|
||||||
@@ -87,7 +90,8 @@ describe('ItemDataService', () => {
|
|||||||
halEndpointService,
|
halEndpointService,
|
||||||
notificationsService,
|
notificationsService,
|
||||||
http,
|
http,
|
||||||
comparator
|
comparator,
|
||||||
|
bundleService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,4 +216,20 @@ describe('ItemDataService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('createBundle', () => {
|
||||||
|
const itemId = '3de6ea60-ec39-419b-ae6f-065930ac1429';
|
||||||
|
const bundleName = 'ORIGINAL';
|
||||||
|
let result;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
service = initTestService();
|
||||||
|
spyOn(requestService, 'configure');
|
||||||
|
result = service.createBundle(itemId, bundleName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should configure a POST request', () => {
|
||||||
|
result.subscribe(() => expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(PostRequest)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user