diff --git a/src/app/shared/mocks/external-source.service.mock.ts b/src/app/shared/mocks/external-source.service.mock.ts
index fd6d7cdc46..89b2927939 100644
--- a/src/app/shared/mocks/external-source.service.mock.ts
+++ b/src/app/shared/mocks/external-source.service.mock.ts
@@ -53,6 +53,7 @@ export const externalSourceMyStaffDb: ExternalSource = {
export function getMockExternalSourceService(): ExternalSourceService {
return jasmine.createSpyObj('ExternalSourceService', {
findAll: jasmine.createSpy('findAll'),
+ searchBy: jasmine.createSpy('searchBy'),
getExternalSourceEntries: jasmine.createSpy('getExternalSourceEntries'),
});
}
diff --git a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html
index 73b41378c8..e1f03c40d5 100644
--- a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html
+++ b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.html
@@ -5,7 +5,12 @@
-
+
+
diff --git a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.spec.ts b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.spec.ts
index 1247eda0dc..3fb2d971b5 100644
--- a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.spec.ts
+++ b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.spec.ts
@@ -1,10 +1,11 @@
-import { Component, NO_ERRORS_SCHEMA, EventEmitter } from '@angular/core';
-import { waitForAsync, TestBed, ComponentFixture, inject } from '@angular/core/testing';
+import { Component, EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core';
+import { ComponentFixture, fakeAsync, inject, TestBed, waitForAsync } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { createTestComponent } from '../../../shared/testing/utils.test';
import { SubmissionImportExternalCollectionComponent } from './submission-import-external-collection.component';
import { CollectionListEntry } from '../../../shared/collection-dropdown/collection-dropdown.component';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
+import { By } from '@angular/platform-browser';
describe('SubmissionImportExternalCollectionComponent test suite', () => {
let comp: SubmissionImportExternalCollectionComponent;
@@ -76,6 +77,48 @@ describe('SubmissionImportExternalCollectionComponent test suite', () => {
expect(compAsAny.activeModal.dismiss).toHaveBeenCalled();
});
+
+ it('should be in loading state when hasChoice variable is different to true', () => {
+ comp.hasChoice = null;
+ expect(comp.isLoading()).toBeTrue();
+
+ comp.hasChoice = false;
+ expect(comp.isLoading()).toBeTrue();
+
+ comp.hasChoice = true;
+ expect(comp.isLoading()).toBeFalse();
+ });
+
+ it('should set hasChoice variable on hasChoice event', () => {
+ comp.hasChoice = null;
+
+ comp.onHasChoice(true);
+ expect(comp.hasChoice).toBe(true);
+
+ comp.onHasChoice(false);
+ expect(comp.hasChoice).toBe(false);
+ });
+
+ it('should emit theOnlySelectable', () => {
+ spyOn(comp.selectedEvent, 'emit').and.callThrough();
+
+ const selected: any = {};
+ comp.theOnlySelectable(selected);
+
+ expect(comp.selectedEvent.emit).toHaveBeenCalledWith(selected);
+ });
+
+ it('dropdown should be invisible when the component is loading', fakeAsync(() => {
+
+ spyOn(comp, 'isLoading').and.returnValue(true);
+ fixture.detectChanges();
+
+ fixture.whenStable().then(() => {
+ const dropdownMenu = fixture.debugElement.query(By.css('ds-collection-dropdown')).nativeElement;
+ expect(dropdownMenu.classList).toContain('d-none');
+ });
+ }));
+
});
});
diff --git a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.ts b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.ts
index cbac0cb710..588bce89f9 100644
--- a/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.ts
+++ b/src/app/submission/import-external/import-external-collection/submission-import-external-collection.component.ts
@@ -1,4 +1,4 @@
-import { Component, Output, EventEmitter } from '@angular/core';
+import { Component, EventEmitter, Output } from '@angular/core';
import { CollectionListEntry } from '../../../shared/collection-dropdown/collection-dropdown.component';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@@ -16,6 +16,16 @@ export class SubmissionImportExternalCollectionComponent {
*/
@Output() public selectedEvent = new EventEmitter();
+ /**
+ * If present this value is used to filter collection list by entity type
+ */
+ public entityType: string;
+
+ /**
+ * If a collection choice is available
+ */
+ public hasChoice: boolean = null;
+
/**
* Initialize the component variables.
* @param {NgbActiveModal} activeModal
@@ -37,4 +47,27 @@ export class SubmissionImportExternalCollectionComponent {
public closeCollectionModal(): void {
this.activeModal.dismiss(false);
}
+
+ /**
+ * Propagate the onlySelectable collection
+ * @param theOnlySelectable
+ */
+ public theOnlySelectable(theOnlySelectable: CollectionListEntry) {
+ this.selectedEvent.emit(theOnlySelectable);
+ }
+
+ /**
+ * Set the hasChoice state
+ * @param hasChoice
+ */
+ public onHasChoice(hasChoice: boolean) {
+ this.hasChoice = hasChoice;
+ }
+
+ /**
+ * If the component is in loading state.
+ */
+ public isLoading(): boolean {
+ return this.hasChoice !== true;
+ }
}
diff --git a/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.html b/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.html
index 83c1ed82b6..bbb0dbcc94 100644
--- a/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.html
+++ b/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.html
@@ -1,5 +1,5 @@