mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-5738] add special group with mock & test cases.
This commit is contained in:
@@ -6,6 +6,8 @@ import { CacheableObject } from '../../cache/object-cache.reducer';
|
||||
import { RemoteData } from '../../data/remote-data';
|
||||
import { EPerson } from '../../eperson/models/eperson.model';
|
||||
import { EPERSON } from '../../eperson/models/eperson.resource-type';
|
||||
import { Group } from '../../eperson/models/group.model';
|
||||
import { GROUP } from '../../eperson/models/group.resource-type';
|
||||
import { HALLink } from '../../shared/hal-link.model';
|
||||
import { ResourceType } from '../../shared/resource-type';
|
||||
import { excludeFromEquals } from '../../utilities/equals.decorators';
|
||||
@@ -14,6 +16,7 @@ import { AUTH_STATUS } from './auth-status.resource-type';
|
||||
import { AuthTokenInfo } from './auth-token-info.model';
|
||||
import { AuthMethod } from './auth.method';
|
||||
|
||||
|
||||
/**
|
||||
* Object that represents the authenticated status of a user
|
||||
*/
|
||||
@@ -61,6 +64,7 @@ export class AuthStatus implements CacheableObject {
|
||||
_links: {
|
||||
self: HALLink;
|
||||
eperson: HALLink;
|
||||
specialGroups: HALLink;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -70,6 +74,13 @@ export class AuthStatus implements CacheableObject {
|
||||
@link(EPERSON)
|
||||
eperson?: Observable<RemoteData<EPerson>>;
|
||||
|
||||
/**
|
||||
* The SpecialGroup of this auth status
|
||||
* Will be undefined unless the SpecialGroup {@link HALLink} has been resolved.
|
||||
*/
|
||||
@link(GROUP)
|
||||
specialGroups?: Observable<RemoteData<Group>>;
|
||||
|
||||
/**
|
||||
* True if the token is valid, false if there was no token or the token wasn't valid
|
||||
*/
|
||||
|
@@ -29,5 +29,16 @@
|
||||
</ul>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngVar="(specialGroupsRD$ | async)?.payload?.page as specialGroups">
|
||||
<div *ngIf="specialGroups">
|
||||
<div id="specialGroups">
|
||||
<h3 class="mt-4">{{'profile.special.groups.head' | translate}}</h3>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li *ngFor="let specialGroup of specialGroups" class="list-group-item">{{specialGroup.name}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
@@ -13,13 +13,17 @@ import { NotificationsService } from '../shared/notifications/notifications.serv
|
||||
import { authReducer } from '../core/auth/auth.reducer';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
|
||||
import { createPaginatedList } from '../shared/testing/utils.test';
|
||||
import { BehaviorSubject, of as observableOf } from 'rxjs';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { AuthService } from '../core/auth/auth.service';
|
||||
import { RestResponse } from '../core/cache/response.models';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
||||
import { getTestScheduler } from 'jasmine-marbles';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
import { PaginatedList } from '../core/data/paginated-list.model';
|
||||
import { Group } from '../core/eperson/models/group.model';
|
||||
import { SpecialGroupData } from '../shared/testing/special-group.mock';
|
||||
|
||||
describe('ProfilePageComponent', () => {
|
||||
let component: ProfilePageComponent;
|
||||
@@ -235,4 +239,20 @@ describe('ProfilePageComponent', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('check for specialGroups', () => {
|
||||
it('should contains specialGroups list', () => {
|
||||
component.specialGroupsRD$ = SpecialGroupData;
|
||||
fixture.detectChanges();
|
||||
const specialGroupsEle = fixture.debugElement.query(By.css('#specialGroups'));
|
||||
expect(specialGroupsEle).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not contains specialGroups list', () => {
|
||||
component.specialGroupsRD$ = null;
|
||||
fixture.detectChanges();
|
||||
const specialGroupsEle = fixture.debugElement.query(By.css('#specialGroups'));
|
||||
expect(specialGroupsEle).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -20,6 +20,8 @@ import { AuthService } from '../core/auth/auth.service';
|
||||
import { Operation } from 'fast-json-patch';
|
||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../core/data/feature-authorization/feature-id';
|
||||
import { SpecialGroupData } from '../shared/testing/special-group.mock';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'ds-profile-page',
|
||||
@@ -45,6 +47,11 @@ export class ProfilePageComponent implements OnInit {
|
||||
*/
|
||||
groupsRD$: Observable<RemoteData<PaginatedList<Group>>>;
|
||||
|
||||
/**
|
||||
* The special groups the user belongs to
|
||||
*/
|
||||
specialGroupsRD$: Observable<RemoteData<PaginatedList<Group>>>;
|
||||
|
||||
/**
|
||||
* Prefix for the notification messages of this component
|
||||
*/
|
||||
@@ -88,6 +95,7 @@ export class ProfilePageComponent implements OnInit {
|
||||
);
|
||||
this.groupsRD$ = this.user$.pipe(switchMap((user: EPerson) => user.groups));
|
||||
this.canChangePassword$ = this.user$.pipe(switchMap((user: EPerson) => this.authorizationService.isAuthorized(FeatureID.CanChangePassword, user._links.self.href)));
|
||||
this.specialGroupsRD$ = SpecialGroupData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -34,6 +34,9 @@ export class AuthRequestServiceStub {
|
||||
},
|
||||
eperson: {
|
||||
href: this.mockUser._links.self.href
|
||||
},
|
||||
specialGroups: {
|
||||
href: this.mockUser._links.self.href
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -62,6 +65,9 @@ export class AuthRequestServiceStub {
|
||||
},
|
||||
eperson: {
|
||||
href: this.mockUser._links.self.href
|
||||
},
|
||||
specialGroups: {
|
||||
href: this.mockUser._links.self.href
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
64
src/app/shared/testing/special-group.mock.ts
Normal file
64
src/app/shared/testing/special-group.mock.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { EPersonMock } from './eperson.mock';
|
||||
import { of } from 'rxjs';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { RequestEntryState } from '../../core/data/request.reducer';
|
||||
import { PageInfo } from '../../core/shared/page-info.model';
|
||||
import { buildPaginatedList } from '../../core/data/paginated-list.model';
|
||||
import { Group } from '../../core/eperson/models/group.model';
|
||||
|
||||
|
||||
export const SpecialGroupMock2: Group = Object.assign(new Group(), {
|
||||
handle: null,
|
||||
subgroups: [],
|
||||
epersons: [],
|
||||
permanent: true,
|
||||
selfRegistered: false,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid2',
|
||||
},
|
||||
subgroups: { href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid2/subgroups' },
|
||||
object: { href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid2/object' },
|
||||
epersons: { href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid2/epersons' }
|
||||
},
|
||||
_name: 'testgroupname2',
|
||||
id: 'testgroupid2',
|
||||
uuid: 'testgroupid2',
|
||||
type: 'specialGroups',
|
||||
// object: createSuccessfulRemoteDataObject$({ name: 'testspecialGroupsid2objectName'})
|
||||
});
|
||||
|
||||
export const SpecialGroupMock: Group = Object.assign(new Group(), {
|
||||
handle: null,
|
||||
subgroups: [SpecialGroupMock2],
|
||||
epersons: [EPersonMock],
|
||||
selfRegistered: false,
|
||||
permanent: false,
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid',
|
||||
},
|
||||
subgroups: { href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid/subgroups' },
|
||||
object: { href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid2/object' },
|
||||
epersons: { href: 'https://rest.api/server/api/eperson/specialGroups/testgroupid/epersons' }
|
||||
},
|
||||
_name: 'testgroupname',
|
||||
id: 'testgroupid',
|
||||
uuid: 'testgroupid',
|
||||
type: 'specialGroups',
|
||||
});
|
||||
|
||||
export const SpecialGroupData = of(new RemoteData(
|
||||
new Date().getTime(),
|
||||
environment.cache.msToLive.default,
|
||||
new Date().getTime(),
|
||||
RequestEntryState.Success,
|
||||
undefined,
|
||||
buildPaginatedList(new PageInfo(), [SpecialGroupMock2,SpecialGroupMock]),
|
||||
200
|
||||
));
|
||||
|
||||
|
||||
|
||||
|
@@ -2861,6 +2861,8 @@
|
||||
|
||||
"profile.groups.head": "Authorization groups you belong to",
|
||||
|
||||
"profile.special.groups.head": "Authorization special groups you belong to",
|
||||
|
||||
"profile.head": "Update Profile",
|
||||
|
||||
"profile.metadata.form.error.firstname.required": "First Name is required",
|
||||
|
Reference in New Issue
Block a user