Skip to content
Snippets Groups Projects
Commit 74bf69f9 authored by Yana De Pauw's avatar Yana De Pauw
Browse files

62571: Move item update and test fixes

parent d55e2341
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ import { ItemMetadataComponent } from './item-metadata/item-metadata.component';
import { EditInPlaceFieldComponent } from './item-metadata/edit-in-place-field/edit-in-place-field.component';
import { ItemBitstreamsComponent } from './item-bitstreams/item-bitstreams.component';
import { ItemMoveComponent } from './item-move/item-move.component';
import { EditItemPageRoutingModule } from './edit-item-page.routing.module';
/**
* Module that contains all components related to the Edit Item page administrator functionality
......@@ -23,6 +24,7 @@ import { ItemMoveComponent } from './item-move/item-move.component';
imports: [
CommonModule,
SharedModule,
EditItemPageRoutingModule
],
declarations: [
EditItemPageComponent,
......
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {Item} from '../../../core/shared/item.model';
import {RouterStub} from '../../../shared/testing/router-stub';
import {CommonModule} from '@angular/common';
import {RouterTestingModule} from '@angular/router/testing';
import {TranslateModule} from '@ngx-translate/core';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import {ActivatedRoute, Router} from '@angular/router';
import {ItemMoveComponent} from './item-move.component';
import {NotificationsServiceStub} from '../../../shared/testing/notifications-service-stub';
import {NotificationsService} from '../../../shared/notifications/notifications.service';
import {SearchService} from '../../../+search-page/search-service/search.service';
import {of as observableOf} from 'rxjs';
import {FormsModule} from '@angular/forms';
import {ItemDataService} from '../../../core/data/item-data.service';
import {RemoteData} from '../../../core/data/remote-data';
import {PaginatedList} from '../../../core/data/paginated-list';
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Item } from '../../../core/shared/item.model';
import { RouterStub } from '../../../shared/testing/router-stub';
import { CommonModule } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { ActivatedRoute, Router } from '@angular/router';
import { ItemMoveComponent } from './item-move.component';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service-stub';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { SearchService } from '../../../+search-page/search-service/search.service';
import { of as observableOf } from 'rxjs';
import { FormsModule } from '@angular/forms';
import { ItemDataService } from '../../../core/data/item-data.service';
import { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { RestResponse } from '../../../core/cache/response.models';
import { Collection } from '../../../core/shared/collection.model';
describe('ItemMoveComponent', () => {
let comp: ItemMoveComponent;
......@@ -49,20 +50,28 @@ describe('ItemMoveComponent', () => {
})
};
const collection1 = Object.assign(new Collection(),{
uuid: 'collection-uuid-1',
name: 'Test collection 1',
self: 'self-link-1',
});
const collection2 = Object.assign(new Collection(),{
uuid: 'collection-uuid-2',
name: 'Test collection 2',
self: 'self-link-2',
});
const mockSearchService = {
search: () => {
return observableOf(new RemoteData(false, false, true, null,
new PaginatedList(null, [
{
dspaceObject: {
name: 'Test collection 1',
uuid: 'collection1'
}, hitHighlights: {}
indexableObject: collection1,
hitHighlights: {}
}, {
dspaceObject: {
name: 'Test collection 2',
uuid: 'collection2'
}, hitHighlights: {}
indexableObject: collection2,
hitHighlights: {}
}
])));
}
......@@ -98,14 +107,14 @@ describe('ItemMoveComponent', () => {
displayValue: 'Test collection 1',
value: {
name: 'Test collection 1',
id: 'collection1',
object: collection1,
}
},
{
displayValue: 'Test collection 2',
value: {
name: 'Test collection 2',
id: 'collection2',
object: collection2,
}
}
];
......@@ -121,24 +130,23 @@ describe('ItemMoveComponent', () => {
it('should on click select the correct collection name and id', () => {
const data = {
name: 'Test collection 1',
id: 'collection1',
object: collection1,
};
comp.onClick(data);
expect(comp.selectedCollection).toEqual('Test collection 1');
expect(comp.selectedCollectionId).toEqual('collection1');
expect(comp.selectedCollectionObject).toEqual(collection1);
});
describe('moveCollection', () => {
it('should call itemDataService.moveToCollection', () => {
comp.itemId = 'item-id';
comp.selectedCollectionId = 'selected-collection-id';
comp.selectedCollection = 'selected-collection-id';
comp.selectedCollectionObject = collection1;
comp.moveCollection();
expect(mockItemDataService.moveToCollection).toHaveBeenCalledWith('item-id', 'selected-collection-id');
expect(mockItemDataService.moveToCollection).toHaveBeenCalledWith('item-id', collection1);
});
it('should call notificationsService success message on success', () => {
// spyOn(notificationsServiceStub, 'success');
comp.moveCollection();
expect(notificationsServiceStub.success).toHaveBeenCalled();
......@@ -170,8 +178,6 @@ describe('ItemMoveComponent', () => {
});
it('should call notificationsService error message on fail', () => {
// spyOn(notificationsServiceStub, 'error');
comp.moveCollection();
expect(notificationsServiceStub.error).toHaveBeenCalled();
......
......@@ -37,7 +37,6 @@ export class ItemMoveComponent implements OnInit {
selectedCollection: string;
selectedCollectionObject: Collection;
selectedCollectionId: string;
itemId: string;
constructor(private route: ActivatedRoute,
......@@ -78,8 +77,8 @@ export class ItemMoveComponent implements OnInit {
map((rd: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) => {
return rd.payload.page.map((searchResult) => {
return {
displayValue: searchResult.dspaceObject.name,
value: {name: searchResult.dspaceObject.name, id: searchResult.dspaceObject.uuid}
displayValue: searchResult.indexableObject.name,
value: {name: searchResult.indexableObject.name, object: searchResult.indexableObject}
};
});
})
......@@ -93,8 +92,7 @@ export class ItemMoveComponent implements OnInit {
*/
onClick(data: any): void {
this.selectedCollection = data.name;
this.selectedCollectionId = data.id;
this.selectedCollectionObject = data;
this.selectedCollectionObject = data.object;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment