mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-19 07:53:02 +00:00
[CST-7757] fix tests
This commit is contained in:
@@ -2,11 +2,11 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
|
||||
|
||||
import { BehaviorSubject, combineLatest, from, shareReplay } from 'rxjs';
|
||||
import { map, mergeMap, take, tap } from 'rxjs/operators';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
|
||||
import { Subscription } from '../models/subscription.model';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
@@ -17,7 +17,6 @@ import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
||||
import { AuthService } from '../../../core/auth/auth.service';
|
||||
import { isNotEmpty } from '../../empty.util';
|
||||
import { findIndex } from 'lodash';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-subscription-modal',
|
||||
|
@@ -9,9 +9,6 @@ export class NotificationsServiceStub {
|
||||
remove = jasmine.createSpy('remove');
|
||||
removeAll = jasmine.createSpy('removeAll');
|
||||
|
||||
notificationWithAnchor() {
|
||||
}
|
||||
|
||||
private getDefaultOptions(): NotificationOptions {
|
||||
return new NotificationOptions();
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -7,14 +7,13 @@
|
||||
<ds-themed-loading *ngIf="loading$ | async"></ds-themed-loading>
|
||||
<ng-container *ngVar="(subscriptions$ | async) as subscriptions">
|
||||
|
||||
<ds-pagination
|
||||
*ngIf="subscriptions?.pageInfo?.totalElements > 0 && !(loading$ | async)"
|
||||
<ds-pagination *ngIf="subscriptions?.pageInfo?.totalElements > 0 && !(loading$ | async)"
|
||||
[paginationOptions]="config"
|
||||
[collectionSize]="subscriptions?.pageInfo?.totalPages"
|
||||
[hideGear]="true"
|
||||
[hidePagerWhenSinglePage]="true">
|
||||
<div class="table-responsive">
|
||||
<table id="formats" class="table table-striped table-hover">
|
||||
<table id="formats" class="table table-striped table-hover" data-test="subscription-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{{'subscriptions.table.dso' | translate}}</th>
|
||||
@@ -35,7 +34,7 @@
|
||||
</div>
|
||||
</ds-pagination>
|
||||
|
||||
<ds-alert *ngIf="subscriptions?.pageInfo?.totalElements == 0 && !(loading$ | async)" [type]="'alert-info'">
|
||||
<ds-alert *ngIf="subscriptions?.pageInfo?.totalElements == 0 && !(loading$ | async)" [type]="'alert-info'" data-test="empty-alert">
|
||||
{{ 'subscriptions.table.empty.message' | translate }}
|
||||
</ds-alert>
|
||||
|
||||
|
@@ -1,41 +1,31 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
|
||||
|
||||
// Import modules
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { BrowserModule, By } from '@angular/platform-browser';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
// Import components
|
||||
import { SubscriptionsPageComponent } from './subscriptions-page.component';
|
||||
|
||||
// Import services
|
||||
import { PaginationService } from '../core/pagination/pagination.service';
|
||||
import { SubscriptionService } from '../shared/subscriptions/subscription.service';
|
||||
import { PaginationServiceStub } from '../shared/testing/pagination-service.stub';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
|
||||
// Import utils
|
||||
import { HostWindowService } from '../shared/host-window.service';
|
||||
import { HostWindowServiceStub } from '../shared/testing/host-window-service.stub';
|
||||
|
||||
|
||||
// Import mocks
|
||||
import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock';
|
||||
import { findAllSubscriptionRes } from '../shared/testing/subscriptions-data.mock';
|
||||
import { MockActivatedRoute } from '../shared/mocks/active-router.mock';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { EPersonMock } from '../shared/testing/eperson.mock';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { VarDirective } from '../shared/utils/var.directive';
|
||||
import {
|
||||
SubscriptionViewComponent
|
||||
} from '../shared/subscriptions/components/subscription-view/subscription-view.component';
|
||||
|
||||
mockSubscriptionEperson,
|
||||
subscriptionMock,
|
||||
subscriptionMock2
|
||||
} from '../shared/testing/subscriptions-data.mock';
|
||||
import { MockActivatedRoute } from '../shared/mocks/active-router.mock';
|
||||
import { VarDirective } from '../shared/utils/var.directive';
|
||||
import { SubscriptionViewComponent } from '../shared/subscriptions/subscription-view/subscription-view.component';
|
||||
import { PageInfo } from '../core/shared/page-info.model';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
|
||||
import { buildPaginatedList } from '../core/data/paginated-list.model';
|
||||
|
||||
describe('SubscriptionsPageComponent', () => {
|
||||
let component: SubscriptionsPageComponent;
|
||||
@@ -43,15 +33,26 @@ describe('SubscriptionsPageComponent', () => {
|
||||
let de: DebugElement;
|
||||
|
||||
const authServiceStub = jasmine.createSpyObj('authorizationService', {
|
||||
getAuthenticatedUserFromStore: observableOf(EPersonMock)
|
||||
getAuthenticatedUserFromStore: observableOf(mockSubscriptionEperson)
|
||||
});
|
||||
|
||||
const subscriptionServiceStub = jasmine.createSpyObj('SubscriptionService', {
|
||||
findByEPerson: observableOf(findAllSubscriptionRes)
|
||||
findByEPerson: jasmine.createSpy('findByEPerson')
|
||||
});
|
||||
|
||||
const paginationService = new PaginationServiceStub();
|
||||
|
||||
beforeEach(waitForAsync( () => {
|
||||
const mockSubscriptionList = [subscriptionMock, subscriptionMock2];
|
||||
|
||||
const emptyPageInfo = Object.assign(new PageInfo(), {
|
||||
totalElements: 0
|
||||
});
|
||||
|
||||
const pageInfo = Object.assign(new PageInfo(), {
|
||||
totalElements: 2
|
||||
});
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
@@ -65,10 +66,9 @@ describe('SubscriptionsPageComponent', () => {
|
||||
}),
|
||||
NoopAnimationsModule
|
||||
],
|
||||
declarations: [ SubscriptionsPageComponent, SubscriptionViewComponent, VarDirective ],
|
||||
providers:[
|
||||
declarations: [SubscriptionsPageComponent, SubscriptionViewComponent, VarDirective],
|
||||
providers: [
|
||||
{ provide: SubscriptionService, useValue: subscriptionServiceStub },
|
||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
||||
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
|
||||
{ provide: AuthService, useValue: authServiceStub },
|
||||
{ provide: PaginationService, useValue: paginationService }
|
||||
@@ -82,46 +82,46 @@ describe('SubscriptionsPageComponent', () => {
|
||||
fixture = TestBed.createComponent(SubscriptionsPageComponent);
|
||||
component = fixture.componentInstance;
|
||||
de = fixture.debugElement;
|
||||
});
|
||||
|
||||
describe('when there are subscriptions', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
subscriptionServiceStub.findByEPerson.and.returnValue(createSuccessfulRemoteDataObject$(buildPaginatedList(pageInfo, mockSubscriptionList)));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
fixture.detectChanges();
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('when table', () => {
|
||||
it('should show table', () => {
|
||||
expect(de.query(By.css('[data-test="subscription-table"]'))).toBeTruthy();
|
||||
expect(de.query(By.css('[data-test="empty-alert"]'))).toBeNull();
|
||||
});
|
||||
|
||||
it('should show table', async() => {
|
||||
await fixture.whenStable();
|
||||
it('should show a row for each results entry',() => {
|
||||
expect(de.query(By.css('[data-test="subscription-table"]'))).toBeTruthy();
|
||||
expect(de.query(By.css('[data-test="empty-alert"]'))).toBeNull();
|
||||
expect(de.queryAll(By.css('tbody > tr')).length).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there are no subscriptions', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
subscriptionServiceStub.findByEPerson.and.returnValue(createSuccessfulRemoteDataObject$(buildPaginatedList(emptyPageInfo, [])));
|
||||
fixture.detectChanges();
|
||||
const table = de.query(By.css('table'));
|
||||
expect(table).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should show all the results', () => {
|
||||
expect(de.queryAll(By.css('tbody > tr')).length).toEqual(10);
|
||||
it('should not show table', () => {
|
||||
expect(de.query(By.css('[data-test="subscription-table"]'))).toBeNull();
|
||||
expect(de.query(By.css('[data-test="empty-alert"]'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have dso object info', () => {
|
||||
expect(de.query(By.css('.dso-info > span'))).toBeTruthy();
|
||||
expect(de.query(By.css('.dso-info > p > a'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have subscription type info', () => {
|
||||
expect(de.query(By.css('.subscription-type'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have subscription paramenter info', () => {
|
||||
expect(de.query(By.css('.subscription-parmenters > span'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have subscription action info', () => {
|
||||
expect(de.query(By.css('.btn-outline-primary'))).toBeTruthy();
|
||||
expect(de.query(By.css('.btn-outline-danger'))).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
@@ -11,7 +11,8 @@ import { PaginationService } from '../core/pagination/pagination.service';
|
||||
import { PageInfo } from '../core/shared/page-info.model';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
import { EPerson } from '../core/eperson/models/eperson.model';
|
||||
import { getFirstSucceededRemoteDataPayload } from '../core/shared/operators';
|
||||
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-subscriptions-page',
|
||||
@@ -43,7 +44,7 @@ export class SubscriptionsPageComponent implements OnInit {
|
||||
ePersonId$: Observable<string>;
|
||||
|
||||
/**
|
||||
* EPerson id of the logged in user
|
||||
* EPerson id of the logged-in user
|
||||
*/
|
||||
// ePersonId: string;
|
||||
|
||||
@@ -61,35 +62,26 @@ export class SubscriptionsPageComponent implements OnInit {
|
||||
this.ePersonId$ = this.authService.getAuthenticatedUserFromStore().pipe(
|
||||
take(1),
|
||||
map((ePerson: EPerson) => ePerson.id),
|
||||
shareReplay(),
|
||||
/*tap((ePersonId: string) => { // TODO unused
|
||||
this.ePersonId = ePersonId;
|
||||
}),*/
|
||||
shareReplay()
|
||||
);
|
||||
this.retrieveSubscriptions();
|
||||
}
|
||||
|
||||
private retrieveSubscriptions() {
|
||||
this.paginationService.getCurrentPagination(this.config.id, this.config).pipe(
|
||||
tap(console.log),
|
||||
combineLatestWith(this.ePersonId$),
|
||||
tap(() => {this.loading$.next(true);}),
|
||||
tap(() => this.loading$.next(true)),
|
||||
switchMap(([currentPagination, ePersonId]) => this.subscriptionService.findByEPerson(ePersonId,{
|
||||
currentPage: currentPagination.currentPage,
|
||||
elementsPerPage: currentPagination.pageSize
|
||||
})),
|
||||
getFirstSucceededRemoteDataPayload(),
|
||||
tap((x) => console.log('find', x)),
|
||||
// getFirstSucceededRemoteDataPayload(),
|
||||
).subscribe({
|
||||
next: (res: any) => {
|
||||
console.log('next',res);
|
||||
this.subscriptions$.next(res);
|
||||
this.loading$.next(false);
|
||||
},
|
||||
error: () => {
|
||||
this.loading$.next(false);
|
||||
getFirstCompletedRemoteData()
|
||||
|
||||
).subscribe((res: RemoteData<PaginatedList<Subscription>>) => {
|
||||
if (res.hasSucceeded) {
|
||||
this.subscriptions$.next(res.payload);
|
||||
}
|
||||
this.loading$.next(false);
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
Reference in New Issue
Block a user