mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Pagination for collections & Process feedback
This commit is contained in:
560
src/app/community-list-page/community-list-service.spec.ts
Normal file
560
src/app/community-list-page/community-list-service.spec.ts
Normal file
@@ -0,0 +1,560 @@
|
||||
import { TestBed, inject, async, fakeAsync } from '@angular/core/testing';
|
||||
import { CommunityListService, FlatNode, toFlatNode } from './community-list-service';
|
||||
import { CollectionDataService } from '../core/data/collection-data.service';
|
||||
import { PaginatedList } from '../core/data/paginated-list';
|
||||
import { PageInfo } from '../core/shared/page-info.model';
|
||||
import { CommunityDataService } from '../core/data/community-data.service';
|
||||
import {
|
||||
createFailedRemoteDataObject$,
|
||||
createSuccessfulRemoteDataObject$
|
||||
} from '../shared/testing/utils';
|
||||
import { Community } from '../core/shared/community.model';
|
||||
import { Collection } from '../core/shared/collection.model';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { FindListOptions } from '../core/data/request.models';
|
||||
|
||||
describe('CommunityListService', () => {
|
||||
const standardElementsPerPage = 2;
|
||||
let collectionDataServiceStub: any;
|
||||
let communityDataServiceStub: any;
|
||||
const mockSubcommunities1Page1 = [Object.assign(new Community(), {
|
||||
id: 'ce64f48e-2c9b-411a-ac36-ee429c0e6a88',
|
||||
uuid: 'ce64f48e-2c9b-411a-ac36-ee429c0e6a88',
|
||||
}),
|
||||
Object.assign(new Community(), {
|
||||
id: '59ee713b-ee53-4220-8c3f-9860dc84fe33',
|
||||
uuid: '59ee713b-ee53-4220-8c3f-9860dc84fe33',
|
||||
})
|
||||
];
|
||||
const mockCollectionsPage1 = [
|
||||
Object.assign(new Collection(), {
|
||||
id: 'e9dbf393-7127-415f-8919-55be34a6e9ed',
|
||||
uuid: 'e9dbf393-7127-415f-8919-55be34a6e9ed',
|
||||
name: 'Collection 1'
|
||||
}),
|
||||
Object.assign(new Collection(), {
|
||||
id: '59da2ff0-9bf4-45bf-88be-e35abd33f304',
|
||||
uuid: '59da2ff0-9bf4-45bf-88be-e35abd33f304',
|
||||
name: 'Collection 2'
|
||||
})
|
||||
];
|
||||
const mockCollectionsPage2 = [
|
||||
Object.assign(new Collection(), {
|
||||
id: 'a5159760-f362-4659-9e81-e3253ad91ede',
|
||||
uuid: 'a5159760-f362-4659-9e81-e3253ad91ede',
|
||||
name: 'Collection 3'
|
||||
}),
|
||||
Object.assign(new Collection(), {
|
||||
id: 'a392e16b-fcf2-400a-9a88-53ef7ecbdcd3',
|
||||
uuid: 'a392e16b-fcf2-400a-9a88-53ef7ecbdcd3',
|
||||
name: 'Collection 4'
|
||||
})
|
||||
];
|
||||
const mockListOfTopCommunitiesPage1 = [
|
||||
Object.assign(new Community(), {
|
||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), mockSubcommunities1Page1)),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
}),
|
||||
Object.assign(new Community(), {
|
||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [...mockCollectionsPage1, ...mockCollectionsPage2])),
|
||||
}),
|
||||
Object.assign(new Community(), {
|
||||
id: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
uuid: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
}),
|
||||
];
|
||||
const mockListOfTopCommunitiesPage2 = [
|
||||
Object.assign(new Community(), {
|
||||
id: 'c2e04392-3b8a-4dfa-976d-d76fb1b8a4b6',
|
||||
uuid: 'c2e04392-3b8a-4dfa-976d-d76fb1b8a4b6',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
}),
|
||||
];
|
||||
const mockTopCommunitiesWithChildrenArraysPage1 = [
|
||||
{
|
||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
subcommunities: mockSubcommunities1Page1,
|
||||
collections: [],
|
||||
},
|
||||
{
|
||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
subcommunities: [],
|
||||
collections: [...mockCollectionsPage1, ...mockCollectionsPage2],
|
||||
},
|
||||
{
|
||||
id: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
uuid: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
subcommunities: [],
|
||||
collections: [],
|
||||
}];
|
||||
const mockTopCommunitiesWithChildrenArraysPage2 = [
|
||||
{
|
||||
id: 'c2e04392-3b8a-4dfa-976d-d76fb1b8a4b6',
|
||||
uuid: 'c2e04392-3b8a-4dfa-976d-d76fb1b8a4b6',
|
||||
subcommunities: [],
|
||||
collections: [],
|
||||
}];
|
||||
|
||||
const allCommunities = [...mockTopCommunitiesWithChildrenArraysPage1, ...mockTopCommunitiesWithChildrenArraysPage2, ...mockSubcommunities1Page1];
|
||||
|
||||
let service: CommunityListService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
communityDataServiceStub = {
|
||||
findTop(options: FindListOptions = {}) {
|
||||
const allTopComs = [...mockListOfTopCommunitiesPage1, ...mockListOfTopCommunitiesPage2]
|
||||
let currentPage = options.currentPage;
|
||||
const elementsPerPage = 3;
|
||||
if (currentPage === undefined) {
|
||||
currentPage = 1
|
||||
}
|
||||
const startPageIndex = (currentPage - 1) * elementsPerPage;
|
||||
let endPageIndex = (currentPage * elementsPerPage);
|
||||
if (endPageIndex > allTopComs.length) {
|
||||
endPageIndex = allTopComs.length;
|
||||
}
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), allTopComs.slice(startPageIndex, endPageIndex)));
|
||||
},
|
||||
findByParent(parentUUID: string, options: FindListOptions = {}) {
|
||||
const foundCom = allCommunities.find((community) => (community.id === parentUUID));
|
||||
let currentPage = options.currentPage;
|
||||
let elementsPerPage = options.elementsPerPage;
|
||||
if (currentPage === undefined) {
|
||||
currentPage = 1
|
||||
}
|
||||
if (elementsPerPage === 0) {
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), (foundCom.subcommunities as [Community])));
|
||||
}
|
||||
elementsPerPage = standardElementsPerPage;
|
||||
if (foundCom !== undefined && foundCom.subcommunities !== undefined) {
|
||||
const coms = foundCom.subcommunities as [Community];
|
||||
const startPageIndex = (currentPage - 1) * elementsPerPage;
|
||||
let endPageIndex = (currentPage * elementsPerPage);
|
||||
if (endPageIndex > coms.length) {
|
||||
endPageIndex = coms.length;
|
||||
}
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), coms.slice(startPageIndex, endPageIndex)));
|
||||
} else {
|
||||
return createFailedRemoteDataObject$();
|
||||
}
|
||||
}
|
||||
};
|
||||
collectionDataServiceStub = {
|
||||
findByParent(parentUUID: string, options: FindListOptions = {}) {
|
||||
const foundCom = allCommunities.find((community) => (community.id === parentUUID));
|
||||
let currentPage = options.currentPage;
|
||||
let elementsPerPage = options.elementsPerPage;
|
||||
if (currentPage === undefined) {
|
||||
currentPage = 1
|
||||
}
|
||||
if (elementsPerPage === 0) {
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), (foundCom.collections as [Collection])));
|
||||
}
|
||||
elementsPerPage = standardElementsPerPage;
|
||||
if (foundCom !== undefined && foundCom.collections !== undefined) {
|
||||
const colls = foundCom.collections as [Collection];
|
||||
const startPageIndex = (currentPage - 1) * elementsPerPage;
|
||||
let endPageIndex = (currentPage * elementsPerPage);
|
||||
if (endPageIndex > colls.length) {
|
||||
endPageIndex = colls.length;
|
||||
}
|
||||
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), colls.slice(startPageIndex, endPageIndex)));
|
||||
} else {
|
||||
return createFailedRemoteDataObject$();
|
||||
}
|
||||
}
|
||||
};
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CommunityListService,
|
||||
{ provide: CollectionDataService, useValue: collectionDataServiceStub },
|
||||
{ provide: CommunityDataService, useValue: communityDataServiceStub },],
|
||||
});
|
||||
service = new CommunityListService(communityDataServiceStub, collectionDataServiceStub);
|
||||
}));
|
||||
|
||||
afterAll(() => service = new CommunityListService(communityDataServiceStub, collectionDataServiceStub));
|
||||
|
||||
it('should create', inject([CommunityListService], (serviceIn: CommunityListService) => {
|
||||
expect(serviceIn).toBeTruthy();
|
||||
}));
|
||||
|
||||
describe('getNextPageTopCommunities', () => {
|
||||
describe('also load in second page of top communities', () => {
|
||||
let flatNodeList;
|
||||
describe('None expanded: should return list containing only flatnodes of the test top communities page 1 and 2', () => {
|
||||
let findTopSpy;
|
||||
beforeEach(() => {
|
||||
findTopSpy = spyOn(communityDataServiceStub, 'findTop').and.callThrough();
|
||||
service.getNextPageTopCommunities();
|
||||
|
||||
const sub = service.loadCommunities(null)
|
||||
.subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('flatnode list should contain just flatnodes of top community list page 1 and 2', () => {
|
||||
expect(findTopSpy).toHaveBeenCalled();
|
||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockListOfTopCommunitiesPage2.length);
|
||||
mockListOfTopCommunitiesPage1.map((community) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === community.id))).toBeTruthy();
|
||||
});
|
||||
mockListOfTopCommunitiesPage2.map((community) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === community.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadCommunities', () => {
|
||||
describe('should transform all communities in a list of flatnodes with possible subcoms and collections as subflatnodes if they\'re expanded', () => {
|
||||
let flatNodeList;
|
||||
describe('None expanded: should return list containing only flatnodes of the test top communities', () => {
|
||||
beforeEach(() => {
|
||||
const sub = service.loadCommunities(null)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be as big as top community list', () => {
|
||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length);
|
||||
});
|
||||
it('flatnode list should contain flatNode representations of top communities', () => {
|
||||
mockListOfTopCommunitiesPage1.map((community) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === community.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
it('none of the flatnodes in the list should be expanded', () => {
|
||||
flatNodeList.map((flatnode: FlatNode) => {
|
||||
expect(flatnode.isExpanded).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('All top expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||
beforeEach(() => {
|
||||
const expandedNodes = [];
|
||||
mockListOfTopCommunitiesPage1.map((community: Community) => {
|
||||
const communityFlatNode = toFlatNode(community, true, 0, true, null);
|
||||
communityFlatNode.currentCollectionPage = 1;
|
||||
communityFlatNode.currentCommunityPage = 1;
|
||||
expandedNodes.push(communityFlatNode);
|
||||
});
|
||||
const sub = service.loadCommunities(expandedNodes)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be as big as top community list and size of its possible page-limited children', () => {
|
||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockSubcommunities1Page1.length + mockSubcommunities1Page1.length);
|
||||
});
|
||||
it('flatnode list should contain flatNode representations of all page-limited children', () => {
|
||||
mockSubcommunities1Page1.map((subcommunity) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === subcommunity.id))).toBeTruthy();
|
||||
});
|
||||
mockCollectionsPage1.map((collection) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === collection.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Just first top comm expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||
beforeEach(() => {
|
||||
const communityFlatNode = toFlatNode(mockListOfTopCommunitiesPage1[0], true, 0, true, null);
|
||||
communityFlatNode.currentCollectionPage = 1;
|
||||
communityFlatNode.currentCommunityPage = 1;
|
||||
const expandedNodes = [communityFlatNode];
|
||||
const sub = service.loadCommunities(expandedNodes)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be as big as top community list and size of page-limited children of first top community', () => {
|
||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockSubcommunities1Page1.length);
|
||||
});
|
||||
it('flatnode list should contain flatNode representations of all page-limited children of first top community', () => {
|
||||
mockSubcommunities1Page1.map((subcommunity) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === subcommunity.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Just second top comm expanded, collections at page 2: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||
beforeEach(() => {
|
||||
const communityFlatNode = toFlatNode(mockListOfTopCommunitiesPage1[1], true, 0, true, null);
|
||||
communityFlatNode.currentCollectionPage = 2;
|
||||
communityFlatNode.currentCommunityPage = 1;
|
||||
const expandedNodes = [communityFlatNode];
|
||||
const sub = service.loadCommunities(expandedNodes)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be as big as top community list and size of page-limited children of second top community', () => {
|
||||
expect(flatNodeList.length).toEqual(mockListOfTopCommunitiesPage1.length + mockCollectionsPage1.length + mockCollectionsPage2.length);
|
||||
});
|
||||
it('flatnode list should contain flatNode representations of all page-limited children of first top community', () => {
|
||||
mockCollectionsPage1.map((collection) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === collection.id))).toBeTruthy();
|
||||
});
|
||||
mockCollectionsPage2.map((collection) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === collection.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('transformListOfCommunities', () => {
|
||||
describe('should transform list of communities in a list of flatnodes with possible subcoms and collections as subflatnodes if they\'re expanded', () => {
|
||||
describe('list of communities with possible children', () => {
|
||||
const listOfCommunities = mockListOfTopCommunitiesPage1;
|
||||
let flatNodeList;
|
||||
describe('None expanded: should return list containing only flatnodes of the communities in the test list', () => {
|
||||
beforeEach(() => {
|
||||
const sub = service.transformListOfCommunities(new PaginatedList(new PageInfo(), listOfCommunities), 0, null, null)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be as big as community test list', () => {
|
||||
expect(flatNodeList.length).toEqual(listOfCommunities.length);
|
||||
});
|
||||
it('flatnode list should contain flatNode representations of all communities from test list', () => {
|
||||
listOfCommunities.map((community) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === community.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
it('none of the flatnodes in the list should be expanded', () => {
|
||||
flatNodeList.map((flatnode: FlatNode) => {
|
||||
expect(flatnode.isExpanded).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('All top expanded, all page 1: should return list containing flatnodes of the communities in the test list and all its possible page-limited children (subcommunities and collections)', () => {
|
||||
beforeEach(() => {
|
||||
const expandedNodes = [];
|
||||
listOfCommunities.map((community: Community) => {
|
||||
const communityFlatNode = toFlatNode(community, true, 0, true, null);
|
||||
communityFlatNode.currentCollectionPage = 1;
|
||||
communityFlatNode.currentCommunityPage = 1;
|
||||
expandedNodes.push(communityFlatNode);
|
||||
});
|
||||
const sub = service.transformListOfCommunities(new PaginatedList(new PageInfo(), listOfCommunities), 0, null, expandedNodes)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be as big as community test list and size of its possible children', () => {
|
||||
expect(flatNodeList.length).toEqual(listOfCommunities.length + mockSubcommunities1Page1.length + mockSubcommunities1Page1.length);
|
||||
});
|
||||
it('flatnode list should contain flatNode representations of all children', () => {
|
||||
mockSubcommunities1Page1.map((subcommunity) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === subcommunity.id))).toBeTruthy();
|
||||
});
|
||||
mockSubcommunities1Page1.map((collection) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === collection.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('transformCommunity', () => {
|
||||
describe('should transform community in list of flatnodes with possible subcoms and collections as subflatnodes if its expanded', () => {
|
||||
describe('topcommunity without subcoms or collections, unexpanded', () => {
|
||||
const communityWithNoSubcomsOrColls = Object.assign(new Community(), {
|
||||
id: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
uuid: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
metadata: {
|
||||
'dc.description': [{ language: 'en_US', value: 'no subcoms, 2 coll' }],
|
||||
'dc.title': [{ language: 'en_US', value: 'Community 2' }]
|
||||
}
|
||||
});
|
||||
let flatNodeList;
|
||||
describe('should return list containing only flatnode corresponding to that community', () => {
|
||||
beforeEach(() => {
|
||||
const sub = service.transformCommunity(communityWithNoSubcomsOrColls, 0, null, null)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be 1', () => {
|
||||
expect(flatNodeList.length).toEqual(1);
|
||||
});
|
||||
it('flatnode list only element should be flatNode of test community', () => {
|
||||
expect(flatNodeList[0].id).toEqual(communityWithNoSubcomsOrColls.id);
|
||||
});
|
||||
it('flatnode from test community is not expanded', () => {
|
||||
expect(flatNodeList[0].isExpanded).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('topcommunity with subcoms or collections, unexpanded', () => {
|
||||
const communityWithSubcoms = Object.assign(new Community(), {
|
||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), mockSubcommunities1Page1)),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
metadata: {
|
||||
'dc.description': [{ language: 'en_US', value: '2 subcoms, no coll' }],
|
||||
'dc.title': [{ language: 'en_US', value: 'Community 1' }]
|
||||
}
|
||||
});
|
||||
let flatNodeList;
|
||||
describe('should return list containing only flatnode corresponding to that community', () => {
|
||||
beforeAll(() => {
|
||||
const sub = service.transformCommunity(communityWithSubcoms, 0, null, null)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('length of flatnode list should be 1', () => {
|
||||
expect(flatNodeList.length).toEqual(1);
|
||||
});
|
||||
it('flatnode list only element should be flatNode of test community', () => {
|
||||
expect(flatNodeList[0].id).toEqual(communityWithSubcoms.id);
|
||||
});
|
||||
it('flatnode from test community is not expanded', () => {
|
||||
expect(flatNodeList[0].isExpanded).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('topcommunity with subcoms, expanded, first page for all', () => {
|
||||
describe('should return list containing flatnodes of that community, its possible subcommunities and its possible collections', () => {
|
||||
const communityWithSubcoms = Object.assign(new Community(), {
|
||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), mockSubcommunities1Page1)),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
metadata: {
|
||||
'dc.description': [{ language: 'en_US', value: '2 subcoms, no coll' }],
|
||||
'dc.title': [{ language: 'en_US', value: 'Community 1' }]
|
||||
}
|
||||
});
|
||||
let flatNodeList;
|
||||
beforeEach(() => {
|
||||
const communityFlatNode = toFlatNode(communityWithSubcoms, true, 0, true, null);
|
||||
communityFlatNode.currentCollectionPage = 1;
|
||||
communityFlatNode.currentCommunityPage = 1;
|
||||
const expandedNodes = [communityFlatNode];
|
||||
const sub = service.transformCommunity(communityWithSubcoms, 0, null, expandedNodes)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('list of flatnodes is length is 1 + nrOfSubcoms & first flatnode is of expanded test community', () => {
|
||||
expect(flatNodeList.length).toEqual(1 + mockSubcommunities1Page1.length);
|
||||
expect(flatNodeList[0].isExpanded).toEqual(true);
|
||||
expect(flatNodeList[0].id).toEqual(communityWithSubcoms.id);
|
||||
});
|
||||
it('list of flatnodes contains flatnodes for all subcoms of test community', () => {
|
||||
mockSubcommunities1Page1.map((subcommunity) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === subcommunity.id))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
it('the subcoms of the test community are a level higher than the parent community', () => {
|
||||
mockSubcommunities1Page1.map((subcommunity) => {
|
||||
expect((flatNodeList.find((flatnode) => (flatnode.id === subcommunity.id))).level).toEqual(flatNodeList[0].level + 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('topcommunity with collections, expanded, on second page of collections', () => {
|
||||
describe('should return list containing flatnodes of that community, its collections of the first two pages', () => {
|
||||
const communityWithCollections = Object.assign(new Community(), {
|
||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [...mockCollectionsPage1, ...mockCollectionsPage2])),
|
||||
metadata: {
|
||||
'dc.description': [{ language: 'en_US', value: '2 subcoms, no coll' }],
|
||||
'dc.title': [{ language: 'en_US', value: 'Community 1' }]
|
||||
}
|
||||
});
|
||||
let flatNodeList;
|
||||
beforeEach(() => {
|
||||
const communityFlatNode = toFlatNode(communityWithCollections, true, 0, true, null);
|
||||
communityFlatNode.currentCollectionPage = 2;
|
||||
communityFlatNode.currentCommunityPage = 1;
|
||||
const expandedNodes = [communityFlatNode];
|
||||
const sub = service.transformCommunity(communityWithCollections, 0, null, expandedNodes)
|
||||
.pipe(take(1)).subscribe((value) => flatNodeList = value);
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('list of flatnodes is length is 1 + nrOfCollections & first flatnode is of expanded test community', () => {
|
||||
expect(flatNodeList.length).toEqual(1 + mockCollectionsPage1.length + mockCollectionsPage2.length);
|
||||
expect(flatNodeList[0].isExpanded).toEqual(true);
|
||||
expect(flatNodeList[0].id).toEqual(communityWithCollections.id);
|
||||
});
|
||||
it('list of flatnodes contains flatnodes for all subcolls (first 2 pages) of test community', () => {
|
||||
mockCollectionsPage1.map((collection) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === collection.id))).toBeTruthy();
|
||||
});
|
||||
mockCollectionsPage2.map((collection) => {
|
||||
expect(flatNodeList.find((flatnode) => (flatnode.id === collection.id))).toBeTruthy();
|
||||
})
|
||||
});
|
||||
it('the collections of the test community are a level higher than the parent community', () => {
|
||||
mockCollectionsPage1.map((collection) => {
|
||||
expect((flatNodeList.find((flatnode) => (flatnode.id === collection.id))).level).toEqual(flatNodeList[0].level + 1);
|
||||
});
|
||||
mockCollectionsPage2.map((collection) => {
|
||||
expect((flatNodeList.find((flatnode) => (flatnode.id === collection.id))).level).toEqual(flatNodeList[0].level + 1);
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getIsExpandable', () => {
|
||||
describe('should return true', () => {
|
||||
it('if community has subcommunities', () => {
|
||||
const communityWithSubcoms = Object.assign(new Community(), {
|
||||
id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), mockSubcommunities1Page1)),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
metadata: {
|
||||
'dc.description': [{ language: 'en_US', value: '2 subcoms, no coll' }],
|
||||
'dc.title': [{ language: 'en_US', value: 'Community 1' }]
|
||||
}
|
||||
});
|
||||
expect(service.getIsExpandable(communityWithSubcoms)).toEqual(true);
|
||||
});
|
||||
it('if community has collections', () => {
|
||||
const communityWithCollections = Object.assign(new Community(), {
|
||||
id: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), mockCollectionsPage1)),
|
||||
metadata: {
|
||||
'dc.description': [{ language: 'en_US', value: 'no subcoms, 2 coll' }],
|
||||
'dc.title': [{ language: 'en_US', value: 'Community 2' }]
|
||||
}
|
||||
});
|
||||
expect(service.getIsExpandable(communityWithCollections)).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('should return false', () => {
|
||||
it('if community has neither subcommunities nor collections', () => {
|
||||
const communityWithNoSubcomsOrColls = Object.assign(new Community(), {
|
||||
id: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
uuid: 'efbf25e1-2d8c-4c28-8f3e-2e04c215be24',
|
||||
subcommunities: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
collections: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||
metadata: {
|
||||
'dc.description': [{ language: 'en_US', value: 'no subcoms, no coll' }],
|
||||
'dc.title': [{ language: 'en_US', value: 'Community 3' }]
|
||||
}
|
||||
});
|
||||
expect(service.getIsExpandable(communityWithNoSubcomsOrColls)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user