Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item-Collection mapper #348

Merged
merged 104 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
6b986c8
55693: Item mapper page + ItemSelectComponent
Atmire-Kristof Sep 26, 2018
315b6a9
55693: Intermediate commit
Atmire-Kristof Sep 26, 2018
3dc0906
55693: Tabset
Atmire-Kristof Sep 26, 2018
9440401
55693: Fixed scope being passed between tabs
Atmire-Kristof Sep 26, 2018
5040d23
55693: (incomplete) store interraction for selecting items
Atmire-Kristof Sep 26, 2018
09a84ed
55693: Working store interaction for selecting items
Atmire-Kristof Sep 27, 2018
ce134bb
55693: emit only once and reset selected items + notification
Atmire-Kristof Sep 27, 2018
4731da8
55693: Intermediate Commit
Atmire-Kristof Sep 27, 2018
6f64b94
Merge branch 'Authentication-issue-fix' into w2p-55693_Item-mapping-t…
Atmire-Kristof Sep 27, 2018
7b74d9c
55693: Notifications on success/failure and small refactoring
Atmire-Kristof Sep 27, 2018
ba8be3f
55693: Temporary pagination fix (remove url params on tab change)
Atmire-Kristof Sep 28, 2018
0a8a6bb
55693: Messages improvement
Atmire-Kristof Sep 28, 2018
e1c734e
55693: CollectionItemMapperComponent test intermediate
Atmire-Kristof Sep 28, 2018
44caed8
Merge branch 'master' into w2p-55693_Item-mapping-to-collections
Atmire-Kristof Sep 28, 2018
95b4635
55693: CollectionItemMapperComponent tests
Atmire-Kristof Sep 28, 2018
c3add84
55693: ItemSelectComponent tests intermediate + ItemSelectServiceStub
Atmire-Kristof Sep 28, 2018
8b99ea4
ItemSelectComponent tests
Atmire-Kristof Oct 1, 2018
7934b87
55693: ItemSelectService tests
Atmire-Kristof Oct 1, 2018
199e6c7
55693: Empty ItemSelectReducer test file
Atmire-Kristof Oct 1, 2018
5f56d59
55693: ItemSelectReducer tests
Atmire-Kristof Oct 1, 2018
24f6f98
55693: Authentication Guard and TSDocs
Atmire-Kristof Oct 1, 2018
ba4d286
55946: Start of Edit Item Page
Atmire-Kristof Oct 8, 2018
3a809cc
55946: Finished edit-item-page and start of collection mapper
Atmire-Kristof Oct 9, 2018
6bc4d06
55946: Intermediate commit
Atmire-Kristof Oct 9, 2018
c25340f
erge branch 'w2p-55946_Item-mapping-on-item-level-old' into w2p-55946…
Atmire-Kristof Oct 9, 2018
7021527
55946: Fixed api calls for fetching collections with/without item
Atmire-Kristof Oct 9, 2018
c4203f2
55946: Refactored item-select to object-select to allow for easier im…
Atmire-Kristof Oct 9, 2018
0b3b5d3
55946: Refactoring of object-select and collection-select component
Atmire-Kristof Oct 10, 2018
0cf91fb
55946: Removal of unnecessary scss files and test fixes
Atmire-Kristof Oct 10, 2018
dd38e61
55946: Functional item-collection-mapper
Atmire-Kristof Oct 10, 2018
378fbe8
55946: Functionality for removing mappings
Atmire-Kristof Oct 10, 2018
497f089
55946: Improvement on mapping by excluding already existing mapped co…
Atmire-Kristof Oct 10, 2018
8f0d7b6
55946: ItemCollectionMapperComponent tests
Atmire-Kristof Oct 11, 2018
fc96700
55946: Fixed search query not working
Atmire-Kristof Oct 11, 2018
3d9e4a6
55693: Mapped items using new REST endpoint + item-select component
Atmire-Kristof Nov 6, 2018
dd36913
55693: Functionality for removing mappings
Atmire-Kristof Nov 6, 2018
9902209
55946: Small import fix
Atmire-Kristof Nov 7, 2018
0d89eb6
55693: TODO location query
Atmire-Kristof Nov 7, 2018
7bd8fae
55693: Fixed getMappedItems to use object cache instead of response
Atmire-Kristof Nov 13, 2018
2a4eebc
Merge branch 'w2p-55693_Item-mapping-to-collections' into w2p-55946_I…
Atmire-Kristof Nov 13, 2018
469b424
55693: Map tab excludes already mapped items
Atmire-Kristof Nov 13, 2018
31fe5ef
Merge branch 'w2p-55693_Item-mapping-to-collections' into w2p-55946_I…
Atmire-Kristof Nov 13, 2018
e61467b
55693: JSDocs and Test fixes
Atmire-Kristof Nov 14, 2018
512b678
Merge branch 'w2p-55693_Item-mapping-to-collections' into w2p-55946_I…
Atmire-Kristof Nov 14, 2018
b11a168
55946: CollectionItemMapper test fixes after merge
Atmire-Kristof Nov 14, 2018
0806315
55946: object-select store lists intermediate commit
Atmire-Kristof Nov 15, 2018
8d396f3
55946: Multi-list object select support
Atmire-Kristof Nov 16, 2018
904ee2c
55693: Search box inside Map tab
Atmire-Kristof Nov 16, 2018
1c013bc
Merge branch 'w2p-55693_Item-mapping-to-collections' into w2p-55946_I…
Atmire-Kristof Nov 16, 2018
3e75bc5
55946: Search box inside Map tab on item-level
Atmire-Kristof Nov 16, 2018
44d18d2
55946: Exclude already mapped collections from Map tab
Atmire-Kristof Nov 16, 2018
7f0e798
Merge branch 'response-cache-refactoring' into w2p-55946_Item-mapping…
Atmire-Kristof Nov 23, 2018
aa172b6
55946: Changes to comply to the new response cache features
Atmire-Kristof Nov 23, 2018
e275fe5
55946: Remove href-to-uuid index cache on mapping
Atmire-Kristof Nov 23, 2018
4307cb0
55946: Clear data/request attached to the hrefs deleted from index
Atmire-Kristof Nov 26, 2018
55e37a6
55946: discovery requests reset and reload and list updates
Atmire-Kristof Nov 27, 2018
2053078
55946: Dynamic reloading of item mapper on item-level
Atmire-Kristof Nov 27, 2018
930af49
55946: Fixed tests and added JSDocs
Atmire-Kristof Nov 27, 2018
32db97e
55946: Spec file fixes
Atmire-Kristof Nov 30, 2018
791325f
55946: TSLint fixes
Atmire-Kristof Dec 7, 2018
0193893
Merge branch 'response-cache-refactoring' into w2p-55946_Item-mapping…
Atmire-Kristof Dec 19, 2018
8bbc89d
Merge branch 'response-cache-refactoring' into w2p-55946_Item-mapping…
Atmire-Kristof Dec 20, 2018
c242ba0
Merge branch 'response-cache-refactoring' into w2p-55946_Item-mapping…
Atmire-Kristof Dec 20, 2018
90b4a0b
55946: Fixed imports and declarations on ItemCollectionMapperComponen…
Atmire-Kristof Dec 20, 2018
1f19324
55946: fdescribe to describe
Atmire-Kristof Dec 20, 2018
f2bfdbc
55946: Prevent list update from calling mapper over and over
Atmire-Kristof Dec 20, 2018
69f4846
55946: Removed console log
Atmire-Kristof Dec 20, 2018
13c1a55
55946: Remove TODOs (fixed)
Atmire-Kristof Dec 21, 2018
6e7024e
Merge branch 'master' into w2p-55946_Item-mapping-on-item-level
Atmire-Kristof Dec 21, 2018
aeba5d6
55946: Destroy on hide to prevent pagination issues
Atmire-Kristof Dec 31, 2018
eb7b4cb
55946: Destroy on hide to prevent pagination issues 2
Atmire-Kristof Dec 31, 2018
532cd4d
Merge branch 'master' into w2p-55946_Item-mapping-on-item-level
Atmire-Kristof Dec 31, 2018
0b164b3
remove unused 'first' imports
artlowel Jan 10, 2019
04ad79e
remove exportToZip config property that was added accidentally
artlowel Jan 10, 2019
ff924ab
fix a typo in a comment
artlowel Jan 10, 2019
47294d3
Merge branch 'master' into Item-Collection_Mapper
Atmire-Kristof Jan 17, 2019
41e14e1
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof May 28, 2019
2b1fd76
62589: Fixed order of imports messing with routes
Atmire-Kristof May 28, 2019
045b87c
62589: Post-Merge Tests and error fixes
Atmire-Kristof May 28, 2019
28fe62f
62589: Fix mappedCollections endpoint
Atmire-Kristof May 29, 2019
df730ef
62589: Provider and POST item-collection mapping fix
Atmire-Kristof May 29, 2019
acf83f6
62589: Test provider fix
Atmire-Kristof May 29, 2019
3868b0a
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Jun 7, 2019
cc389e1
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Jun 18, 2019
2f0a5a4
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Aug 12, 2019
26e2506
62589: PR Feedback
Atmire-Kristof Aug 12, 2019
c95fa8f
62589: Refactoring mapping endpoint and methods to mapped + collectio…
Atmire-Kristof Aug 19, 2019
04f57b7
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Sep 5, 2019
7fe0db7
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Sep 6, 2019
02b007a
62589: Exclude owning collection + redirect to first tab after mappin…
Atmire-Kristof Sep 10, 2019
8b5a3ac
Merge branch 'master' of https://git.atmire.com/contributions/dspace-…
Atmire-Kristof Sep 11, 2019
1b0b1d7
62589: Fixed import
Atmire-Kristof Sep 11, 2019
683c19b
Merge remote-tracking branch 'atmire/upgrade-travis-image' into w2p-6…
Atmire-Kristof Sep 16, 2019
4f6c3c0
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Sep 16, 2019
647bfb4
62589: Import fix
Atmire-Kristof Sep 16, 2019
a87dc89
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Sep 19, 2019
f83e31a
Merge remote-tracking branch 'dspace/master' into w2p-62589_Item-mapp…
Atmire-Kristof Sep 27, 2019
145ed34
62589: Feedback improvements and fixes
Atmire-Kristof Sep 27, 2019
a2fb8a3
62589: Added tests for more coverage
Atmire-Kristof Sep 30, 2019
3c8e35e
Merge branch 'master' into w2p-62589_Item-mapper-update
Atmire-Kristof Sep 30, 2019
b8a466d
62589: Loading components for item and collection select lists
Atmire-Kristof Sep 30, 2019
8652c4b
62589: Fixed test imports
Atmire-Kristof Sep 30, 2019
5b776b6
62589: Review 03-10-2019 Changes and fixes
Atmire-Kristof Oct 8, 2019
f7bd30c
62589: Item-Mapper Requests responseMsToLive to 10s
Atmire-Kristof Oct 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions config/environment.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ module.exports = {
// Caching settings
cache: {
// NOTE: how long should objects be cached for by default
msToLive: 15 * 60 * 1000, // 15 minutes
msToLive: {
default: 15 * 60 * 1000, // 15 minutes
exportToZip: 5 * 1000 // 5 seconds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me what these new settings in environment.default.js are for. Are these an unrelated change, or maybe local configuration?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR includes the same response cache refactor @LotteHofstede's #349 PR is based on. It adds the ability to cache certain responses for different lengths of time. (e.g. you may want to cache most responses for 15 minutes, but for certain admin features you may want to disable the cache, or cache it a very short time) However the exportToZip config is something that snuck in from an unrelated branch i.e. the export to zip feature that is on hold atm waiting for the scripts and processes work on the REST side. We'll remove it

},
// msToLive: 1000, // 15 minutes
control: 'max-age=60' // revalidate browser
control: 'max-age=60', // revalidate browser
autoSync: {
defaultTime: 0,
maxBufferSize: 100,
timePerMethod: {'PATCH': 3} //time in seconds
}
},
// Form settings
form: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"core-js": "^2.5.7",
"express": "4.16.2",
"express-session": "1.15.6",
"fast-json-patch": "^2.0.7",
"font-awesome": "4.7.0",
"fork-ts-checker-webpack-plugin": "^0.4.10",
"http-server": "0.11.1",
Expand Down
137 changes: 137 additions & 0 deletions resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@
"head": "Recent Submissions"
}
}
},
"item-mapper": {
"head": "Item Mapper - Map Items from Other Collections",
"collection": "Collection: \"<b>{{name}}</b>\"",
"description": "This is the item mapper tool that allows collection administrators to map items from other collections into this collection. You can search for items from other collections and map them, or browse the list of currently mapped items.",
"confirm": "Map selected items",
"remove": "Remove selected item mappings",
"tabs": {
"browse": "Browse",
"map": "Map"
},
"notifications": {
"map": {
"success": {
"head": "Mapping completed",
"content": "Successfully mapped {{amount}} items."
},
"error": {
"head": "Mapping errors",
"content": "Errors occurred for mapping of {{amount}} items."
}
},
"unmap": {
"success": {
"head": "Remove mapping completed",
"content": "Successfully removed the mappings of {{amount}} items."
},
"error": {
"head": "Remove mapping errors",
"content": "Errors occurred for removing the mappings of {{amount}} items."
}
}
},
"return": "Return"
},
"select": {
"table": {
"title": "Title"
},
"confirm": "Confirm selected"
}
},
"community": {
Expand Down Expand Up @@ -46,6 +86,103 @@
"simple": "Simple item page",
"full": "Full item page"
}
},
"select": {
"table": {
"collection": "Collection",
"author": "Author",
"title": "Title"
},
"confirm": "Confirm selected"
},
"edit": {
"head": "Edit Item",
"tabs": {
"status": {
"head": "Item Status",
"description": "Welcome to the item management page. From here you can withdraw, reinstate, move or delete the item. You may also update or add new metadata / bitstreams on the other tabs.",
"labels": {
"id": "Item Internal ID",
"handle": "Handle",
"lastModified": "Last Modified",
"itemPage": "Item Page"
},
"buttons": {
"authorizations": {
"label": "Edit item's authorization policies",
"button": "Authorizations..."
},
"withdraw": {
"label": "Withdraw item from the repository",
"button": "Withdraw..."
},
"move": {
"label": "Move item to another collection",
"button": "Move..."
},
"private": {
"label": "Make item private",
"button": "Make it private..."
},
"delete": {
"label": "Completely expunge item",
"button": "Permanently delete"
},
"mappedCollections": {
"label": "Manage mapped collections",
"button": "Mapped collections"
}
}
},
"bitstreams": {
"head": "Item Bitstreams"
},
"metadata": {
"head": "Item Metadata"
},
"view": {
"head": "View Item"
},
"curate": {
"head": "Curate"
}
},
"item-mapper": {
"head": "Item Mapper - Map Item to Collections",
"item": "Item: \"<b>{{name}}</b>\"",
"description": "This is the item mapper tool that allows administrators to map this item to other collections. You can search for collections and map them, or browse the list of collections the item is currently mapped to.",
"tabs": {
"browse": "Browse",
"map": "Map"
},
"buttons": {
"add": "Map item to selected collections",
"remove": "Remove item's mapping for selected collections"
},
"notifications": {
"add": {
"success": {
"head": "Mapping completed",
"content": "Successfully mapped item to {{amount}} collections."
},
"error": {
"head": "Mapping errors",
"content": "Errors occurred for mapping of item to {{amount}} collections."
}
},
"remove": {
"success": {
"head": "Removal of mapping completed",
"content": "Successfully removed mapping of item to {{amount}} collections."
},
"error": {
"head": "Removal of mapping errors",
"content": "Errors occurred for the removal of the mapping to {{amount}} collections."
}
}
},
"return": "Return"
}
}
},
"nav": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="container">
<div class="row">
<div class="col-12">
<h2>{{'collection.item-mapper.head' | translate}}</h2>
<p [innerHTML]="'collection.item-mapper.collection' | translate:{ name: (collectionRD$ | async)?.payload?.name }" id="collection-name"></p>
<p>{{'collection.item-mapper.description' | translate}}</p>

