From d6a5d9d1ddf96bb792a5fd3db23534acd9a7dad2 Mon Sep 17 00:00:00 2001 From: Matteo Perelli Date: Mon, 6 Jul 2020 09:12:18 +0200 Subject: [PATCH] CI test fix, buttons and searchbar style fix and service methods removed --- .../my-dspace-new-submission.component.html | 10 ++++--- ...my-dspace-new-submission.component.spec.ts | 5 +++- .../my-dspace-new-submission.component.ts | 15 ++++++++-- .../core/data/external-source.service.spec.ts | 17 ----------- src/app/core/data/external-source.service.ts | 28 ------------------- .../mocks/external-source.service.mock.ts | 2 +- ...-import-external-preview.component.spec.ts | 7 ++++- ...n-import-external-searchbar.component.html | 9 ++++-- ...mport-external-searchbar.component.spec.ts | 5 +++- ...ion-import-external-searchbar.component.ts | 14 ++++++++-- src/assets/i18n/en.json5 | 6 ++-- 11 files changed, 55 insertions(+), 63 deletions(-) diff --git a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.html b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.html index da5519eb07..248909b215 100644 --- a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.html +++ b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.html @@ -7,11 +7,13 @@
- - - {{'mydspace.new-submission-external' | translate}} +
+
+ + {{'mydspace.new-submission-external-short' | translate}}
diff --git a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.spec.ts b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.spec.ts index 16b50d18f0..f2687e452c 100644 --- a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.spec.ts +++ b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.spec.ts @@ -23,6 +23,8 @@ import { getMockScrollToService } from '../../shared/mocks/scroll-to-service.moc import { UploaderService } from '../../shared/uploader/uploader.service'; import { By } from '@angular/platform-browser'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { HostWindowService } from '../../shared/host-window.service'; +import { HostWindowServiceStub } from '../../shared/testing/host-window-service.stub'; describe('MyDSpaceNewSubmissionComponent test', () => { @@ -63,7 +65,8 @@ describe('MyDSpaceNewSubmissionComponent test', () => { }, ChangeDetectorRef, MyDSpaceNewSubmissionComponent, - UploaderService + UploaderService, + { provide: HostWindowService, useValue: new HostWindowServiceStub(800) }, ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts index 8d20a5736a..e3cf19bf8a 100644 --- a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts +++ b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectorRef, Component, EventEmitter, OnDestroy, OnInit, Output } from '@angular/core'; -import { Subscription } from 'rxjs'; +import { Subscription, Observable } from 'rxjs'; import { first } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { TranslateService } from '@ngx-translate/core'; @@ -18,6 +18,7 @@ import { SearchResult } from '../../shared/search/search-result.model'; import { Router } from '@angular/router'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { CreateItemParentSelectorComponent } from 'src/app/shared/dso-selector/modal-wrappers/create-item-parent-selector/create-item-parent-selector.component'; +import { HostWindowService } from '../../shared/host-window.service'; /** * This component represents the whole mydspace page header @@ -38,6 +39,11 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit { */ public uploadFilesOptions: UploaderOptions = new UploaderOptions(); + /** + * Emits true if were on a small screen + */ + public isXsOrSm$: Observable; + /** * Subscription to unsubscribe from */ @@ -52,6 +58,9 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit { * @param {NotificationsService} notificationsService * @param {Store} store * @param {TranslateService} translate + * @param {Router} router + * @param {NgbModal} modalService + * @param {HostWindowService} windowService */ constructor(private authService: AuthService, private changeDetectorRef: ChangeDetectorRef, @@ -60,7 +69,8 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit { private store: Store, private translate: TranslateService, private router: Router, - private modalService: NgbModal) { + private modalService: NgbModal, + protected windowService: HostWindowService) { } /** @@ -73,6 +83,7 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit { this.changeDetectorRef.detectChanges(); } ); + this.isXsOrSm$ = this.windowService.isXsOrSm(); } /** diff --git a/src/app/core/data/external-source.service.spec.ts b/src/app/core/data/external-source.service.spec.ts index 2fc4589bed..7c7d676bc7 100644 --- a/src/app/core/data/external-source.service.spec.ts +++ b/src/app/core/data/external-source.service.spec.ts @@ -74,21 +74,4 @@ describe('ExternalSourceService', () => { }); }); }); - - describe('getAllExternalSources', () => { - it('should call findAll', () => { - spyOn(service, 'findAll'); - service.getAllExternalSources(); - expect(service.findAll).toHaveBeenCalled(); - }); - }); - - describe('getExternalSource', () => { - it('should call findById', () => { - const externalSourceId = 'orcidV2'; - spyOn(service, 'findById'); - service.getExternalSource(externalSourceId); - expect(service.findById).toHaveBeenCalledWith(externalSourceId); - }); - }); }); diff --git a/src/app/core/data/external-source.service.ts b/src/app/core/data/external-source.service.ts index 0d84639a40..edc538a39b 100644 --- a/src/app/core/data/external-source.service.ts +++ b/src/app/core/data/external-source.service.ts @@ -60,34 +60,6 @@ export class ExternalSourceService extends DataService { ); } - /** - * Return a single external source. - * - * @param id - * The external source id. - * @param linksToFollow - * List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved. - * @return Observable> - * The list of the external sources. - */ - getExternalSource(id: string, ...linksToFollow: Array>): Observable> { - return this.findById(id, ...linksToFollow); - } - - /** - * Return the list of external sources. - * - * @param options - * Find list options object. - * @param linksToFollow - * List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved. - * @return Observable>> - * The list of the external sources. - */ - getAllExternalSources(options: FindListOptions = {}, ...linksToFollow: Array>): Observable>> { - return this.findAll(options, ...linksToFollow); - } - /** * Get the entries for an external source * @param externalSourceId The id of the external source to fetch entries for diff --git a/src/app/shared/mocks/external-source.service.mock.ts b/src/app/shared/mocks/external-source.service.mock.ts index 3e96eb508e..85d63189e5 100644 --- a/src/app/shared/mocks/external-source.service.mock.ts +++ b/src/app/shared/mocks/external-source.service.mock.ts @@ -53,7 +53,7 @@ export const externalSourceMyStaffDb: ExternalSource = { export function getMockExternalSourceService(): ExternalSourceService { return jasmine.createSpyObj('ExternalSourceService', { - getAllExternalSources: jasmine.createSpy('getAllExternalSources'), + findAll: jasmine.createSpy('findAll'), getExternalSourceEntries: jasmine.createSpy('getExternalSourceEntries'), }); } diff --git a/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.spec.ts b/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.spec.ts index 3bb6a19645..29b0094b69 100644 --- a/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.spec.ts +++ b/src/app/submission/import-external/import-external-preview/submission-import-external-preview.component.spec.ts @@ -3,7 +3,9 @@ import { async, TestBed, ComponentFixture, inject } from '@angular/core/testing' import { TranslateModule } from '@ngx-translate/core'; import { Router } from '@angular/router'; import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { TestScheduler } from 'rxjs/testing'; import { of as observableOf, of } from 'rxjs/internal/observable/of'; +import { getTestScheduler } from 'jasmine-marbles'; import { SubmissionImportExternalPreviewComponent } from './submission-import-external-preview.component'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { RouterStub } from '../../../shared/testing/router.stub'; @@ -21,6 +23,7 @@ describe('SubmissionImportExternalPreviewComponent test suite', () => { let compAsAny: any; let fixture: ComponentFixture; let submissionServiceStub: SubmissionServiceStub; + let scheduler: TestScheduler; const ngbActiveModal = jasmine.createSpyObj('modal', ['close', 'dismiss']); const ngbModal = jasmine.createSpyObj('modal', ['open']); const externalEntry = Object.assign(new ExternalSourceEntry(), { @@ -38,6 +41,7 @@ describe('SubmissionImportExternalPreviewComponent test suite', () => { }); beforeEach(async (() => { + scheduler = getTestScheduler(); TestBed.configureTestingModule({ imports: [ TranslateModule.forRoot() @@ -134,7 +138,8 @@ describe('SubmissionImportExternalPreviewComponent test suite', () => { spyOn(comp, 'closeMetadataModal'); submissionServiceStub.createSubmissionFromExternalSource.and.returnValue(observableOf(submissionObjects)); spyOn(compAsAny.router, 'navigateByUrl'); - comp.import(); + scheduler.schedule(() => comp.import()); + scheduler.flush(); expect(compAsAny.modalService.open).toHaveBeenCalledWith(SubmissionImportExternalCollectionComponent, { size: 'lg' }); expect(comp.closeMetadataModal).toHaveBeenCalled(); diff --git a/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.html b/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.html index a63828568d..fe70299e4e 100644 --- a/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.html +++ b/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.html @@ -1,6 +1,9 @@ -
+
-
+
+
+ +
- +
diff --git a/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.spec.ts b/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.spec.ts index 285581560b..25f12c6e38 100644 --- a/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.spec.ts +++ b/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.spec.ts @@ -11,6 +11,8 @@ import { PaginatedList } from '../../../core/data/paginated-list'; import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils'; import { ExternalSource } from '../../../core/shared/external-source.model'; import { FindListOptions } from '../../../core/data/request.models'; +import { HostWindowService } from '../../../shared/host-window.service'; +import { HostWindowServiceStub } from '../../../shared/testing/host-window-service.stub'; describe('SubmissionImportExternalSearchbarComponent test suite', () => { let comp: SubmissionImportExternalSearchbarComponent; @@ -29,6 +31,7 @@ describe('SubmissionImportExternalSearchbarComponent test suite', () => { providers: [ { provide: ExternalSourceService, useClass: getMockExternalSourceService }, ChangeDetectorRef, + { provide: HostWindowService, useValue: new HostWindowServiceStub(800) }, SubmissionImportExternalSearchbarComponent ], schemas: [NO_ERRORS_SCHEMA] @@ -68,7 +71,7 @@ describe('SubmissionImportExternalSearchbarComponent test suite', () => { const pageInfo = new PageInfo(); paginatedList = new PaginatedList(pageInfo, [externalSourceOrcid, externalSourceCiencia, externalSourceMyStaffDb]); const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList); - compAsAny.externalService.getAllExternalSources.and.returnValue(observableOf(paginatedListRD)); + compAsAny.externalService.findAll.and.returnValue(observableOf(paginatedListRD)); sourceList = [ {id: 'orcid', name: 'orcid'}, {id: 'ciencia', name: 'ciencia'}, diff --git a/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.ts b/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.ts index efbcbad60c..bb156e1878 100644 --- a/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.ts +++ b/src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { of as observableOf } from 'rxjs'; +import { of as observableOf, Observable } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; import { ExternalSourceService } from '../../../core/data/external-source.service'; @@ -11,6 +11,7 @@ import { PageInfo } from '../../../core/shared/page-info.model'; import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils'; import { FindListOptions } from '../../../core/data/request.models'; import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators'; +import { HostWindowService } from '../../../shared/host-window.service'; /** * Interface for the selected external source element. @@ -57,6 +58,10 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit { * The external sources loading status. */ public sourceListLoading = false; + /** + * Emits true if were on a small screen + */ + public isXsOrSm$: Observable; /** * The external source data to use to perform the search. */ @@ -75,10 +80,12 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit { * Initialize the component variables. * @param {ExternalSourceService} externalService * @param {ChangeDetectorRef} cdr + * @param {HostWindowService} windowService */ constructor( private externalService: ExternalSourceService, private cdr: ChangeDetectorRef, + protected windowService: HostWindowService ) { } @@ -96,7 +103,7 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit { elementsPerPage: 5, currentPage: 0, }); - this.externalService.getAllExternalSources(this.findListOptions).pipe( + this.externalService.findAll(this.findListOptions).pipe( catchError(() => { const pageInfo = new PageInfo(); const paginatedList = new PaginatedList(pageInfo, []); @@ -118,6 +125,7 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit { this.pageInfo = externalSource.pageInfo; this.cdr.detectChanges(); }); + this.isXsOrSm$ = this.windowService.isXsOrSm(); } /** @@ -137,7 +145,7 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit { elementsPerPage: 5, currentPage: this.findListOptions.currentPage + 1, }); - this.externalService.getAllExternalSources(this.findListOptions).pipe( + this.externalService.findAll(this.findListOptions).pipe( catchError(() => { const pageInfo = new PageInfo(); const paginatedList = new PaginatedList(pageInfo, []); diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index cc21874672..75cf73339d 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1859,7 +1859,9 @@ "mydspace.new-submission": "New submission", - "mydspace.new-submission-external": "Import from external source", + "mydspace.new-submission-external": "Import metadata from external source", + + "mydspace.new-submission-external-short": "Import metadata", "mydspace.results.head": "Your submissions", @@ -2562,7 +2564,7 @@ "submission.import-external.title": "Import metadata from an external source", - "submission.import-external.page.hint": "Search items using external sources.", + "submission.import-external.page.hint": "No search performed yet. Search items using external sources.", "submission.import-external.back-to-my-dspace": "Back to MyDSpace",