[CST-4058] tests

This commit is contained in:
Davide Negretti
2021-08-23 18:09:03 +02:00
parent 8134e6bc17
commit 2cb9345ed5
2 changed files with 17 additions and 71 deletions

View File

@@ -21,7 +21,7 @@ import { RouteService } from '../../core/services/route.service';
import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { PageInfo } from '../../core/shared/page-info.model'; import { PageInfo } from '../../core/shared/page-info.model';
import { NotificationsService } from '../../shared/notifications/notifications.service'; import { NotificationsService } from '../../shared/notifications/notifications.service';
import { GroupMock, GroupMock2, GroupMockNoLinkedDSO } from '../../shared/testing/group-mock'; import { GroupMock, GroupMock2 } from '../../shared/testing/group-mock';
import { GroupsRegistryComponent } from './groups-registry.component'; import { GroupsRegistryComponent } from './groups-registry.component';
import { EPersonMock, EPersonMock2 } from '../../shared/testing/eperson.mock'; import { EPersonMock, EPersonMock2 } from '../../shared/testing/eperson.mock';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
@@ -67,7 +67,7 @@ describe('GroupRegistryComponent', () => {
}; };
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
mockGroups = [GroupMock, GroupMock2, GroupMockNoLinkedDSO]; mockGroups = [GroupMock, GroupMock2];
mockEPeople = [EPersonMock, EPersonMock2]; mockEPeople = [EPersonMock, EPersonMock2];
ePersonDataServiceStub = { ePersonDataServiceStub = {
findAllByHref(href: string): Observable<RemoteData<PaginatedList<EPerson>>> { findAllByHref(href: string): Observable<RemoteData<PaginatedList<EPerson>>> {
@@ -149,36 +149,13 @@ describe('GroupRegistryComponent', () => {
}), [result])); }), [result]));
} }
}; };
dsoDataServiceStub = { // EDIT ripristinare dsoDataServiceStub = {
findByHref(href: string): Observable<RemoteData<DSpaceObject>> { findByHref(href: string): Observable<RemoteData<DSpaceObject>> {
console.warn(href); console.warn(href);
return createSuccessfulRemoteDataObject$(Object.assign(new DSpaceObject(), { return createSuccessfulRemoteDataObject$(undefined);
id: "282164f5-d325-4740-8dd1-fa4d6d3e7200",
uuid: "282164f5-d325-4740-8dd1-fa4d6d3e7200",
name: 'x',
}));
} }
}; };
dataServiceStub = { // EDIT eliminare
findAllByHref(href: string): Observable<RemoteData<PaginatedList<any>>> {
switch (href) {
case 'https://rest.api/server/api/eperson/groups/testgroupid2/object':
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo({
elementsPerPage: 1,
totalElements: 1,
totalPages: 1,
currentPage: 1
}), [{ name: 'xxx' }]));
default:
return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo({
elementsPerPage: 1,
totalElements: 0,
totalPages: 0,
currentPage: 1
}), []));
}
},
};
authorizationService = jasmine.createSpyObj('authorizationService', ['isAuthorized']); authorizationService = jasmine.createSpyObj('authorizationService', ['isAuthorized']);
setIsAuthorized(true, true); setIsAuthorized(true, true);
paginationService = new PaginationServiceStub(); paginationService = new PaginationServiceStub();
@@ -220,7 +197,7 @@ describe('GroupRegistryComponent', () => {
it('should display list of groups', () => { it('should display list of groups', () => {
const groupIdsFound = fixture.debugElement.queryAll(By.css('#groups tr td:first-child')); const groupIdsFound = fixture.debugElement.queryAll(By.css('#groups tr td:first-child'));
expect(groupIdsFound.length).toEqual(3); expect(groupIdsFound.length).toEqual(2);
mockGroups.map((group: Group) => { mockGroups.map((group: Group) => {
expect(groupIdsFound.find((foundEl) => { expect(groupIdsFound.find((foundEl) => {
return (foundEl.nativeElement.textContent.trim() === group.uuid); return (foundEl.nativeElement.textContent.trim() === group.uuid);
@@ -228,25 +205,11 @@ describe('GroupRegistryComponent', () => {
}); });
}); });
fit('should XXXXXX', () => { // WIP it('should display community/collection name if present', () => {
const collectionNamesFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(3)')); const collectionNamesFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(3)'));
expect(collectionNamesFound.length).toEqual(3); expect(collectionNamesFound.length).toEqual(2);
expect(collectionNamesFound[0].nativeElement.textContent).toEqual('z'); expect(collectionNamesFound[0].nativeElement.textContent).toEqual('');
expect(collectionNamesFound[1].nativeElement.textContent).toEqual('z'); expect(collectionNamesFound[1].nativeElement.textContent).toEqual('testgroupid2objectName');
expect(collectionNamesFound[2].nativeElement.textContent).toEqual('z');
// mockGroups.map((group: Group) => {
// expect(collectionNamesFound.find((foundEl) => {
// return (group.uuid === 'testgroupid3') ? (foundEl.nativeElement.textContent.length == 0) : (foundEl.nativeElement.textContent.length > 0);
// })).toBeTruthy();
// expect(collectionNamesFound.find((foundEl) => group.uuid.length > 0 )).toBeTruthy();
// collectionNamesFound.forEach((name) => {
// const nameExpected = !(group.uuid === 'testgroupid3');
// // expect(nameExpected ? name.nativeElement.textContent.length > 0 : name.nativeElement.textContent.length == 0).toBeTrue();
// expect(name.nativeElement.textContent).toBe('x');
// });
// expect(collectionNamesFound.find((foundEl) => foundEl.nativeElement.textContent.length == group.)).toBeTruthy();
// });
}); });
describe('edit buttons', () => { describe('edit buttons', () => {
@@ -263,7 +226,7 @@ describe('GroupRegistryComponent', () => {
it('should be active', () => { it('should be active', () => {
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
expect(editButtonsFound.length).toEqual(3); expect(editButtonsFound.length).toEqual(2);
editButtonsFound.forEach((editButtonFound) => { editButtonsFound.forEach((editButtonFound) => {
expect(editButtonFound.nativeElement.disabled).toBeFalse(); expect(editButtonFound.nativeElement.disabled).toBeFalse();
}); });
@@ -297,7 +260,7 @@ describe('GroupRegistryComponent', () => {
it('should be active', () => { it('should be active', () => {
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
expect(editButtonsFound.length).toEqual(3); expect(editButtonsFound.length).toEqual(2);
editButtonsFound.forEach((editButtonFound) => { editButtonsFound.forEach((editButtonFound) => {
expect(editButtonFound.nativeElement.disabled).toBeFalse(); expect(editButtonFound.nativeElement.disabled).toBeFalse();
}); });
@@ -316,7 +279,7 @@ describe('GroupRegistryComponent', () => {
it('should not be active', () => { it('should not be active', () => {
const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit'));
expect(editButtonsFound.length).toEqual(3); expect(editButtonsFound.length).toEqual(2);
editButtonsFound.forEach((editButtonFound) => { editButtonsFound.forEach((editButtonFound) => {
expect(editButtonFound.nativeElement.disabled).toBeTrue(); expect(editButtonFound.nativeElement.disabled).toBeTrue();
}); });

View File

@@ -1,5 +1,7 @@
import { Group } from '../../core/eperson/models/group.model'; import { Group } from '../../core/eperson/models/group.model';
import { EPersonMock } from './eperson.mock'; import { EPersonMock } from './eperson.mock';
import { of } from 'rxjs';
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
export const GroupMock2: Group = Object.assign(new Group(), { export const GroupMock2: Group = Object.assign(new Group(), {
handle: null, handle: null,
@@ -19,6 +21,7 @@ export const GroupMock2: Group = Object.assign(new Group(), {
id: 'testgroupid2', id: 'testgroupid2',
uuid: 'testgroupid2', uuid: 'testgroupid2',
type: 'group', type: 'group',
object: createSuccessfulRemoteDataObject$({ name: 'testgroupid2objectName'})
}); });
export const GroupMock: Group = Object.assign(new Group(), { export const GroupMock: Group = Object.assign(new Group(), {
@@ -39,24 +42,4 @@ export const GroupMock: Group = Object.assign(new Group(), {
id: 'testgroupid', id: 'testgroupid',
uuid: 'testgroupid', uuid: 'testgroupid',
type: 'group', type: 'group',
}); });
export const GroupMockNoLinkedDSO: Group = Object.assign(new Group(), {
handle: null,
subgroups: [],
epersons: [],
permanent: true,
selfRegistered: false,
_links: {
self: {
href: 'https://rest.api/server/api/eperson/groups/testgroupid3',
},
subgroups: { href: 'https://rest.api/server/api/eperson/groups/testgroupid3/subgroups' },
object: { href: 'https://rest.api/server/api/eperson/groups/testgroupid3/object' }, // should be empty
epersons: { href: 'https://rest.api/server/api/eperson/groups/testgroupid3/epersons' }
},
_name: 'testgroupname3',
id: 'testgroupid3',
uuid: 'testgroupid3',
type: 'group',
});