<ngb-tabset (tabChange)="tabChange($event)" [destroyOnHide]="true">
<ngb-tab title="{{'collection.item-mapper.tabs.browse' | translate}}">
<ng-template ngbTabContent>
<div class="mt-2">
<ds-item-select class="mt-2"
[key]="'browse'"
[dsoRD$]="collectionItemsRD$"
[paginationOptions]="(searchOptions$ | async)?.pagination"
[confirmButton]="'collection.item-mapper.remove'"
[hideCollection]="true"
(confirm)="mapItems($event, true)"></ds-item-select>
</div>
</ng-template>
</ngb-tab>
<ngb-tab title="{{'collection.item-mapper.tabs.map' | translate}}">
<ng-template ngbTabContent>
<div class="row mt-2">
<div class="col-12 col-lg-6">
<ds-search-form id="search-form"
[query]="(searchOptions$ | async)?.query"
[scope]="(searchOptions$ | async)?.scope"
[currentUrl]="getCurrentUrl()">
</ds-search-form>
</div>
</div>

<div>
<ds-item-select class="mt-2"
[key]="'map'"
[dsoRD$]="mappingItemsRD$"
[paginationOptions]="(searchOptions$ | async)?.pagination"
[confirmButton]="'collection.item-mapper.confirm'"
(confirm)="mapItems($event)"></ds-item-select>
</div>
</ng-template>
</ngb-tab>
</ngb-tabset>

<button [routerLink]="['/collections/', (collectionRD$ | async)?.payload?.id]" class="btn btn-outline-secondary">{{'collection.item-mapper.return' | translate}}</button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import '../../../styles/variables.scss';
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { CollectionItemMapperComponent } from './collection-item-mapper.component';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { CommonModule } from '@angular/common';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { SearchFormComponent } from '../../shared/search-form/search-form.component';
import { SearchPageModule } from '../../+search-page/search-page.module';
import { ObjectCollectionComponent } from '../../shared/object-collection/object-collection.component';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
import { RouterStub } from '../../shared/testing/router-stub';
import { SearchConfigurationService } from '../../+search-page/search-service/search-configuration.service';
import { SearchService } from '../../+search-page/search-service/search.service';
import { SearchServiceStub } from '../../shared/testing/search-service-stub';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service-stub';
import { ItemDataService } from '../../core/data/item-data.service';
import { FormsModule } from '@angular/forms';
import { SharedModule } from '../../shared/shared.module';
import { Collection } from '../../core/shared/collection.model';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
import { EventEmitter, NgModule } from '@angular/core';
import { HostWindowService } from '../../shared/host-window.service';
import { HostWindowServiceStub } from '../../shared/testing/host-window-service-stub';
import { By } from '@angular/platform-browser';
import { PaginatedList } from '../../core/data/paginated-list';
import { PageInfo } from '../../core/shared/page-info.model';
import { CollectionDataService } from '../../core/data/collection-data.service';
import { PaginationComponent } from '../../shared/pagination/pagination.component';
import { EnumKeysPipe } from '../../shared/utils/enum-keys-pipe';
import { ItemSelectComponent } from '../../shared/object-select/item-select/item-select.component';
import { ObjectSelectService } from '../../shared/object-select/object-select.service';
import { ObjectSelectServiceStub } from '../../shared/testing/object-select-service-stub';
import { VarDirective } from '../../shared/utils/var.directive';
import { Observable } from 'rxjs/internal/Observable';
import { of } from 'rxjs/internal/observable/of';
import { RestResponse } from '../../core/cache/response.models';

