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

Reducer test and e2e test for persisting tree state through store

parent db7ebfb1
No related branches found
No related tags found
No related merge requests found
import { CommunityListPageProtractor } from './community-list-page.po';
describe('protractor CommunityListPage', () => {
let page: CommunityListPageProtractor;
beforeEach(() => {
page = new CommunityListPageProtractor();
});
it('should contain page-limited top communities (at least 1 expandable community)', () => {
page.navigateToCommunityList();
expect<any>(page.anExpandableCommunityIsPresent()).toEqual(true)
});
describe('if expanded a node and navigating away, tree state gets saved', () => {
it('if navigating back, same node is expanded', () => {
page.navigateToCommunityList();
const linkOfSecondNodeBeforeExpanding = page.getLinkOfSecondNode();
page.toggleExpandFirstExpandableCommunity();
const linkOfSecondNodeAfterExpanding = page.getLinkOfSecondNode();
page.navigateToHome();
page.navigateToCommunityList();
expect<any>(page.getLinkOfSecondNode()).toEqual(linkOfSecondNodeAfterExpanding);
page.toggleExpandFirstExpandableCommunity();
expect<any>(page.getLinkOfSecondNode()).toEqual(linkOfSecondNodeBeforeExpanding);
});
});
});
import { browser, by, element } from 'protractor';
export class CommunityListPageProtractor {
HOMEPAGE = '/home';
COMMUNITY_LIST = '/community-list';
navigateToHome() {
return browser.get(this.HOMEPAGE);
}
navigateToCommunityList() {
return browser.get(this.COMMUNITY_LIST);
}
anExpandableCommunityIsPresent() {
return element(by.css('.expandable-node h5 a')).isPresent();
}
toggleExpandFirstExpandableCommunity() {
element(by.css('.expandable-node button')).click();
}
getLinkOfSecondNode() {
return element(by.css('.cdk-tree-node h5 a')).getAttribute('href');
}
}
import { of as observableOf } from 'rxjs/internal/observable/of';
import { PaginatedList } from '../core/data/paginated-list';
import { Community } from '../core/shared/community.model';
import { PageInfo } from '../core/shared/page-info.model';
import { createSuccessfulRemoteDataObject$ } from '../shared/testing/utils';
import { toFlatNode } from './community-list-service';
import { CommunityListSaveAction } from './community-list.actions';
import { CommunityListReducer } from './community-list.reducer';
describe('communityListReducer', () => {
const mockSubcommunities1Page1 = [Object.assign(new Community(), {
id: 'ce64f48e-2c9b-411a-ac36-ee429c0e6a88',
uuid: 'ce64f48e-2c9b-411a-ac36-ee429c0e6a88',
name: 'subcommunity1',
})];
const mockFlatNodeOfCommunity = toFlatNode(
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(), [])),
name: 'community1',
}), observableOf(true), 0, false, null
);
it ('should set init state of the expandedNodes and loadingNode', () => {
const state = {
expandedNodes: [],
loadingNode: null,
};
const action = new CommunityListSaveAction([], null);
const newState = CommunityListReducer(null, action);
expect(newState).toEqual(state);
});
it ('should save new state of the expandedNodes and loadingNode at a save action', () => {
const state = {
expandedNodes: [mockFlatNodeOfCommunity],
loadingNode: null,
};
const action = new CommunityListSaveAction([mockFlatNodeOfCommunity], null);
const newState = CommunityListReducer(null, action);
expect(newState).toEqual(state);
});
});
import { FlatNode } from './community-list-service';
import { CommunityListActionTypes, CommunityListSaveAction } from './community-list.actions';
import { CommunityListActions, CommunityListActionTypes, CommunityListSaveAction } from './community-list.actions';
/**
* States we wish to put in store concerning the community list
......@@ -21,7 +21,7 @@ const initialState: CommunityListState = {
* Reducer to interact with store concerning objects for the community list
* @constructor
*/
export function CommunityListReducer(state = initialState, action: CommunityListSaveAction) {
export function CommunityListReducer(state = initialState, action: CommunityListActions) {
switch (action.type) {
case CommunityListActionTypes.SAVE: {
return Object.assign({}, state, {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment