group reducer and group registry tests

This commit is contained in:
Marie Verdonck
2020-03-19 17:35:38 +01:00
parent e10a37e414
commit 909158c30e
6 changed files with 189 additions and 8 deletions

View File

@@ -188,7 +188,7 @@
"admin.access-control.epeople.table.name": "Name",
"admin.access-control.epeople.table.email": "E-mail",
"admin.access-control.epeople.table.email": "E-mail (exact)",
"admin.access-control.epeople.table.edit": "Edit",
@@ -287,7 +287,7 @@
"admin.access-control.groups.form.members-list.search.scope.metadata": "Metadata",
"admin.access-control.groups.form.members-list.search.scope.email": "E-mail",
"admin.access-control.groups.form.members-list.search.scope.email": "E-mail (exact)",
"admin.access-control.groups.form.members-list.search.button": "Search",

View File

@@ -89,8 +89,7 @@ describe('EPeopleRegistryComponent', () => {
providers: [EPeopleRegistryComponent,
{ provide: EPersonDataService, useValue: ePersonDataServiceStub },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: FormBuilderService, useValue: builderService },
EPeopleRegistryComponent
{ provide: FormBuilderService, useValue: builderService }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();

View File

@@ -0,0 +1,54 @@
import { GroupMock } from '../../../shared/testing/group-mock';
import { GroupRegistryCancelGroupAction, GroupRegistryEditGroupAction } from './group-registry.actions';
import { groupRegistryReducer, GroupRegistryState } from './group-registry.reducers';
const initialState: GroupRegistryState = {
editGroup: null,
};
const editState: GroupRegistryState = {
editGroup: GroupMock,
};
class NullAction extends GroupRegistryEditGroupAction {
type = null;
constructor() {
super(undefined);
}
}
describe('groupRegistryReducer', () => {
it('should return the current state when no valid actions have been made', () => {
const state = initialState;
const action = new NullAction();
const newState = groupRegistryReducer(state, action);
expect(newState).toEqual(state);
});
it('should start with an initial state', () => {
const state = initialState;
const action = new NullAction();
const initState = groupRegistryReducer(undefined, action);
expect(initState).toEqual(state);
});
it('should update the current state to change the editGroup to a new group when GroupRegistryEditGroupAction is dispatched', () => {
const state = editState;
const action = new GroupRegistryEditGroupAction(GroupMock);
const newState = groupRegistryReducer(state, action);
expect(newState.editGroup).toEqual(GroupMock);
});
it('should update the current state to remove the editGroup from the state when GroupRegistryCancelGroupAction is dispatched', () => {
const state = editState;
const action = new GroupRegistryCancelGroupAction();
const newState = groupRegistryReducer(state, action);
expect(newState.editGroup).toEqual(null);
});
});

View File

@@ -7,7 +7,6 @@ import { GroupRegistryAction, GroupRegistryActionTypes, GroupRegistryEditGroupAc
*/
export interface GroupRegistryState {
editGroup: Group;
selectedGroup: Group[];
}
/**
@@ -15,7 +14,6 @@ export interface GroupRegistryState {
*/
const initialState: GroupRegistryState = {
editGroup: null,
selectedGroup: [],
};
/**

View File

@@ -0,0 +1,130 @@
import { CommonModule } from '@angular/common';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, fakeAsync, inject, TestBed, tick } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule, By } from '@angular/platform-browser';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { Observable } from 'rxjs/internal/Observable';
import { PaginatedList } from '../../../core/data/paginated-list';
import { RemoteData } from '../../../core/data/remote-data';
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
import { GroupDataService } from '../../../core/eperson/group-data.service';
import { EPerson } from '../../../core/eperson/models/eperson.model';
import { Group } from '../../../core/eperson/models/group.model';
import { PageInfo } from '../../../core/shared/page-info.model';
import { MockTranslateLoader } from '../../../shared/mocks/mock-translate-loader';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { EPersonMock, EPersonMock2 } from '../../../shared/testing/eperson-mock';
import { GroupMock, GroupMock2 } from '../../../shared/testing/group-mock';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service-stub';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/testing/utils';
import { GroupsRegistryComponent } from './groups-registry.component';
describe('GroupRegistryComponent', () => {
let component: GroupsRegistryComponent;
let fixture: ComponentFixture<GroupsRegistryComponent>;
let ePersonDataServiceStub: any;
let groupsDataServiceStub: any;
let mockGroups;
let mockEPeople;
beforeEach(async(() => {
mockGroups = [GroupMock, GroupMock2];
mockEPeople = [EPersonMock, EPersonMock2];
ePersonDataServiceStub = {
findAllByHref(href: string): Observable<RemoteData<PaginatedList<EPerson>>> {
switch (href) {
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/epersons':
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid/epersons':
return createSuccessfulRemoteDataObject$(new PaginatedList(null, [EPersonMock]));
default:
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
}
}
};
groupsDataServiceStub = {
allGroups: mockGroups,
getGroups(): Observable<RemoteData<PaginatedList<Group>>> {
return createSuccessfulRemoteDataObject$(new PaginatedList(null, this.allGroups));
},
findAllByHref(href: string): Observable<RemoteData<PaginatedList<Group>>> {
switch (href) {
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/groups':
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
case 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid/groups':
return createSuccessfulRemoteDataObject$(new PaginatedList(null, [GroupMock2]));
default:
return createSuccessfulRemoteDataObject$(new PaginatedList(null, []));
}
},
getGroupEditPageRouterLink(group: Group): string {
return '/admin/access-control/groups/' + group.id;
},
searchGroups(query: string): Observable<RemoteData<PaginatedList<Group>>> {
const result = this.allGroups.find((group: Group) => {
return (group.id.includes(query))
});
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [result]));
}
};
TestBed.configureTestingModule({
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: MockTranslateLoader
}
}),
],
declarations: [GroupsRegistryComponent],
providers: [GroupsRegistryComponent,
{ provide: EPersonDataService, useValue: ePersonDataServiceStub },
{ provide: GroupDataService, useValue: groupsDataServiceStub },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GroupsRegistryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create GroupRegistryComponent', inject([GroupsRegistryComponent], (comp: GroupsRegistryComponent) => {
expect(comp).toBeDefined();
}));
it('should display list of groups', () => {
const groupIdsFound = fixture.debugElement.queryAll(By.css('#groups tr td:first-child'));
expect(groupIdsFound.length).toEqual(2);
mockGroups.map((group: Group) => {
expect(groupIdsFound.find((foundEl) => {
return (foundEl.nativeElement.textContent.trim() === group.uuid);
})).toBeTruthy();
})
});
describe('search', () => {
describe('when searching with query', () => {
let groupIdsFound;
beforeEach(fakeAsync(() => {
component.search({ query: GroupMock2.id });
tick();
fixture.detectChanges();
groupIdsFound = fixture.debugElement.queryAll(By.css('#groups tr td:first-child'));
}));
it('should display search result', () => {
expect(groupIdsFound.length).toEqual(1);
expect(groupIdsFound.find((foundEl) => {
return (foundEl.nativeElement.textContent.trim() === GroupMock2.uuid);
})).toBeTruthy();
});
});
});
});

View File

@@ -3,7 +3,7 @@ import { GroupMock } from './group-mock';
export const EPersonMock: EPerson = Object.assign(new EPerson(), {
handle: null,
groups: [],
groups: [GroupMock],
netid: 'test@test.com',
lastActive: '2018-05-14T12:25:42.411+0000',
canLogIn: true,
@@ -49,7 +49,7 @@ export const EPersonMock: EPerson = Object.assign(new EPerson(), {
export const EPersonMock2: EPerson = Object.assign(new EPerson(), {
handle: null,
groups: [GroupMock],
groups: [],
netid: 'test2@test.com',
lastActive: '2019-05-14T12:25:42.411+0000',
canLogIn: false,