CI test fix, buttons and searchbar style fix and service methods removed

This commit is contained in:
Matteo Perelli
2020-07-06 09:12:18 +02:00
parent e36cb83622
commit d6a5d9d1dd
11 changed files with 55 additions and 63 deletions

View File

@@ -7,11 +7,13 @@
</div> </div>
<div class="add"> <div class="add">
<button class="btn btn-lg btn-primary mt-1 ml-2" (click)="openDialog()" role="button"> <button class="btn btn-lg btn-primary mt-1 ml-2" (click)="openDialog()" role="button" title="{{'mydspace.new-submission' | translate}}">
<i class="fa fa-plus-circle" aria-hidden="true"></i> {{'mydspace.new-submission' | translate}} <i class="fa fa-plus-circle" aria-hidden="true"></i> <span *ngIf="!(isXsOrSm$ | async)">{{'mydspace.new-submission' | translate}}</span>
</button> </button>
<a class="btn btn-lg btn-primary mt-1 ml-2" [routerLink]="['/import-external']" role="button"> </div>
<i class="fa fa-file-import" aria-hidden="true"></i> {{'mydspace.new-submission-external' | translate}} <div class="add">
<a class="btn btn-lg btn-primary mt-1 ml-2" [routerLink]="['/import-external']" role="button" title="{{'mydspace.new-submission-external' | translate}}">
<i class="fa fa-file-import" aria-hidden="true"></i> <span *ngIf="!(isXsOrSm$ | async)">{{'mydspace.new-submission-external-short' | translate}}</span>
</a> </a>
</div> </div>

View File

@@ -23,6 +23,8 @@ import { getMockScrollToService } from '../../shared/mocks/scroll-to-service.moc
import { UploaderService } from '../../shared/uploader/uploader.service'; import { UploaderService } from '../../shared/uploader/uploader.service';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; 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', () => { describe('MyDSpaceNewSubmissionComponent test', () => {
@@ -63,7 +65,8 @@ describe('MyDSpaceNewSubmissionComponent test', () => {
}, },
ChangeDetectorRef, ChangeDetectorRef,
MyDSpaceNewSubmissionComponent, MyDSpaceNewSubmissionComponent,
UploaderService UploaderService,
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();

View File

@@ -1,6 +1,6 @@
import { ChangeDetectorRef, Component, EventEmitter, OnDestroy, OnInit, Output } from '@angular/core'; 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 { first } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@@ -18,6 +18,7 @@ import { SearchResult } from '../../shared/search/search-result.model';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; 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 { 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 * This component represents the whole mydspace page header
@@ -38,6 +39,11 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit {
*/ */
public uploadFilesOptions: UploaderOptions = new UploaderOptions(); public uploadFilesOptions: UploaderOptions = new UploaderOptions();
/**
* Emits true if were on a small screen
*/
public isXsOrSm$: Observable<boolean>;
/** /**
* Subscription to unsubscribe from * Subscription to unsubscribe from
*/ */
@@ -52,6 +58,9 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit {
* @param {NotificationsService} notificationsService * @param {NotificationsService} notificationsService
* @param {Store<SubmissionState>} store * @param {Store<SubmissionState>} store
* @param {TranslateService} translate * @param {TranslateService} translate
* @param {Router} router
* @param {NgbModal} modalService
* @param {HostWindowService} windowService
*/ */
constructor(private authService: AuthService, constructor(private authService: AuthService,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
@@ -60,7 +69,8 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit {
private store: Store<SubmissionState>, private store: Store<SubmissionState>,
private translate: TranslateService, private translate: TranslateService,
private router: Router, 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.changeDetectorRef.detectChanges();
} }
); );
this.isXsOrSm$ = this.windowService.isXsOrSm();
} }
/** /**

View File

@@ -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);
});
});
}); });

View File

@@ -60,34 +60,6 @@ export class ExternalSourceService extends DataService<ExternalSource> {
); );
} }
/**
* 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<RemoteData<ExternalSource>>
* The list of the external sources.
*/
getExternalSource(id: string, ...linksToFollow: Array<FollowLinkConfig<ExternalSource>>): Observable<RemoteData<ExternalSource>> {
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<RemoteData<PaginatedList<ExternalSource>>>
* The list of the external sources.
*/
getAllExternalSources(options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<ExternalSource>>): Observable<RemoteData<PaginatedList<ExternalSource>>> {
return this.findAll(options, ...linksToFollow);
}
/** /**
* Get the entries for an external source * Get the entries for an external source
* @param externalSourceId The id of the external source to fetch entries for * @param externalSourceId The id of the external source to fetch entries for

View File

@@ -53,7 +53,7 @@ export const externalSourceMyStaffDb: ExternalSource = {
export function getMockExternalSourceService(): export function getMockExternalSourceService():
ExternalSourceService { ExternalSourceService {
return jasmine.createSpyObj('ExternalSourceService', { return jasmine.createSpyObj('ExternalSourceService', {
getAllExternalSources: jasmine.createSpy('getAllExternalSources'), findAll: jasmine.createSpy('findAll'),
getExternalSourceEntries: jasmine.createSpy('getExternalSourceEntries'), getExternalSourceEntries: jasmine.createSpy('getExternalSourceEntries'),
}); });
} }

View File

@@ -3,7 +3,9 @@ import { async, TestBed, ComponentFixture, inject } from '@angular/core/testing'
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { TestScheduler } from 'rxjs/testing';
import { of as observableOf, of } from 'rxjs/internal/observable/of'; import { of as observableOf, of } from 'rxjs/internal/observable/of';
import { getTestScheduler } from 'jasmine-marbles';
import { SubmissionImportExternalPreviewComponent } from './submission-import-external-preview.component'; import { SubmissionImportExternalPreviewComponent } from './submission-import-external-preview.component';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { RouterStub } from '../../../shared/testing/router.stub'; import { RouterStub } from '../../../shared/testing/router.stub';
@@ -21,6 +23,7 @@ describe('SubmissionImportExternalPreviewComponent test suite', () => {
let compAsAny: any; let compAsAny: any;
let fixture: ComponentFixture<SubmissionImportExternalPreviewComponent>; let fixture: ComponentFixture<SubmissionImportExternalPreviewComponent>;
let submissionServiceStub: SubmissionServiceStub; let submissionServiceStub: SubmissionServiceStub;
let scheduler: TestScheduler;
const ngbActiveModal = jasmine.createSpyObj('modal', ['close', 'dismiss']); const ngbActiveModal = jasmine.createSpyObj('modal', ['close', 'dismiss']);
const ngbModal = jasmine.createSpyObj('modal', ['open']); const ngbModal = jasmine.createSpyObj('modal', ['open']);
const externalEntry = Object.assign(new ExternalSourceEntry(), { const externalEntry = Object.assign(new ExternalSourceEntry(), {
@@ -38,6 +41,7 @@ describe('SubmissionImportExternalPreviewComponent test suite', () => {
}); });
beforeEach(async (() => { beforeEach(async (() => {
scheduler = getTestScheduler();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
TranslateModule.forRoot() TranslateModule.forRoot()
@@ -134,7 +138,8 @@ describe('SubmissionImportExternalPreviewComponent test suite', () => {
spyOn(comp, 'closeMetadataModal'); spyOn(comp, 'closeMetadataModal');
submissionServiceStub.createSubmissionFromExternalSource.and.returnValue(observableOf(submissionObjects)); submissionServiceStub.createSubmissionFromExternalSource.and.returnValue(observableOf(submissionObjects));
spyOn(compAsAny.router, 'navigateByUrl'); spyOn(compAsAny.router, 'navigateByUrl');
comp.import(); scheduler.schedule(() => comp.import());
scheduler.flush();
expect(compAsAny.modalService.open).toHaveBeenCalledWith(SubmissionImportExternalCollectionComponent, { size: 'lg' }); expect(compAsAny.modalService.open).toHaveBeenCalledWith(SubmissionImportExternalCollectionComponent, { size: 'lg' });
expect(comp.closeMetadataModal).toHaveBeenCalled(); expect(comp.closeMetadataModal).toHaveBeenCalled();

View File

@@ -1,6 +1,9 @@
<div class="input-group mb-5"> <div *ngIf="(isXsOrSm$ | async)" class="input-group mb-2">
<input type="text" class="form-control" (keyup.enter)="(searchString === '')?null:search()" [(ngModel)]="searchString" placeholder="{{'submission.import-external.search.placeholder' |translate}}" aria-label="" aria-describedby=""> <input type="text" class="form-control" (keyup.enter)="(searchString === '')?null:search()" [(ngModel)]="searchString" placeholder="{{'submission.import-external.search.placeholder' |translate}}" aria-label="" aria-describedby="">
<div class="input-group-append" ngbDropdown role="group" aria-label=""> </div>
<div class="input-group mb-5">
<input *ngIf="!(isXsOrSm$ | async)" type="text" class="form-control" (keyup.enter)="(searchString === '')?null:search()" [(ngModel)]="searchString" placeholder="{{'submission.import-external.search.placeholder' |translate}}" aria-label="" aria-describedby="">
<div [ngClass]="{'input-group-append': !(isXsOrSm$ | async)}" ngbDropdown role="group" aria-label="">
<button class="btn btn-outline-secondary w-fx" title="{{'submission.import-external.search.source.hint' |translate}}" ngbDropdownToggle>{{'submission.import-external.source.' + selectedElement.name | translate}}</button> <button class="btn btn-outline-secondary w-fx" title="{{'submission.import-external.search.source.hint' |translate}}" ngbDropdownToggle>{{'submission.import-external.source.' + selectedElement.name | translate}}</button>
<div ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100" <div ngbDropdownMenu class="dropdown-menu scrollable-dropdown-menu w-100"
aria-haspopup="true" aria-haspopup="true"
@@ -17,6 +20,6 @@
<div ngbDropdownItem class="scrollable-dropdown-loading text-center" *ngIf="sourceListLoading"><p>{{'submission.import-external.source.loading' | translate}}</p></div> <div ngbDropdownItem class="scrollable-dropdown-loading text-center" *ngIf="sourceListLoading"><p>{{'submission.import-external.source.loading' | translate}}</p></div>
</div> </div>
</div> </div>
<button type="button" class="btn btn-outline-secondary" [title]="(searchString === '')?('submission.import-external.search.button.hint' | translate):('submission.import-external.search.button' | translate)" [disabled]="searchString === ''" (click)="search()">{{'submission.import-external.search.button' | translate}}</button> <button type="button" class="btn btn-primary" [title]="(searchString === '')?('submission.import-external.search.button.hint' | translate):('submission.import-external.search.button' | translate)" [disabled]="searchString === ''" (click)="search()">{{'submission.import-external.search.button' | translate}}</button>
</div> </div>
</div> </div>

View File

@@ -11,6 +11,8 @@ import { PaginatedList } from '../../../core/data/paginated-list';
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils'; import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
import { ExternalSource } from '../../../core/shared/external-source.model'; import { ExternalSource } from '../../../core/shared/external-source.model';
import { FindListOptions } from '../../../core/data/request.models'; 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', () => { describe('SubmissionImportExternalSearchbarComponent test suite', () => {
let comp: SubmissionImportExternalSearchbarComponent; let comp: SubmissionImportExternalSearchbarComponent;
@@ -29,6 +31,7 @@ describe('SubmissionImportExternalSearchbarComponent test suite', () => {
providers: [ providers: [
{ provide: ExternalSourceService, useClass: getMockExternalSourceService }, { provide: ExternalSourceService, useClass: getMockExternalSourceService },
ChangeDetectorRef, ChangeDetectorRef,
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
SubmissionImportExternalSearchbarComponent SubmissionImportExternalSearchbarComponent
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -68,7 +71,7 @@ describe('SubmissionImportExternalSearchbarComponent test suite', () => {
const pageInfo = new PageInfo(); const pageInfo = new PageInfo();
paginatedList = new PaginatedList(pageInfo, [externalSourceOrcid, externalSourceCiencia, externalSourceMyStaffDb]); paginatedList = new PaginatedList(pageInfo, [externalSourceOrcid, externalSourceCiencia, externalSourceMyStaffDb]);
const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList); const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList);
compAsAny.externalService.getAllExternalSources.and.returnValue(observableOf(paginatedListRD)); compAsAny.externalService.findAll.and.returnValue(observableOf(paginatedListRD));
sourceList = [ sourceList = [
{id: 'orcid', name: 'orcid'}, {id: 'orcid', name: 'orcid'},
{id: 'ciencia', name: 'ciencia'}, {id: 'ciencia', name: 'ciencia'},

View File

@@ -1,6 +1,6 @@
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; 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 { catchError, tap } from 'rxjs/operators';
import { ExternalSourceService } from '../../../core/data/external-source.service'; 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 { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
import { FindListOptions } from '../../../core/data/request.models'; import { FindListOptions } from '../../../core/data/request.models';
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators'; import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
import { HostWindowService } from '../../../shared/host-window.service';
/** /**
* Interface for the selected external source element. * Interface for the selected external source element.
@@ -57,6 +58,10 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit {
* The external sources loading status. * The external sources loading status.
*/ */
public sourceListLoading = false; public sourceListLoading = false;
/**
* Emits true if were on a small screen
*/
public isXsOrSm$: Observable<boolean>;
/** /**
* The external source data to use to perform the search. * The external source data to use to perform the search.
*/ */
@@ -75,10 +80,12 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit {
* Initialize the component variables. * Initialize the component variables.
* @param {ExternalSourceService} externalService * @param {ExternalSourceService} externalService
* @param {ChangeDetectorRef} cdr * @param {ChangeDetectorRef} cdr
* @param {HostWindowService} windowService
*/ */
constructor( constructor(
private externalService: ExternalSourceService, private externalService: ExternalSourceService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
protected windowService: HostWindowService
) { ) {
} }
@@ -96,7 +103,7 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit {
elementsPerPage: 5, elementsPerPage: 5,
currentPage: 0, currentPage: 0,
}); });
this.externalService.getAllExternalSources(this.findListOptions).pipe( this.externalService.findAll(this.findListOptions).pipe(
catchError(() => { catchError(() => {
const pageInfo = new PageInfo(); const pageInfo = new PageInfo();
const paginatedList = new PaginatedList(pageInfo, []); const paginatedList = new PaginatedList(pageInfo, []);
@@ -118,6 +125,7 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit {
this.pageInfo = externalSource.pageInfo; this.pageInfo = externalSource.pageInfo;
this.cdr.detectChanges(); this.cdr.detectChanges();
}); });
this.isXsOrSm$ = this.windowService.isXsOrSm();
} }
/** /**
@@ -137,7 +145,7 @@ export class SubmissionImportExternalSearchbarComponent implements OnInit {
elementsPerPage: 5, elementsPerPage: 5,
currentPage: this.findListOptions.currentPage + 1, currentPage: this.findListOptions.currentPage + 1,
}); });
this.externalService.getAllExternalSources(this.findListOptions).pipe( this.externalService.findAll(this.findListOptions).pipe(
catchError(() => { catchError(() => {
const pageInfo = new PageInfo(); const pageInfo = new PageInfo();
const paginatedList = new PaginatedList(pageInfo, []); const paginatedList = new PaginatedList(pageInfo, []);

View File

@@ -1859,7 +1859,9 @@
"mydspace.new-submission": "New submission", "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", "mydspace.results.head": "Your submissions",
@@ -2562,7 +2564,7 @@
"submission.import-external.title": "Import metadata from an external source", "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", "submission.import-external.back-to-my-dspace": "Back to MyDSpace",