describe('CollectionItemMapperComponent', () => {
let comp: CollectionItemMapperComponent;
let fixture: ComponentFixture<CollectionItemMapperComponent>;

let route: ActivatedRoute;
let router: Router;
let searchConfigService: SearchConfigurationService;
let searchService: SearchService;
let notificationsService: NotificationsService;
let itemDataService: ItemDataService;

const mockCollection: Collection = Object.assign(new Collection(), {
id: 'ce41d451-97ed-4a9c-94a1-7de34f16a9f4',
name: 'test-collection'
});
const mockCollectionRD: RemoteData<Collection> = new RemoteData<Collection>(false, false, true, null, mockCollection);
const mockSearchOptions = of(new PaginatedSearchOptions({
pagination: Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration',
pageSize: 10,
currentPage: 1
}),
sort: new SortOptions('dc.title', SortDirection.ASC),
scope: mockCollection.id
}));
const routerStub = Object.assign(new RouterStub(), {
url: 'http://test.url'
});
const searchConfigServiceStub = {
paginatedSearchOptions: mockSearchOptions
};
const itemDataServiceStub = {
mapToCollection: () => of(new RestResponse(true, '200'))
};
const activatedRouteStub = new ActivatedRouteStub({}, { collection: mockCollectionRD });
const translateServiceStub = {
get: () => of('test-message of collection ' + mockCollection.name),
onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
};
const emptyList = new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), []));
const searchServiceStub = Object.assign(new SearchServiceStub(), {
search: () => of(emptyList),
/* tslint:disable:no-empty */
clearDiscoveryRequests: () => {}
/* tslint:enable:no-empty */
});
const collectionDataServiceStub = {
getMappedItems: () => of(emptyList),
/* tslint:disable:no-empty */
clearMappingItemsRequests: () => {}
/* tslint:enable:no-empty */
};

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule.forRoot()],
declarations: [CollectionItemMapperComponent, ItemSelectComponent, SearchFormComponent, PaginationComponent, EnumKeysPipe, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useValue: routerStub },
{ provide: SearchConfigurationService, useValue: searchConfigServiceStub },
{ provide: SearchService, useValue: searchServiceStub },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: ItemDataService, useValue: itemDataServiceStub },
{ provide: CollectionDataService, useValue: collectionDataServiceStub },
{ provide: TranslateService, useValue: translateServiceStub },
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
{ provide: ObjectSelectService, useValue: new ObjectSelectServiceStub() }
]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CollectionItemMapperComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
route = (comp as any).route;
router = (comp as any).router;
searchConfigService = (comp as any).searchConfigService;
searchService = (comp as any).searchService;
notificationsService = (comp as any).notificationsService;
itemDataService = (comp as any).itemDataService;
});

it('should display the correct collection name', () => {
const name: HTMLElement = fixture.debugElement.query(By.css('#collection-name')).nativeElement;
expect(name.innerHTML).toContain(mockCollection.name);
});

describe('mapItems', () => {
const ids = ['id1', 'id2', 'id3', 'id4'];

beforeEach(() => {
spyOn(notificationsService, 'success').and.callThrough();
spyOn(notificationsService, 'error').and.callThrough();
});

it('should display a success message if at least one mapping was successful', () => {
comp.mapItems(ids);
expect(notificationsService.success).toHaveBeenCalled();
expect(notificationsService.error).not.toHaveBeenCalled();
});

it('should display an error message if at least one mapping was unsuccessful', () => {
spyOn(itemDataService, 'mapToCollection').and.returnValue(of(new RestResponse(false, '404')));
comp.mapItems(ids);
expect(notificationsService.success).not.toHaveBeenCalled();
expect(notificationsService.error).toHaveBeenCalled();
});
});

});
Loading