mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Update DSO edit menu resolver tests
- Abstract away the different "subsections" ~ DSO type (the tests should not care about this)
Instead, retrieve sections of interest by ID & assert whether they're there & how they should look
- Test separately for Communities, Collections & Items
- Test newly added menu section
(cherry picked from commit 18b7a9c7de
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
578a427f46
commit
6d195f5ffa
@@ -1,6 +1,6 @@
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { MenuServiceStub } from '../testing/menu-service.stub';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { combineLatest, map, of as observableOf } from 'rxjs';
|
||||
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
@@ -16,10 +16,13 @@ import { Item } from '../../core/shared/item.model';
|
||||
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
|
||||
import { MenuID } from '../menu/menu-id.model';
|
||||
import { MenuItemType } from '../menu/menu-item-type.model';
|
||||
import { TextMenuItemModel } from '../menu/menu-item/models/text.model';
|
||||
import { LinkMenuItemModel } from '../menu/menu-item/models/link.model';
|
||||
import { ResearcherProfileDataService } from '../../core/profile/researcher-profile-data.service';
|
||||
import { NotificationsService } from '../notifications/notifications.service';
|
||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||
import { Community } from '../../core/shared/community.model';
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
import flatten from 'lodash/flatten';
|
||||
|
||||
describe('DSOEditMenuResolver', () => {
|
||||
|
||||
@@ -37,25 +40,44 @@ describe('DSOEditMenuResolver', () => {
|
||||
let notificationsService;
|
||||
let translate;
|
||||
|
||||
const route = {
|
||||
data: {
|
||||
menu: {
|
||||
'statistics': [{
|
||||
id: 'statistics-dummy-1',
|
||||
active: false,
|
||||
visible: true,
|
||||
model: null
|
||||
}]
|
||||
}
|
||||
},
|
||||
params: {id: 'test-uuid'},
|
||||
const dsoRoute = (dso: DSpaceObject) => {
|
||||
return {
|
||||
data: {
|
||||
menu: {
|
||||
'statistics': [{
|
||||
id: 'statistics-dummy-1',
|
||||
active: false,
|
||||
visible: true,
|
||||
model: null
|
||||
}]
|
||||
}
|
||||
},
|
||||
params: {id: dso.uuid},
|
||||
};
|
||||
};
|
||||
|
||||
const state = {
|
||||
url: 'test-url'
|
||||
};
|
||||
|
||||
const testObject = Object.assign(new Item(), {uuid: 'test-uuid', type: 'item', _links: {self: {href: 'self-link'}}});
|
||||
const testCommunity: Community = Object.assign(new Community(), {
|
||||
uuid: 'test-community-uuid',
|
||||
type: 'community',
|
||||
_links: {self: {href: 'self-link'}},
|
||||
});
|
||||
const testCollection: Collection = Object.assign(new Collection(), {
|
||||
uuid: 'test-collection-uuid',
|
||||
type: 'collection',
|
||||
_links: {self: {href: 'self-link'}},
|
||||
});
|
||||
const testItem: Item = Object.assign(new Item(), {
|
||||
uuid: 'test-item-uuid',
|
||||
type: 'item',
|
||||
_links: {self: {href: 'self-link'}},
|
||||
});
|
||||
|
||||
let testObject: DSpaceObject;
|
||||
let route;
|
||||
|
||||
const dummySections1 = [{
|
||||
id: 'dummy-1',
|
||||
@@ -90,6 +112,10 @@ describe('DSOEditMenuResolver', () => {
|
||||
}];
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
// test with Items unless specified otherwise
|
||||
testObject = testItem;
|
||||
route = dsoRoute(testItem);
|
||||
|
||||
menuService = new MenuServiceStub();
|
||||
spyOn(menuService, 'getMenu').and.returnValue(observableOf(MENU_STATE));
|
||||
|
||||
@@ -154,16 +180,17 @@ describe('DSOEditMenuResolver', () => {
|
||||
{
|
||||
...route.data.menu,
|
||||
[MenuID.DSO_EDIT]: [
|
||||
...dummySections1.map((menu) => Object.assign(menu, {id: menu.id + '-test-uuid'})),
|
||||
...dummySections2.map((menu) => Object.assign(menu, {id: menu.id + '-test-uuid'}))
|
||||
...dummySections1.map((menu) => Object.assign(menu, {id: menu.id + '-test-item-uuid'})),
|
||||
...dummySections2.map((menu) => Object.assign(menu, {id: menu.id + '-test-item-uuid'}))
|
||||
]
|
||||
}
|
||||
);
|
||||
expect(dSpaceObjectDataService.findById).toHaveBeenCalledWith('test-uuid', true, false);
|
||||
expect(dSpaceObjectDataService.findById).toHaveBeenCalledWith('test-item-uuid', true, false);
|
||||
expect(resolver.getDsoMenus).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create all menus when a dso is found based on the route scope query param when no id param is present', (done) => {
|
||||
spyOn(resolver, 'getDsoMenus').and.returnValue(
|
||||
[observableOf(dummySections1), observableOf(dummySections2)]
|
||||
@@ -198,6 +225,7 @@ describe('DSOEditMenuResolver', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the statistics menu when no dso is found', (done) => {
|
||||
(dSpaceObjectDataService.findById as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$());
|
||||
|
||||
@@ -211,49 +239,165 @@ describe('DSOEditMenuResolver', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDsoMenus', () => {
|
||||
it('should return as first part the item version, orcid and claim list ', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
result[0].subscribe((menuList) => {
|
||||
expect(menuList.length).toEqual(3);
|
||||
expect(menuList[0].id).toEqual('orcid-dso');
|
||||
expect(menuList[0].active).toEqual(false);
|
||||
// Visible should be false due to the item not being of type person
|
||||
expect(menuList[0].visible).toEqual(false);
|
||||
expect(menuList[0].model.type).toEqual(MenuItemType.LINK);
|
||||
|
||||
expect(menuList[1].id).toEqual('version-dso');
|
||||
expect(menuList[1].active).toEqual(false);
|
||||
expect(menuList[1].visible).toEqual(true);
|
||||
expect(menuList[1].model.type).toEqual(MenuItemType.ONCLICK);
|
||||
expect((menuList[1].model as TextMenuItemModel).text).toEqual('message');
|
||||
expect(menuList[1].model.disabled).toEqual(false);
|
||||
expect(menuList[1].icon).toEqual('code-branch');
|
||||
|
||||
expect(menuList[2].id).toEqual('claim-dso');
|
||||
expect(menuList[2].active).toEqual(false);
|
||||
// Visible should be false due to the item not being of type person
|
||||
expect(menuList[2].visible).toEqual(false);
|
||||
expect(menuList[2].model.type).toEqual(MenuItemType.ONCLICK);
|
||||
expect((menuList[2].model as TextMenuItemModel).text).toEqual('item.page.claim.button');
|
||||
done();
|
||||
describe('for Communities', () => {
|
||||
beforeEach(() => {
|
||||
testObject = testCommunity;
|
||||
dSpaceObjectDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(testCommunity));
|
||||
route = dsoRoute(testCommunity);
|
||||
});
|
||||
|
||||
it('should not return Item-specific entries', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const orcidEntry = menu.find(entry => entry.id === 'orcid-dso');
|
||||
expect(orcidEntry).toBeFalsy();
|
||||
|
||||
const versionEntry = menu.find(entry => entry.id === 'version-dso');
|
||||
expect(versionEntry).toBeFalsy();
|
||||
|
||||
const claimEntry = menu.find(entry => entry.id === 'claim-dso');
|
||||
expect(claimEntry).toBeFalsy();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return Community/Collection-specific entries', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
|
||||
expect(subscribeEntry).toBeTruthy();
|
||||
expect(subscribeEntry.active).toBeFalse();
|
||||
expect(subscribeEntry.visible).toBeTrue();
|
||||
expect(subscribeEntry.model.type).toEqual(MenuItemType.ONCLICK);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return as third part the common list ', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const editEntry = menu.find(entry => entry.id === 'edit-dso');
|
||||
expect(editEntry).toBeTruthy();
|
||||
expect(editEntry.active).toBeFalse();
|
||||
expect(editEntry.visible).toBeTrue();
|
||||
expect(editEntry.model.type).toEqual(MenuItemType.LINK);
|
||||
expect((editEntry.model as LinkMenuItemModel).link).toEqual(
|
||||
'/communities/test-community-uuid/edit/metadata'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should return as second part the common list ', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
result[1].subscribe((menuList) => {
|
||||
expect(menuList.length).toEqual(1);
|
||||
expect(menuList[0].id).toEqual('edit-dso');
|
||||
expect(menuList[0].active).toEqual(false);
|
||||
expect(menuList[0].visible).toEqual(true);
|
||||
expect(menuList[0].model.type).toEqual(MenuItemType.LINK);
|
||||
expect((menuList[0].model as LinkMenuItemModel).text).toEqual('item.page.edit');
|
||||
expect((menuList[0].model as LinkMenuItemModel).link).toEqual('/items/test-uuid/edit/metadata');
|
||||
expect(menuList[0].icon).toEqual('pencil-alt');
|
||||
done();
|
||||
|
||||
describe('for Collections', () => {
|
||||
beforeEach(() => {
|
||||
testObject = testCollection;
|
||||
dSpaceObjectDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(testCollection));
|
||||
route = dsoRoute(testCollection);
|
||||
});
|
||||
|
||||
it('should not return Item-specific entries', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const orcidEntry = menu.find(entry => entry.id === 'orcid-dso');
|
||||
expect(orcidEntry).toBeFalsy();
|
||||
|
||||
const versionEntry = menu.find(entry => entry.id === 'version-dso');
|
||||
expect(versionEntry).toBeFalsy();
|
||||
|
||||
const claimEntry = menu.find(entry => entry.id === 'claim-dso');
|
||||
expect(claimEntry).toBeFalsy();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return Community/Collection-specific entries', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
|
||||
expect(subscribeEntry).toBeTruthy();
|
||||
expect(subscribeEntry.active).toBeFalse();
|
||||
expect(subscribeEntry.visible).toBeTrue();
|
||||
expect(subscribeEntry.model.type).toEqual(MenuItemType.ONCLICK);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return as third part the common list ', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const editEntry = menu.find(entry => entry.id === 'edit-dso');
|
||||
expect(editEntry).toBeTruthy();
|
||||
expect(editEntry.active).toBeFalse();
|
||||
expect(editEntry.visible).toBeTrue();
|
||||
expect(editEntry.model.type).toEqual(MenuItemType.LINK);
|
||||
expect((editEntry.model as LinkMenuItemModel).link).toEqual(
|
||||
'/collections/test-collection-uuid/edit/metadata'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('for Items', () => {
|
||||
beforeEach(() => {
|
||||
testObject = testItem;
|
||||
dSpaceObjectDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(testItem));
|
||||
route = dsoRoute(testItem);
|
||||
});
|
||||
|
||||
it('should return Item-specific entries', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const orcidEntry = menu.find(entry => entry.id === 'orcid-dso');
|
||||
expect(orcidEntry).toBeTruthy();
|
||||
expect(orcidEntry.active).toBeFalse();
|
||||
expect(orcidEntry.visible).toBeFalse();
|
||||
expect(orcidEntry.model.type).toEqual(MenuItemType.LINK);
|
||||
|
||||
const versionEntry = menu.find(entry => entry.id === 'version-dso');
|
||||
expect(versionEntry).toBeTruthy();
|
||||
expect(versionEntry.active).toBeFalse();
|
||||
expect(versionEntry.visible).toBeTrue();
|
||||
expect(versionEntry.model.type).toEqual(MenuItemType.ONCLICK);
|
||||
expect(versionEntry.model.disabled).toBeFalse();
|
||||
|
||||
const claimEntry = menu.find(entry => entry.id === 'claim-dso');
|
||||
expect(claimEntry).toBeTruthy();
|
||||
expect(claimEntry.active).toBeFalse();
|
||||
expect(claimEntry.visible).toBeFalse();
|
||||
expect(claimEntry.model.type).toEqual(MenuItemType.ONCLICK);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not return Community/Collection-specific entries', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const subscribeEntry = menu.find(entry => entry.id === 'subscribe');
|
||||
expect(subscribeEntry).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return as third part the common list ', (done) => {
|
||||
const result = resolver.getDsoMenus(testObject, route, state);
|
||||
combineLatest(result).pipe(map(flatten)).subscribe((menu) => {
|
||||
const editEntry = menu.find(entry => entry.id === 'edit-dso');
|
||||
expect(editEntry).toBeTruthy();
|
||||
expect(editEntry.active).toBeFalse();
|
||||
expect(editEntry.visible).toBeTrue();
|
||||
expect(editEntry.model.type).toEqual(MenuItemType.LINK);
|
||||
expect((editEntry.model as LinkMenuItemModel).link).toEqual(
|
||||
'/items/test-item-uuid/edit/metadata'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user