mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #916 from 4Science/CSTPER-66
Communities and collections not shown right after creation
This commit is contained in:
@@ -12,6 +12,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
|||||||
import { CreateCollectionPageComponent } from './create-collection-page.component';
|
import { CreateCollectionPageComponent } from './create-collection-page.component';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
describe('CreateCollectionPageComponent', () => {
|
describe('CreateCollectionPageComponent', () => {
|
||||||
let comp: CreateCollectionPageComponent;
|
let comp: CreateCollectionPageComponent;
|
||||||
@@ -29,7 +30,8 @@ describe('CreateCollectionPageComponent', () => {
|
|||||||
},
|
},
|
||||||
{ provide: RouteService, useValue: { getQueryParameterValue: () => observableOf('1234') } },
|
{ provide: RouteService, useValue: { getQueryParameterValue: () => observableOf('1234') } },
|
||||||
{ provide: Router, useValue: {} },
|
{ provide: Router, useValue: {} },
|
||||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
|
{ provide: RequestService, useValue: {}}
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -7,6 +7,7 @@ import { Collection } from '../../core/shared/collection.model';
|
|||||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can create a new Collection
|
* Component that represents the page where a user can create a new Collection
|
||||||
@@ -26,8 +27,9 @@ export class CreateCollectionPageComponent extends CreateComColPageComponent<Col
|
|||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
protected translate: TranslateService
|
protected translate: TranslateService,
|
||||||
|
protected requestService: RequestService
|
||||||
) {
|
) {
|
||||||
super(collectionDataService, communityDataService, routeService, router, notificationsService, translate);
|
super(collectionDataService, communityDataService, routeService, router, notificationsService, translate, requestService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import { of as observableOf } from 'rxjs';
|
|||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { DeleteCollectionPageComponent } from './delete-collection-page.component';
|
import { DeleteCollectionPageComponent } from './delete-collection-page.component';
|
||||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
describe('DeleteCollectionPageComponent', () => {
|
describe('DeleteCollectionPageComponent', () => {
|
||||||
let comp: DeleteCollectionPageComponent;
|
let comp: DeleteCollectionPageComponent;
|
||||||
@@ -22,6 +23,7 @@ describe('DeleteCollectionPageComponent', () => {
|
|||||||
{ provide: CollectionDataService, useValue: {} },
|
{ provide: CollectionDataService, useValue: {} },
|
||||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
||||||
{ provide: NotificationsService, useValue: {} },
|
{ provide: NotificationsService, useValue: {} },
|
||||||
|
{ provide: RequestService, useValue: {} }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -5,6 +5,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
|
|||||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||||
import { Collection } from '../../core/shared/collection.model';
|
import { Collection } from '../../core/shared/collection.model';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can delete an existing Collection
|
* Component that represents the page where a user can delete an existing Collection
|
||||||
@@ -22,8 +23,9 @@ export class DeleteCollectionPageComponent extends DeleteComColPageComponent<Col
|
|||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notifications: NotificationsService,
|
protected notifications: NotificationsService,
|
||||||
protected translate: TranslateService
|
protected translate: TranslateService,
|
||||||
|
protected requestService: RequestService
|
||||||
) {
|
) {
|
||||||
super(dsoDataService, router, route, notifications, translate);
|
super(dsoDataService, router, route, notifications, translate, requestService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
|||||||
import { CreateCommunityPageComponent } from './create-community-page.component';
|
import { CreateCommunityPageComponent } from './create-community-page.component';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
describe('CreateCommunityPageComponent', () => {
|
describe('CreateCommunityPageComponent', () => {
|
||||||
let comp: CreateCommunityPageComponent;
|
let comp: CreateCommunityPageComponent;
|
||||||
@@ -25,7 +26,8 @@ describe('CreateCommunityPageComponent', () => {
|
|||||||
{ provide: CommunityDataService, useValue: { findById: () => observableOf({}) } },
|
{ provide: CommunityDataService, useValue: { findById: () => observableOf({}) } },
|
||||||
{ provide: RouteService, useValue: { getQueryParameterValue: () => observableOf('1234') } },
|
{ provide: RouteService, useValue: { getQueryParameterValue: () => observableOf('1234') } },
|
||||||
{ provide: Router, useValue: {} },
|
{ provide: Router, useValue: {} },
|
||||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
|
{ provide: RequestService, useValue: {} }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -6,6 +6,7 @@ import { Router } from '@angular/router';
|
|||||||
import { CreateComColPageComponent } from '../../shared/comcol-forms/create-comcol-page/create-comcol-page.component';
|
import { CreateComColPageComponent } from '../../shared/comcol-forms/create-comcol-page/create-comcol-page.component';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can create a new Community
|
* Component that represents the page where a user can create a new Community
|
||||||
@@ -24,8 +25,9 @@ export class CreateCommunityPageComponent extends CreateComColPageComponent<Comm
|
|||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
protected translate: TranslateService
|
protected translate: TranslateService,
|
||||||
|
protected requestService: RequestService
|
||||||
) {
|
) {
|
||||||
super(communityDataService, communityDataService, routeService, router, notificationsService, translate);
|
super(communityDataService, communityDataService, routeService, router, notificationsService, translate, requestService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
|||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { SharedModule } from '../../shared/shared.module';
|
import { SharedModule } from '../../shared/shared.module';
|
||||||
import { DeleteCommunityPageComponent } from './delete-community-page.component';
|
import { DeleteCommunityPageComponent } from './delete-community-page.component';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
describe('DeleteCommunityPageComponent', () => {
|
describe('DeleteCommunityPageComponent', () => {
|
||||||
let comp: DeleteCommunityPageComponent;
|
let comp: DeleteCommunityPageComponent;
|
||||||
@@ -22,6 +23,7 @@ describe('DeleteCommunityPageComponent', () => {
|
|||||||
{ provide: CommunityDataService, useValue: {} },
|
{ provide: CommunityDataService, useValue: {} },
|
||||||
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
{ provide: ActivatedRoute, useValue: { data: observableOf({ dso: { payload: {} } }) } },
|
||||||
{ provide: NotificationsService, useValue: {} },
|
{ provide: NotificationsService, useValue: {} },
|
||||||
|
{ provide: RequestService, useValue: {}}
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -5,6 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { DeleteComColPageComponent } from '../../shared/comcol-forms/delete-comcol-page/delete-comcol-page.component';
|
import { DeleteComColPageComponent } from '../../shared/comcol-forms/delete-comcol-page/delete-comcol-page.component';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import {RequestService} from '../../core/data/request.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that represents the page where a user can delete an existing Community
|
* Component that represents the page where a user can delete an existing Community
|
||||||
@@ -22,8 +23,10 @@ export class DeleteCommunityPageComponent extends DeleteComColPageComponent<Comm
|
|||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notifications: NotificationsService,
|
protected notifications: NotificationsService,
|
||||||
protected translate: TranslateService
|
protected translate: TranslateService,
|
||||||
|
protected requestService: RequestService
|
||||||
) {
|
) {
|
||||||
super(dsoDataService, router, route, notifications, translate);
|
super(dsoDataService, router, route, notifications, translate, requestService);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
|||||||
import { FindByIDRequest, FindListOptions } from './request.models';
|
import { FindByIDRequest, FindListOptions } from './request.models';
|
||||||
import { RequestEntry } from './request.reducer';
|
import { RequestEntry } from './request.reducer';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
|
import {createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject$} from '../../shared/remote-data.utils';
|
||||||
|
|
||||||
const LINK_NAME = 'test';
|
const LINK_NAME = 'test';
|
||||||
|
|
||||||
@@ -51,7 +52,9 @@ describe('ComColDataService', () => {
|
|||||||
let objectCache: ObjectCacheService;
|
let objectCache: ObjectCacheService;
|
||||||
let halService: any = {};
|
let halService: any = {};
|
||||||
|
|
||||||
const rdbService = {} as RemoteDataBuildService;
|
const rdbService = {
|
||||||
|
buildSingle : () => null
|
||||||
|
} as any;
|
||||||
const store = {} as Store<CoreState>;
|
const store = {} as Store<CoreState>;
|
||||||
const notificationsService = {} as NotificationsService;
|
const notificationsService = {} as NotificationsService;
|
||||||
const http = {} as HttpClient;
|
const http = {} as HttpClient;
|
||||||
@@ -178,6 +181,90 @@ describe('ComColDataService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('cache refresh', () => {
|
||||||
|
let communityWithoutParentHref;
|
||||||
|
let data;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
scheduler = getTestScheduler();
|
||||||
|
halService = {
|
||||||
|
getEndpoint: (linkPath) => 'https://rest.api/core/' + linkPath
|
||||||
|
};
|
||||||
|
service = initTestService();
|
||||||
|
|
||||||
|
})
|
||||||
|
describe('cache refreshed top level community', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(rdbService, 'buildSingle').and.returnValue(createNoContentRemoteDataObject$());
|
||||||
|
data = {
|
||||||
|
dso: Object.assign(new Community(), {
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'top level community'
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
_links: {
|
||||||
|
parentCommunity: {
|
||||||
|
href: 'topLevel/parentCommunity'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
communityWithoutParentHref = {
|
||||||
|
dso: Object.assign(new Community(), {
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'top level community'
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
_links: {}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
it('top level community cache refreshed', () => {
|
||||||
|
scheduler.schedule(() => (service as any).refreshCache(data));
|
||||||
|
scheduler.flush();
|
||||||
|
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('https://rest.api/core/communities/search/top');
|
||||||
|
});
|
||||||
|
it('top level community without parent link, cache not refreshed', () => {
|
||||||
|
scheduler.schedule(() => (service as any).refreshCache(communityWithoutParentHref));
|
||||||
|
scheduler.flush();
|
||||||
|
expect(requestService.removeByHrefSubstring).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('cache refreshed child community', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const parentCommunity = Object.assign(new Community(), {
|
||||||
|
uuid: 'a20da287-e174-466a-9926-f66as300d399',
|
||||||
|
id: 'a20da287-e174-466a-9926-f66as300d399',
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'parent community'
|
||||||
|
}],
|
||||||
|
_links: {}
|
||||||
|
});
|
||||||
|
spyOn(rdbService, 'buildSingle').and.returnValue(createSuccessfulRemoteDataObject$(parentCommunity));
|
||||||
|
data = {
|
||||||
|
dso: Object.assign(new Community(), {
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'child community'
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
_links: {
|
||||||
|
parentCommunity: {
|
||||||
|
href: 'child/parentCommunity'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
it('child level community cache refreshed', () => {
|
||||||
|
scheduler.schedule(() => (service as any).refreshCache(data));
|
||||||
|
scheduler.flush();
|
||||||
|
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith('a20da287-e174-466a-9926-f66as300d399');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -21,12 +21,14 @@ import {
|
|||||||
configureRequest,
|
configureRequest,
|
||||||
getRemoteDataPayload,
|
getRemoteDataPayload,
|
||||||
getResponseFromEntry,
|
getResponseFromEntry,
|
||||||
|
getSucceededOrNoContentResponse,
|
||||||
getSucceededRemoteData
|
getSucceededRemoteData
|
||||||
} from '../shared/operators';
|
} from '../shared/operators';
|
||||||
import { CacheableObject } from '../cache/object-cache.reducer';
|
import { CacheableObject } from '../cache/object-cache.reducer';
|
||||||
import { RestResponse } from '../cache/response.models';
|
import { RestResponse } from '../cache/response.models';
|
||||||
import { Bitstream } from '../shared/bitstream.model';
|
import { Bitstream } from '../shared/bitstream.model';
|
||||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
|
import {Collection} from '../shared/collection.model';
|
||||||
|
|
||||||
export abstract class ComColDataService<T extends CacheableObject> extends DataService<T> {
|
export abstract class ComColDataService<T extends CacheableObject> extends DataService<T> {
|
||||||
protected abstract cds: CommunityDataService;
|
protected abstract cds: CommunityDataService;
|
||||||
@@ -119,4 +121,23 @@ export abstract class ComColDataService<T extends CacheableObject> extends DataS
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public refreshCache(dso: T) {
|
||||||
|
const parentCommunityUrl = this.parentCommunityUrlLookup(dso as any);
|
||||||
|
if (!hasValue(parentCommunityUrl)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.findByHref(parentCommunityUrl).pipe(
|
||||||
|
getSucceededOrNoContentResponse(),
|
||||||
|
take(1),
|
||||||
|
).subscribe((rd: RemoteData<any>) => {
|
||||||
|
const href = rd.hasSucceeded && !isEmpty(rd.payload.id) ? rd.payload.id : this.halService.getEndpoint('communities/search/top');
|
||||||
|
this.requestService.removeByHrefSubstring(href)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private parentCommunityUrlLookup(dso: Collection | Community) {
|
||||||
|
const parentCommunity = dso._links.parentCommunity;
|
||||||
|
return isNotEmpty(parentCommunity) ? parentCommunity.href : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,4 +55,8 @@ export class RemoteData<T> {
|
|||||||
return this.state === RemoteDataState.Success;
|
return this.state === RemoteDataState.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get hasNoContent(): boolean {
|
||||||
|
return this.statusCode === 204;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -75,6 +75,10 @@ export const getSucceededRemoteWithNotEmptyData = () =>
|
|||||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||||
source.pipe(find((rd: RemoteData<T>) => rd.hasSucceeded && isNotEmpty(rd.payload)));
|
source.pipe(find((rd: RemoteData<T>) => rd.hasSucceeded && isNotEmpty(rd.payload)));
|
||||||
|
|
||||||
|
export const getSucceededOrNoContentResponse = () =>
|
||||||
|
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||||
|
source.pipe(find((rd: RemoteData<T>) => rd.hasSucceeded || rd.hasNoContent));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the first successful remotely retrieved object
|
* Get the first successful remotely retrieved object
|
||||||
*
|
*
|
||||||
|
@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { CommunityDataService } from '../../../core/data/community-data.service';
|
import { CommunityDataService } from '../../../core/data/community-data.service';
|
||||||
import { RouteService } from '../../../core/services/route.service';
|
import { RouteService } from '../../../core/services/route.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import {TranslateModule, TranslateService} from '@ngx-translate/core';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { Community } from '../../../core/shared/community.model';
|
import { Community } from '../../../core/shared/community.model';
|
||||||
import { SharedModule } from '../../shared.module';
|
import { SharedModule } from '../../shared.module';
|
||||||
@@ -12,12 +12,14 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
|
|||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
import { CreateComColPageComponent } from './create-comcol-page.component';
|
import { CreateComColPageComponent } from './create-comcol-page.component';
|
||||||
import {
|
import {
|
||||||
createFailedRemoteDataObject$,
|
createFailedRemoteDataObject$, createNoContentRemoteDataObject$,
|
||||||
createSuccessfulRemoteDataObject$
|
createSuccessfulRemoteDataObject$
|
||||||
} from '../../remote-data.utils';
|
} from '../../remote-data.utils';
|
||||||
import { ComColDataService } from '../../../core/data/comcol-data.service';
|
import { ComColDataService } from '../../../core/data/comcol-data.service';
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
import { NotificationsServiceStub } from '../../testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../testing/notifications-service.stub';
|
||||||
|
import { RequestService } from '../../../core/data/request.service';
|
||||||
|
import {getTestScheduler} from 'jasmine-marbles';
|
||||||
|
|
||||||
describe('CreateComColPageComponent', () => {
|
describe('CreateComColPageComponent', () => {
|
||||||
let comp: CreateComColPageComponent<DSpaceObject>;
|
let comp: CreateComColPageComponent<DSpaceObject>;
|
||||||
@@ -29,9 +31,12 @@ describe('CreateComColPageComponent', () => {
|
|||||||
|
|
||||||
let community;
|
let community;
|
||||||
let newCommunity;
|
let newCommunity;
|
||||||
|
let parentCommunity;
|
||||||
let communityDataServiceStub;
|
let communityDataServiceStub;
|
||||||
let routeServiceStub;
|
let routeServiceStub;
|
||||||
let routerStub;
|
let routerStub;
|
||||||
|
let requestServiceStub;
|
||||||
|
let scheduler;
|
||||||
|
|
||||||
const logoEndpoint = 'rest/api/logo/endpoint';
|
const logoEndpoint = 'rest/api/logo/endpoint';
|
||||||
|
|
||||||
@@ -41,7 +46,18 @@ describe('CreateComColPageComponent', () => {
|
|||||||
metadata: [{
|
metadata: [{
|
||||||
key: 'dc.title',
|
key: 'dc.title',
|
||||||
value: 'test community'
|
value: 'test community'
|
||||||
}]
|
}],
|
||||||
|
_links: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
parentCommunity = Object.assign(new Community(), {
|
||||||
|
uuid: 'a20da287-e174-466a-9926-f66as300d399',
|
||||||
|
id: 'a20da287-e174-466a-9926-f66as300d399',
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'parent community'
|
||||||
|
}],
|
||||||
|
_links: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
newCommunity = Object.assign(new Community(), {
|
newCommunity = Object.assign(new Community(), {
|
||||||
@@ -49,7 +65,8 @@ describe('CreateComColPageComponent', () => {
|
|||||||
metadata: [{
|
metadata: [{
|
||||||
key: 'dc.title',
|
key: 'dc.title',
|
||||||
value: 'new community'
|
value: 'new community'
|
||||||
}]
|
}],
|
||||||
|
_links: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
communityDataServiceStub = {
|
communityDataServiceStub = {
|
||||||
@@ -61,7 +78,9 @@ describe('CreateComColPageComponent', () => {
|
|||||||
}]
|
}]
|
||||||
})),
|
})),
|
||||||
create: (com, uuid?) => createSuccessfulRemoteDataObject$(newCommunity),
|
create: (com, uuid?) => createSuccessfulRemoteDataObject$(newCommunity),
|
||||||
getLogoEndpoint: () => observableOf(logoEndpoint)
|
getLogoEndpoint: () => observableOf(logoEndpoint),
|
||||||
|
findByHref: () => null,
|
||||||
|
refreshCache: () => {return}
|
||||||
};
|
};
|
||||||
|
|
||||||
routeServiceStub = {
|
routeServiceStub = {
|
||||||
@@ -71,6 +90,10 @@ describe('CreateComColPageComponent', () => {
|
|||||||
navigate: (commands) => commands
|
navigate: (commands) => commands
|
||||||
};
|
};
|
||||||
|
|
||||||
|
requestServiceStub = jasmine.createSpyObj('RequestService', {
|
||||||
|
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring'),
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
@@ -82,7 +105,8 @@ describe('CreateComColPageComponent', () => {
|
|||||||
{ provide: CommunityDataService, useValue: communityDataServiceStub },
|
{ provide: CommunityDataService, useValue: communityDataServiceStub },
|
||||||
{ provide: RouteService, useValue: routeServiceStub },
|
{ provide: RouteService, useValue: routeServiceStub },
|
||||||
{ provide: Router, useValue: routerStub },
|
{ provide: Router, useValue: routerStub },
|
||||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
|
{ provide: RequestService, useValue: requestServiceStub}
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -97,6 +121,7 @@ describe('CreateComColPageComponent', () => {
|
|||||||
communityDataService = (comp as any).communityDataService;
|
communityDataService = (comp as any).communityDataService;
|
||||||
routeService = (comp as any).routeService;
|
routeService = (comp as any).routeService;
|
||||||
router = (comp as any).router;
|
router = (comp as any).router;
|
||||||
|
scheduler = getTestScheduler();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onSubmit', () => {
|
describe('onSubmit', () => {
|
||||||
@@ -111,6 +136,7 @@ describe('CreateComColPageComponent', () => {
|
|||||||
value: 'test'
|
value: 'test'
|
||||||
}]
|
}]
|
||||||
}),
|
}),
|
||||||
|
_links: {},
|
||||||
uploader: {
|
uploader: {
|
||||||
options: {
|
options: {
|
||||||
url: ''
|
url: ''
|
||||||
@@ -123,19 +149,23 @@ describe('CreateComColPageComponent', () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate when successful', () => {
|
it('should navigate and refresh cache when successful', () => {
|
||||||
spyOn(router, 'navigate');
|
spyOn(router, 'navigate');
|
||||||
comp.onSubmit(data);
|
spyOn((dsoDataService as any), 'refreshCache')
|
||||||
fixture.detectChanges();
|
scheduler.schedule(() => comp.onSubmit(data));
|
||||||
|
scheduler.flush();
|
||||||
expect(router.navigate).toHaveBeenCalled();
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
|
expect((dsoDataService as any).refreshCache).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not navigate on failure', () => {
|
it('should neither navigate nor refresh cache on failure', () => {
|
||||||
spyOn(router, 'navigate');
|
spyOn(router, 'navigate');
|
||||||
spyOn(dsoDataService, 'create').and.returnValue(createFailedRemoteDataObject$(newCommunity));
|
spyOn(dsoDataService, 'create').and.returnValue(createFailedRemoteDataObject$(newCommunity));
|
||||||
comp.onSubmit(data);
|
spyOn(dsoDataService, 'refreshCache')
|
||||||
fixture.detectChanges();
|
scheduler.schedule(() => comp.onSubmit(data));
|
||||||
|
scheduler.flush();
|
||||||
expect(router.navigate).not.toHaveBeenCalled();
|
expect(router.navigate).not.toHaveBeenCalled();
|
||||||
|
expect((dsoDataService as any).refreshCache).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -148,6 +178,7 @@ describe('CreateComColPageComponent', () => {
|
|||||||
value: 'test'
|
value: 'test'
|
||||||
}]
|
}]
|
||||||
}),
|
}),
|
||||||
|
_links: {},
|
||||||
uploader: {
|
uploader: {
|
||||||
options: {
|
options: {
|
||||||
url: ''
|
url: ''
|
||||||
@@ -164,21 +195,21 @@ describe('CreateComColPageComponent', () => {
|
|||||||
|
|
||||||
it('should not navigate', () => {
|
it('should not navigate', () => {
|
||||||
spyOn(router, 'navigate');
|
spyOn(router, 'navigate');
|
||||||
comp.onSubmit(data);
|
scheduler.schedule(() => comp.onSubmit(data));
|
||||||
fixture.detectChanges();
|
scheduler.flush();
|
||||||
expect(router.navigate).not.toHaveBeenCalled();
|
expect(router.navigate).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set the uploader\'s url to the logo\'s endpoint', () => {
|
it('should set the uploader\'s url to the logo\'s endpoint', () => {
|
||||||
comp.onSubmit(data);
|
scheduler.schedule(() => comp.onSubmit(data));
|
||||||
fixture.detectChanges();
|
scheduler.flush();
|
||||||
expect(data.uploader.options.url).toEqual(logoEndpoint);
|
expect(data.uploader.options.url).toEqual(logoEndpoint);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the uploader\'s uploadAll', () => {
|
it('should call the uploader\'s uploadAll', () => {
|
||||||
spyOn(data.uploader, 'uploadAll');
|
spyOn(data.uploader, 'uploadAll');
|
||||||
comp.onSubmit(data);
|
scheduler.schedule(() => comp.onSubmit(data));
|
||||||
fixture.detectChanges();
|
scheduler.flush();
|
||||||
expect(data.uploader.uploadAll).toHaveBeenCalled();
|
expect(data.uploader.uploadAll).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -2,18 +2,21 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { take } from 'rxjs/operators';
|
import {flatMap, take} from 'rxjs/operators';
|
||||||
import { ComColDataService } from '../../../core/data/comcol-data.service';
|
import { ComColDataService } from '../../../core/data/comcol-data.service';
|
||||||
import { CommunityDataService } from '../../../core/data/community-data.service';
|
import { CommunityDataService } from '../../../core/data/community-data.service';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { RouteService } from '../../../core/services/route.service';
|
import { RouteService } from '../../../core/services/route.service';
|
||||||
import { Community } from '../../../core/shared/community.model';
|
import { Community } from '../../../core/shared/community.model';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||||
import { getSucceededRemoteData } from '../../../core/shared/operators';
|
import {
|
||||||
|
getFirstSucceededRemoteDataPayload,
|
||||||
|
} from '../../../core/shared/operators';
|
||||||
import { ResourceType } from '../../../core/shared/resource-type';
|
import { ResourceType } from '../../../core/shared/resource-type';
|
||||||
import { hasValue, isNotEmpty, isNotUndefined } from '../../empty.util';
|
import {hasValue, isNotEmpty, isNotUndefined} from '../../empty.util';
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
||||||
|
import {RequestService} from '../../../core/data/request.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component representing the create page for communities and collections
|
* Component representing the create page for communities and collections
|
||||||
@@ -54,7 +57,8 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
protected translate: TranslateService
|
protected translate: TranslateService,
|
||||||
|
protected requestService: RequestService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -76,13 +80,17 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
const dso = event.dso;
|
const dso = event.dso;
|
||||||
const uploader = event.uploader;
|
const uploader = event.uploader;
|
||||||
|
|
||||||
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
|
this.parentUUID$.pipe(
|
||||||
|
take(1),
|
||||||
|
flatMap((uuid: string) => {
|
||||||
const params = uuid ? [new RequestParam('parent', uuid)] : [];
|
const params = uuid ? [new RequestParam('parent', uuid)] : [];
|
||||||
this.dsoDataService.create(dso, ...params)
|
return this.dsoDataService.create(dso, ...params)
|
||||||
.pipe(getSucceededRemoteData())
|
.pipe(getFirstSucceededRemoteDataPayload()
|
||||||
.subscribe((dsoRD: RemoteData<TDomain>) => {
|
)
|
||||||
|
}))
|
||||||
|
.subscribe((dsoRD: TDomain) => {
|
||||||
if (isNotUndefined(dsoRD)) {
|
if (isNotUndefined(dsoRD)) {
|
||||||
this.newUUID = dsoRD.payload.uuid;
|
this.newUUID = dsoRD.uuid;
|
||||||
if (uploader.queue.length > 0) {
|
if (uploader.queue.length > 0) {
|
||||||
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
|
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
|
||||||
uploader.options.url = href;
|
uploader.options.url = href;
|
||||||
@@ -91,9 +99,9 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
} else {
|
} else {
|
||||||
this.navigateToNewPage();
|
this.navigateToNewPage();
|
||||||
}
|
}
|
||||||
this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success'));
|
this.dsoDataService.refreshCache(dsoRD);
|
||||||
}
|
}
|
||||||
});
|
this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,5 +113,4 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
this.router.navigate([this.frontendURL + this.newUUID]);
|
this.router.navigate([this.frontendURL + this.newUUID]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { CommunityDataService } from '../../../core/data/community-data.service';
|
import { CommunityDataService } from '../../../core/data/community-data.service';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import {TranslateModule, TranslateService} from '@ngx-translate/core';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { Community } from '../../../core/shared/community.model';
|
import { Community } from '../../../core/shared/community.model';
|
||||||
import { SharedModule } from '../../shared.module';
|
import { SharedModule } from '../../shared.module';
|
||||||
@@ -13,6 +13,10 @@ import { DataService } from '../../../core/data/data.service';
|
|||||||
import { DeleteComColPageComponent } from './delete-comcol-page.component';
|
import { DeleteComColPageComponent } from './delete-comcol-page.component';
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
import { NotificationsServiceStub } from '../../testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../testing/notifications-service.stub';
|
||||||
|
import {RequestService} from '../../../core/data/request.service';
|
||||||
|
import {getTestScheduler} from 'jasmine-marbles';
|
||||||
|
import {createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject$} from '../../remote-data.utils';
|
||||||
|
import {ComColDataService} from '../../../core/data/comcol-data.service';
|
||||||
|
|
||||||
describe('DeleteComColPageComponent', () => {
|
describe('DeleteComColPageComponent', () => {
|
||||||
let comp: DeleteComColPageComponent<DSpaceObject>;
|
let comp: DeleteComColPageComponent<DSpaceObject>;
|
||||||
@@ -22,9 +26,15 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
|
|
||||||
let community;
|
let community;
|
||||||
let newCommunity;
|
let newCommunity;
|
||||||
|
let parentCommunity;
|
||||||
let routerStub;
|
let routerStub;
|
||||||
let routeStub;
|
let routeStub;
|
||||||
let notificationsService;
|
let notificationsService;
|
||||||
|
let translateServiceStub;
|
||||||
|
let requestServiceStub;
|
||||||
|
|
||||||
|
let scheduler;
|
||||||
|
|
||||||
const validUUID = 'valid-uuid';
|
const validUUID = 'valid-uuid';
|
||||||
const invalidUUID = 'invalid-uuid';
|
const invalidUUID = 'invalid-uuid';
|
||||||
const frontendURL = '/testType';
|
const frontendURL = '/testType';
|
||||||
@@ -45,10 +55,21 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
parentCommunity = Object.assign(new Community(), {
|
||||||
|
uuid: 'a20da287-e174-466a-9926-f66as300d399',
|
||||||
|
id: 'a20da287-e174-466a-9926-f66as300d399',
|
||||||
|
metadata: [{
|
||||||
|
key: 'dc.title',
|
||||||
|
value: 'parent community'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
dsoDataService = jasmine.createSpyObj(
|
dsoDataService = jasmine.createSpyObj(
|
||||||
'dsoDataService',
|
'dsoDataService',
|
||||||
{
|
{
|
||||||
delete: observableOf({ isSuccessful: true })
|
delete: observableOf({ isSuccessful: true }),
|
||||||
|
findByHref: jasmine.createSpy('findByHref'),
|
||||||
|
refreshCache: jasmine.createSpy('refreshCache')
|
||||||
});
|
});
|
||||||
|
|
||||||
routerStub = {
|
routerStub = {
|
||||||
@@ -59,6 +80,14 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
data: observableOf(community)
|
data: observableOf(community)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
requestServiceStub = jasmine.createSpyObj('RequestService', {
|
||||||
|
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring')
|
||||||
|
});
|
||||||
|
|
||||||
|
translateServiceStub = jasmine.createSpyObj('TranslateService', {
|
||||||
|
instant: jasmine.createSpy('instant')
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
@@ -66,10 +95,12 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
imports: [TranslateModule.forRoot(), SharedModule, CommonModule, RouterTestingModule],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: DataService, useValue: dsoDataService },
|
{ provide: ComColDataService, useValue: dsoDataService },
|
||||||
{ provide: Router, useValue: routerStub },
|
{ provide: Router, useValue: routerStub },
|
||||||
{ provide: ActivatedRoute, useValue: routeStub },
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
|
{ provide: TranslateService, useValue: translateServiceStub},
|
||||||
|
{ provide: RequestService, useValue: requestServiceStub}
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -82,43 +113,63 @@ describe('DeleteComColPageComponent', () => {
|
|||||||
notificationsService = (comp as any).notifications;
|
notificationsService = (comp as any).notifications;
|
||||||
(comp as any).frontendURL = frontendURL;
|
(comp as any).frontendURL = frontendURL;
|
||||||
router = (comp as any).router;
|
router = (comp as any).router;
|
||||||
|
scheduler = getTestScheduler();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onConfirm', () => {
|
describe('onConfirm', () => {
|
||||||
let data1;
|
let data1;
|
||||||
let data2;
|
let data2;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
data1 = Object.assign(new Community(), {
|
data1 = {
|
||||||
|
dso: Object.assign(new Community(), {
|
||||||
uuid: validUUID,
|
uuid: validUUID,
|
||||||
metadata: [{
|
metadata: [{
|
||||||
key: 'dc.title',
|
key: 'dc.title',
|
||||||
value: 'test'
|
value: 'test'
|
||||||
}]
|
}]
|
||||||
});
|
}),
|
||||||
|
_links: {}
|
||||||
|
};
|
||||||
|
|
||||||
data2 = Object.assign(new Community(), {
|
data2 = {
|
||||||
|
dso: Object.assign(new Community(), {
|
||||||
uuid: invalidUUID,
|
uuid: invalidUUID,
|
||||||
metadata: [{
|
metadata: [{
|
||||||
key: 'dc.title',
|
key: 'dc.title',
|
||||||
value: 'test'
|
value: 'test'
|
||||||
}]
|
}]
|
||||||
});
|
}),
|
||||||
|
_links: {},
|
||||||
|
uploader: {
|
||||||
|
options: {
|
||||||
|
url: ''
|
||||||
|
},
|
||||||
|
queue: [],
|
||||||
|
/* tslint:disable:no-empty */
|
||||||
|
uploadAll: () => {}
|
||||||
|
/* tslint:enable:no-empty */
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show an error notification on failure', () => {
|
it('should show an error notification on failure', () => {
|
||||||
(dsoDataService.delete as any).and.returnValue(observableOf({ isSuccessful: false }));
|
(dsoDataService.delete as any).and.returnValue(observableOf({ isSuccessful: false }));
|
||||||
spyOn(router, 'navigate');
|
spyOn(router, 'navigate');
|
||||||
comp.onConfirm(data2);
|
scheduler.schedule(() => comp.onConfirm(data2));
|
||||||
|
scheduler.flush();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(notificationsService.error).toHaveBeenCalled();
|
expect(notificationsService.error).toHaveBeenCalled();
|
||||||
|
expect(dsoDataService.refreshCache).not.toHaveBeenCalled();
|
||||||
expect(router.navigate).toHaveBeenCalled();
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show a success notification on success and navigate', () => {
|
it('should show a success notification on success and navigate', () => {
|
||||||
spyOn(router, 'navigate');
|
spyOn(router, 'navigate');
|
||||||
comp.onConfirm(data1);
|
scheduler.schedule(() => comp.onConfirm(data1));
|
||||||
|
scheduler.flush();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(notificationsService.success).toHaveBeenCalled();
|
expect(notificationsService.success).toHaveBeenCalled();
|
||||||
|
expect(dsoDataService.refreshCache).toHaveBeenCalled();
|
||||||
expect(router.navigate).toHaveBeenCalled();
|
expect(router.navigate).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,13 +1,14 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import {RemoteData} from '../../../core/data/remote-data';
|
||||||
import { first, map } from 'rxjs/operators';
|
import {first, map} from 'rxjs/operators';
|
||||||
import { DataService } from '../../../core/data/data.service';
|
import {DSpaceObject} from '../../../core/shared/dspace-object.model';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import {NotificationsService} from '../../notifications/notifications.service';
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import {RestResponse} from '../../../core/cache/response.models';
|
||||||
import { RestResponse } from '../../../core/cache/response.models';
|
import {RequestService} from '../../../core/data/request.service';
|
||||||
|
import {ComColDataService} from '../../../core/data/comcol-data.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component representing the delete page for communities and collections
|
* Component representing the delete page for communities and collections
|
||||||
@@ -27,11 +28,12 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
public dsoRD$: Observable<RemoteData<TDomain>>;
|
public dsoRD$: Observable<RemoteData<TDomain>>;
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
protected dsoDataService: DataService<TDomain>,
|
protected dsoDataService: ComColDataService<TDomain>,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notifications: NotificationsService,
|
protected notifications: NotificationsService,
|
||||||
protected translate: TranslateService
|
protected translate: TranslateService,
|
||||||
|
protected requestService: RequestService
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
|
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
|
||||||
this.notifications.success(successMessage)
|
this.notifications.success(successMessage)
|
||||||
|
this.dsoDataService.refreshCache(dso);
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
|
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
|
||||||
this.notifications.error(errorMessage)
|
this.notifications.error(errorMessage)
|
||||||
|
@@ -69,3 +69,24 @@ export function createPendingRemoteDataObject<T>(object?: T): RemoteData<T> {
|
|||||||
export function createPendingRemoteDataObject$<T>(object?: T): Observable<RemoteData<T>> {
|
export function createPendingRemoteDataObject$<T>(object?: T): Observable<RemoteData<T>> {
|
||||||
return observableOf(createPendingRemoteDataObject(object));
|
return observableOf(createPendingRemoteDataObject(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to create a remote data object with no content
|
||||||
|
*/
|
||||||
|
export function createNoContentRemoteDataObject<T>(): RemoteData<T> {
|
||||||
|
return new RemoteData(
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
204
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to create a remote data object that has succeeded with no content, wrapped in an observable
|
||||||
|
*/
|
||||||
|
export function createNoContentRemoteDataObject$<T>(): Observable<RemoteData<T>> {
|
||||||
|
return observableOf(createNoContentRemoteDataObject());
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user