diff --git a/src/app/access-control/group-registry/group-form/group-form.component.spec.ts b/src/app/access-control/group-registry/group-form/group-form.component.spec.ts index 5f0f570044..9ad864f041 100644 --- a/src/app/access-control/group-registry/group-form/group-form.component.spec.ts +++ b/src/app/access-control/group-registry/group-form/group-form.component.spec.ts @@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { BrowserModule } from '@angular/platform-browser'; +import { BrowserModule, By } from '@angular/platform-browser'; import { ActivatedRoute, Router } from '@angular/router'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { Store } from '@ngrx/store'; diff --git a/src/app/access-control/group-registry/groups-registry.component.spec.ts b/src/app/access-control/group-registry/groups-registry.component.spec.ts index f4a06dc2d6..11ec73bb46 100644 --- a/src/app/access-control/group-registry/groups-registry.component.spec.ts +++ b/src/app/access-control/group-registry/groups-registry.component.spec.ts @@ -20,7 +20,7 @@ import { RouteService } from '../../core/services/route.service'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { PageInfo } from '../../core/shared/page-info.model'; import { NotificationsService } from '../../shared/notifications/notifications.service'; -import { GroupMock, GroupMock2 } from '../../shared/testing/group-mock'; +import { GroupMock, GroupMock2, GroupMockNoLinkedDSO } from '../../shared/testing/group-mock'; import { GroupsRegistryComponent } from './groups-registry.component'; import { EPersonMock, EPersonMock2 } from '../../shared/testing/eperson.mock'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; @@ -65,7 +65,7 @@ describe('GroupRegistryComponent', () => { }; beforeEach(waitForAsync(() => { - mockGroups = [GroupMock, GroupMock2]; + mockGroups = [GroupMock, GroupMock2, GroupMockNoLinkedDSO]; mockEPeople = [EPersonMock, EPersonMock2]; ePersonDataServiceStub = { findAllByHref(href: string): Observable>> { @@ -149,7 +149,12 @@ describe('GroupRegistryComponent', () => { }; dsoDataServiceStub = { findByHref(href: string): Observable> { - return createSuccessfulRemoteDataObject$(undefined); + console.warn(href); + return createSuccessfulRemoteDataObject$(Object.assign(new DSpaceObject(), { + id: "282164f5-d325-4740-8dd1-fa4d6d3e7200", + uuid: "282164f5-d325-4740-8dd1-fa4d6d3e7200", + name: 'x', + })); } }; authorizationService = jasmine.createSpyObj('authorizationService', ['isAuthorized']); @@ -192,7 +197,7 @@ describe('GroupRegistryComponent', () => { it('should display list of groups', () => { const groupIdsFound = fixture.debugElement.queryAll(By.css('#groups tr td:first-child')); - expect(groupIdsFound.length).toEqual(2); + expect(groupIdsFound.length).toEqual(3); mockGroups.map((group: Group) => { expect(groupIdsFound.find((foundEl) => { return (foundEl.nativeElement.textContent.trim() === group.uuid); @@ -200,6 +205,27 @@ describe('GroupRegistryComponent', () => { }); }); + it('should XXXXXX', () => { // WIP + const collectionNamesFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(3)')); + expect(collectionNamesFound.length).toEqual(3); + expect(collectionNamesFound[0].nativeElement.textContent).toEqual('z'); + expect(collectionNamesFound[1].nativeElement.textContent).toEqual('z'); + 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('when the user is a general admin', () => { beforeEach(fakeAsync(() => { @@ -214,7 +240,7 @@ describe('GroupRegistryComponent', () => { it('should be active', () => { const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); - expect(editButtonsFound.length).toEqual(2); + expect(editButtonsFound.length).toEqual(3); editButtonsFound.forEach((editButtonFound) => { expect(editButtonFound.nativeElement.disabled).toBeFalse(); }); @@ -248,7 +274,7 @@ describe('GroupRegistryComponent', () => { it('should be active', () => { const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); - expect(editButtonsFound.length).toEqual(2); + expect(editButtonsFound.length).toEqual(3); editButtonsFound.forEach((editButtonFound) => { expect(editButtonFound.nativeElement.disabled).toBeFalse(); }); @@ -267,7 +293,7 @@ describe('GroupRegistryComponent', () => { it('should not be active', () => { const editButtonsFound = fixture.debugElement.queryAll(By.css('#groups tr td:nth-child(5) button.btn-edit')); - expect(editButtonsFound.length).toEqual(2); + expect(editButtonsFound.length).toEqual(3); editButtonsFound.forEach((editButtonFound) => { expect(editButtonFound.nativeElement.disabled).toBeTrue(); }); diff --git a/src/app/core/eperson/eperson-data.service.spec.ts b/src/app/core/eperson/eperson-data.service.spec.ts index cd7b664379..ac08bda589 100644 --- a/src/app/core/eperson/eperson-data.service.spec.ts +++ b/src/app/core/eperson/eperson-data.service.spec.ts @@ -56,11 +56,11 @@ describe('EPersonDataService', () => { } function init() { - restEndpointURL = 'https://dspace.4science.it/dspace-spring-rest/api/eperson'; + restEndpointURL = 'https://rest.api/dspace-spring-rest/api/eperson'; epersonsEndpoint = `${restEndpointURL}/epersons`; epeople = [EPersonMock, EPersonMock2]; epeople$ = createSuccessfulRemoteDataObject$(createPaginatedList([epeople])); - rdbService = getMockRemoteDataBuildServiceHrefMap(undefined, { 'https://dspace.4science.it/dspace-spring-rest/api/eperson/epersons': epeople$ }); + rdbService = getMockRemoteDataBuildServiceHrefMap(undefined, { 'https://rest.api/dspace-spring-rest/api/eperson/epersons': epeople$ }); halService = new HALEndpointServiceStub(restEndpointURL); TestBed.configureTestingModule({ diff --git a/src/app/shared/testing/eperson.mock.ts b/src/app/shared/testing/eperson.mock.ts index 0ab3fa9ca1..370c2ff1b9 100644 --- a/src/app/shared/testing/eperson.mock.ts +++ b/src/app/shared/testing/eperson.mock.ts @@ -11,9 +11,9 @@ export const EPersonMock: EPerson = Object.assign(new EPerson(), { selfRegistered: false, _links: { self: { - href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/epersons/testid', + href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid', }, - groups: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/epersons/testid/groups' } + groups: { href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid/groups' } }, id: 'testid', uuid: 'testid', @@ -57,9 +57,9 @@ export const EPersonMock2: EPerson = Object.assign(new EPerson(), { selfRegistered: true, _links: { self: { - href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/epersons/testid2', + href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid2', }, - groups: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/epersons/testid2/groups' } + groups: { href: 'https://rest.api/dspace-spring-rest/api/eperson/epersons/testid2/groups' } }, id: 'testid2', uuid: 'testid2', diff --git a/src/app/shared/testing/group-mock.ts b/src/app/shared/testing/group-mock.ts index 24a78a58e5..61f6779b38 100644 --- a/src/app/shared/testing/group-mock.ts +++ b/src/app/shared/testing/group-mock.ts @@ -9,11 +9,11 @@ export const GroupMock2: Group = Object.assign(new Group(), { selfRegistered: false, _links: { self: { - href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2', + href: 'https://rest.api/server/api/eperson/groups/testgroupid2', }, - subgroups: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/subgroups' }, - object: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/object' }, - epersons: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/epersons' } + subgroups: { href: 'https://rest.api/server/api/eperson/groups/testgroupid2/subgroups' }, + object: { href: 'https://rest.api/server/api/eperson/groups/testgroupid2/object' }, + epersons: { href: 'https://rest.api/server/api/eperson/groups/testgroupid2/epersons' } }, _name: 'testgroupname2', id: 'testgroupid2', @@ -29,14 +29,34 @@ export const GroupMock: Group = Object.assign(new Group(), { permanent: false, _links: { self: { - href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid', + href: 'https://rest.api/server/api/eperson/groups/testgroupid', }, - subgroups: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid/subgroups' }, - object: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid2/object' }, - epersons: { href: 'https://dspace.4science.it/dspace-spring-rest/api/eperson/groups/testgroupid/epersons' } + subgroups: { href: 'https://rest.api/server/api/eperson/groups/testgroupid/subgroups' }, + object: { href: 'https://rest.api/server/api/eperson/groups/testgroupid2/object' }, + epersons: { href: 'https://rest.api/server/api/eperson/groups/testgroupid/epersons' } }, _name: 'testgroupname', id: 'testgroupid', uuid: 'testgroupid', 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', +});