Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move subscription button to DSO edit menu #2385

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/app/collection-page/collection-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
</ds-comcol-page-content>
</header>
<ds-dso-edit-menu></ds-dso-edit-menu>
<div class="pl-2 space-children-mr">
<ds-dso-page-subscription-button [dso]="collection"></ds-dso-page-subscription-button>
</div>
</div>
<section class="comcol-page-browse-section">
<!-- Browse-By Links -->
Expand Down
3 changes: 0 additions & 3 deletions src/app/community-page/community-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
</ds-comcol-page-content>
</header>
<ds-dso-edit-menu></ds-dso-edit-menu>
<div class="pl-2 space-children-mr">
<ds-dso-page-subscription-button [dso]="communityPayload"></ds-dso-page-subscription-button>
</div>
</div>
<section class="comcol-page-browse-section">

Expand Down
254 changes: 199 additions & 55 deletions src/app/shared/dso-page/dso-edit-menu.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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', () => {

Expand All @@ -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',
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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$());

Expand All @@ -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();
});
});
});
});
});
Loading
Loading