Skip to content
Snippets Groups Projects
Commit 1dfe7ec1 authored by Marie Verdonck's avatar Marie Verdonck
Browse files

70599: Test fixes comcol tree after changes

parent b1e44a7f
No related merge requests found
import { of as observableOf } from 'rxjs';
import { TestBed, inject, async } from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import { Store } from '@ngrx/store';
import { of as observableOf } from 'rxjs';
import { take } from 'rxjs/operators';
import { AppState } from '../app.reducer';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
import { PaginatedList } from '../core/data/paginated-list';
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
import { StoreMock } from '../shared/testing/store.mock';
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/remote-data.utils';
import { Community } from '../core/shared/community.model';
import { Collection } from '../core/shared/collection.model';
import { take } from 'rxjs/operators';
import { FindListOptions } from '../core/data/request.models';
import { PageInfo } from '../core/shared/page-info.model';
describe('CommunityListService', () => {
let store: StoreMock<AppState>;
......@@ -212,9 +210,11 @@ describe('CommunityListService', () => {
let findTopSpy;
beforeEach((done) => {
findTopSpy = spyOn(communityDataServiceStub, 'findTop').and.callThrough();
service.getNextPageTopCommunities();
service.loadCommunities(null)
service.loadCommunities({
currentPage: 2,
sort: new SortOptions('dc.title', SortDirection.ASC)
}, null)
.pipe(take(1))
.subscribe((value) => {
flatNodeList = value;
......@@ -240,7 +240,10 @@ describe('CommunityListService', () => {
let flatNodeList;
describe('None expanded: should return list containing only flatnodes of the test top communities', () => {
beforeEach((done) => {
service.loadCommunities(null)
service.loadCommunities({
currentPage: 1,
sort: new SortOptions('dc.title', SortDirection.ASC)
}, null)
.pipe(take(1))
.subscribe((value) => {
flatNodeList = value;
......@@ -270,7 +273,10 @@ describe('CommunityListService', () => {
communityFlatNode.currentCommunityPage = 1;
expandedNodes.push(communityFlatNode);
});
service.loadCommunities(expandedNodes)
service.loadCommunities({
currentPage: 1,
sort: new SortOptions('dc.title', SortDirection.ASC)
}, expandedNodes)
.pipe(take(1))
.subscribe((value) => {
flatNodeList = value;
......@@ -295,7 +301,10 @@ describe('CommunityListService', () => {
communityFlatNode.currentCollectionPage = 1;
communityFlatNode.currentCommunityPage = 1;
const expandedNodes = [communityFlatNode];
service.loadCommunities(expandedNodes)
service.loadCommunities({
currentPage: 1,
sort: new SortOptions('dc.title', SortDirection.ASC)
}, expandedNodes)
.pipe(take(1))
.subscribe((value) => {
flatNodeList = value;
......@@ -317,7 +326,10 @@ describe('CommunityListService', () => {
communityFlatNode.currentCollectionPage = 2;
communityFlatNode.currentCommunityPage = 1;
const expandedNodes = [communityFlatNode];
service.loadCommunities(expandedNodes)
service.loadCommunities({
currentPage: 1,
sort: new SortOptions('dc.title', SortDirection.ASC)
}, expandedNodes)
.pipe(take(1))
.subscribe((value) => {
flatNodeList = value;
......
......@@ -114,15 +114,9 @@ describe('CommunityListComponent', () => {
beforeEach(async(() => {
communityListServiceStub = {
topPageSize: 2,
topCurrentPage: 1,
collectionPageSize: 2,
subcommunityPageSize: 2,
pageSize: 2,
expandedNodes: [],
loadingNode: null,
getNextPageTopCommunities() {
this.topCurrentPage++;
},
getLoadingNodeFromStore() {
return observableOf(this.loadingNode);
},
......@@ -133,12 +127,12 @@ describe('CommunityListComponent', () => {
this.expandedNodes = expandedNodes;
this.loadingNode = loadingNode;
},
loadCommunities(expandedNodes) {
loadCommunities(options, expandedNodes) {
let flatnodes;
let showMoreTopComNode = false;
flatnodes = [...mockTopFlatnodesUnexpanded];
const currentPage = this.topCurrentPage;
const elementsPerPage = this.topPageSize;
const currentPage = options.currentPage;
const elementsPerPage = this.pageSize;
let endPageIndex = (currentPage * elementsPerPage);
if (endPageIndex >= flatnodes.length) {
endPageIndex = flatnodes.length;
......@@ -171,14 +165,14 @@ describe('CommunityListComponent', () => {
collFlatnodes = [...collFlatnodes, toFlatNode(coll, observableOf(false), topNode.level + 1, false, topNode)];
});
if (isNotEmpty(subComFlatnodes)) {
const endSubComIndex = this.subcommunityPageSize * expandedParent.currentCommunityPage;
const endSubComIndex = this.pageSize * expandedParent.currentCommunityPage;
flatnodes = [...flatnodes, ...subComFlatnodes.slice(0, endSubComIndex)];
if (subComFlatnodes.length > endSubComIndex) {
flatnodes = [...flatnodes, showMoreFlatNode('community', topNode.level + 1, expandedParent)];
}
}
if (isNotEmpty(collFlatnodes)) {
const endColIndex = this.collectionPageSize * expandedParent.currentCollectionPage;
const endColIndex = this.pageSize * expandedParent.currentCollectionPage;
flatnodes = [...flatnodes, ...collFlatnodes.slice(0, endColIndex)];
if (collFlatnodes.length > endColIndex) {
flatnodes = [...flatnodes, showMoreFlatNode('collection', topNode.level + 1, expandedParent)];
......@@ -225,6 +219,8 @@ describe('CommunityListComponent', () => {
it('should render a cdk tree with the first elementsPerPage (2) nr of top level communities, unexpanded', () => {
const expandableNodesFound = fixture.debugElement.queryAll(By.css('.expandable-node a'));
const childlessNodesFound = fixture.debugElement.queryAll(By.css('.childless-node a'));
console.log('expandableNodesFound', expandableNodesFound)
console.log('childlessNodesFound', childlessNodesFound)
const allNodes = [...expandableNodesFound, ...childlessNodesFound];
expect(allNodes.length).toEqual(2);
mockTopFlatnodesUnexpanded.slice(0, 2).map((topFlatnode: FlatNode) => {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment