diff --git a/config/environment.default.js b/config/environment.default.js index df4f89a2fe1766d86f20a4620c3614724721f6b4..24386d6cf71f8e14e799e0c938b88bc60c2977f4 100644 --- a/config/environment.default.js +++ b/config/environment.default.js @@ -9,10 +9,11 @@ module.exports = { }, // The REST API server settings. rest: { - ssl: true, - host: 'dspace7-entities.atmire.com', - port: 443, - nameSpace: '/server/api' + ssl: true, + host: 'dspace7.4science.cloud', + port: 443, + // NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript + nameSpace: '/server/api' }, // Caching settings cache: { diff --git a/src/app/core/shared/operators.ts b/src/app/core/shared/operators.ts index 0d1aa74591c8d9bf3b90da62a5d3b0224b21339c..308e4f8a2d57a5edc2a62d15a791679f7e421112 100644 --- a/src/app/core/shared/operators.ts +++ b/src/app/core/shared/operators.ts @@ -125,9 +125,3 @@ export const getFirstOccurrence = () => source.pipe( map((rd) => Object.assign(rd, { payload: rd.payload.page.length > 0 ? rd.payload.page[0] : undefined })) ); - -export const obsLog = (logString?: string) => - <T>(source: Observable<T>): Observable<T> => - source.pipe( - tap((t) => console.log(logString || '', t)) - ); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts index 241d022dc3391be5c10297fdf3405b87d21efc20..4434684cbbe803780d42fd61e6892058387c804f 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.spec.ts @@ -24,9 +24,11 @@ describe('DsDynamicLookupRelationSearchTabComponent', () => { let item1; let item2; let item3; + let item4; let searchResult1; let searchResult2; let searchResult3; + let searchResult4; let listID; let selection$; @@ -39,9 +41,11 @@ describe('DsDynamicLookupRelationSearchTabComponent', () => { item1 = Object.assign(new Item(), { uuid: 'e1c51c69-896d-42dc-8221-1d5f2ad5516e' }); item2 = Object.assign(new Item(), { uuid: 'c8279647-1acc-41ae-b036-951d5f65649b' }); item3 = Object.assign(new Item(), { uuid: 'c3bcbff5-ec0c-4831-8e4c-94b9c933ccac' }); + item4 = Object.assign(new Item(), { uuid: 'f96a385e-de10-45b2-be66-7f10bf52f765' }); searchResult1 = Object.assign(new ItemSearchResult(), { indexableObject: item1 }); searchResult2 = Object.assign(new ItemSearchResult(), { indexableObject: item2 }); searchResult3 = Object.assign(new ItemSearchResult(), { indexableObject: item3 }); + searchResult4 = Object.assign(new ItemSearchResult(), { indexableObject: item4 }); listID = '6b0c8221-fcb4-47a8-b483-ca32363fffb3'; selection$ = observableOf([searchResult1, searchResult2]); @@ -93,12 +97,12 @@ describe('DsDynamicLookupRelationSearchTabComponent', () => { describe('selectPage', () => { beforeEach(() => { spyOn(component.selectObject, 'emit'); - component.selectPage([searchResult1, searchResult2, searchResult3]); + component.selectPage([searchResult1, searchResult2, searchResult4]); }); it('should emit the page filtered from already selected objects and call select on the service for all objects', () => { - expect(component.selectObject.emit).toHaveBeenCalledWith(searchResult3); - expect(selectableListService.select).toHaveBeenCalledWith(listID, [searchResult1, searchResult2, searchResult3]); + expect(component.selectObject.emit).toHaveBeenCalledWith(searchResult4); + expect(selectableListService.select).toHaveBeenCalledWith(listID, [searchResult1, searchResult2, searchResult4]); }); }); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.spec.ts index 32c995ba94a2905bb73a384b95a6ce4627298554..203a4df0b074e887507301119e3d980de4c1fc35 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/selection-tab/dynamic-lookup-relation-selection-tab.component.spec.ts @@ -1,46 +1,59 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { TranslateModule } from '@ngx-translate/core'; import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service'; -import { RouterTestingModule } from '@angular/router/testing'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { VarDirective } from '../../../../../utils/var.directive'; -import { of as observableOf } from 'rxjs'; +import { Observable, of as observableOf } from 'rxjs'; import { PaginatedSearchOptions } from '../../../../../search/paginated-search-options.model'; import { ItemSearchResult } from '../../../../../object-collection/shared/item-search-result.model'; import { Item } from '../../../../../../core/shared/item.model'; import { DsDynamicLookupRelationSelectionTabComponent } from './dynamic-lookup-relation-selection-tab.component'; import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model'; +import { Router } from '@angular/router'; +import { By } from '@angular/platform-browser'; +import { RemoteData } from '../../../../../../core/data/remote-data'; +import { PaginatedList } from '../../../../../../core/data/paginated-list'; +import { ListableObject } from '../../../../../object-collection/shared/listable-object.model'; +import { createSuccessfulRemoteDataObject$ } from '../../../../../testing/utils'; describe('DsDynamicLookupRelationSelectionTabComponent', () => { let component: DsDynamicLookupRelationSelectionTabComponent; let fixture: ComponentFixture<DsDynamicLookupRelationSelectionTabComponent>; - let pSearchOptions = new PaginatedSearchOptions({pagination: new PaginationComponentOptions()}); + let pSearchOptions = new PaginatedSearchOptions({ pagination: new PaginationComponentOptions() }); let item1 = Object.assign(new Item(), { uuid: 'e1c51c69-896d-42dc-8221-1d5f2ad5516e' }); let item2 = Object.assign(new Item(), { uuid: 'c8279647-1acc-41ae-b036-951d5f65649b' }); let searchResult1 = Object.assign(new ItemSearchResult(), { indexableObject: item1 }); let searchResult2 = Object.assign(new ItemSearchResult(), { indexableObject: item2 }); let listID = '6b0c8221-fcb4-47a8-b483-ca32363fffb3'; - let selection$ = observableOf([searchResult1, searchResult2]); + let selection$; + let selectionRD$; + let router; function init() { - pSearchOptions = new PaginatedSearchOptions({pagination: new PaginationComponentOptions()}); + pSearchOptions = new PaginatedSearchOptions({ pagination: new PaginationComponentOptions() }); item1 = Object.assign(new Item(), { uuid: 'e1c51c69-896d-42dc-8221-1d5f2ad5516e' }); item2 = Object.assign(new Item(), { uuid: 'c8279647-1acc-41ae-b036-951d5f65649b' }); searchResult1 = Object.assign(new ItemSearchResult(), { indexableObject: item1 }); searchResult2 = Object.assign(new ItemSearchResult(), { indexableObject: item2 }); listID = '6b0c8221-fcb4-47a8-b483-ca32363fffb3'; selection$ = observableOf([searchResult1, searchResult2]); + selectionRD$ = createSelection([searchResult1, searchResult2]); + router = jasmine.createSpyObj('router', ['navigate']) } + beforeEach(async(() => { init(); TestBed.configureTestingModule({ declarations: [DsDynamicLookupRelationSelectionTabComponent, VarDirective], - imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], + imports: [TranslateModule.forRoot()], providers: [ { provide: SearchConfigurationService, useValue: { paginatedSearchOptions: observableOf(pSearchOptions) - } + }, + }, + { + provide: Router, useValue: router } ], schemas: [NO_ERRORS_SCHEMA] @@ -59,4 +72,26 @@ describe('DsDynamicLookupRelationSelectionTabComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should call navigate on the router when is called resetRoute', () => { + component.resetRoute(); + expect(router.navigate).toHaveBeenCalled(); + }); + + it('should call navigate on the router when is called resetRoute', () => { + component.selectionRD$ = createSelection([]); + fixture.detectChanges(); + const colComponent = fixture.debugElement.query(By.css('ds-viewable-collection')); + expect(colComponent).toBe(null); + }); + + it('should call navigate on the router when is called resetRoute', () => { + component.selectionRD$ = selectionRD$; + const colComponent = fixture.debugElement.query(By.css('ds-viewable-collection')); + expect(colComponent).not.toBe(null); + }); }); + +function createSelection(content: ListableObject[]): Observable<RemoteData<PaginatedList<ListableObject>>> { + return createSuccessfulRemoteDataObject$(new PaginatedList(undefined, content)); +} diff --git a/src/app/shared/mocks/dspace-rest-v2/mocks/mock-response-map.ts b/src/app/shared/mocks/dspace-rest-v2/mocks/mock-response-map.ts index 1d1b47ee78d7e2bf6e459af783c68dd9f925c158..a7fab782dac7ed5f5d73901ac48916604a724050 100644 --- a/src/app/shared/mocks/dspace-rest-v2/mocks/mock-response-map.ts +++ b/src/app/shared/mocks/dspace-rest-v2/mocks/mock-response-map.ts @@ -5,6 +5,11 @@ export class MockResponseMap extends Map<string, any> {}; export const MOCK_RESPONSE_MAP: InjectionToken<MockResponseMap> = new InjectionToken<MockResponseMap>('mockResponseMap'); +/** + * List of endpoints with their matching mock response + * Note that this list is only used in development mode + * In production the actual endpoints on the REST server will be called + */ export const mockResponseMap: MockResponseMap = new Map([ // [ '/config/submissionforms/traditionalpageone', mockSubmissionResponse ] ]); diff --git a/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts index d1536c56e6f8e46d0232dd49c2afb8f02a7022c9..d47e05c8fe419f2fb741e25c102ac23b16265616 100644 --- a/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts +++ b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts @@ -10,7 +10,7 @@ import { Observable } from 'rxjs'; templateUrl: './selectable-list-item-control.component.html' }) /** - * Component for determining what component to use depending on the item's relationship type (relationship.type) + * Component for rendering list item that has a control (checkbox or radio button) because it's selectable */ export class SelectableListItemControlComponent implements OnInit { /** diff --git a/src/app/shared/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts index 1be0f69106a4dab78c7042c9ba2e76a8bc5db214..6ca7adb3f9edb057cfbde64d912b4a78b416c4c7 100644 --- a/src/app/shared/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -1,21 +1,11 @@ -import { - ChangeDetectionStrategy, - Component, - EventEmitter, - Input, - Output, - ViewEncapsulation -} from '@angular/core'; +import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core'; import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { PaginatedList } from '../../core/data/paginated-list'; import { RemoteData } from '../../core/data/remote-data'; import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; -import { DSpaceObject } from '../../core/shared/dspace-object.model'; -import { SearchResult } from '../search/search-result.model'; import { SelectableListService } from './selectable-list/selectable-list.service'; -import { map, take, tap } from 'rxjs/operators'; import { ViewMode } from '../../core/shared/view-mode.model'; import { Context } from '../../core/shared/context.model'; import { CollectionElementLinkType } from '../object-collection/collection-element-link.type'; @@ -60,9 +50,6 @@ export class ObjectListComponent { @Input() hidePagerWhenSinglePage = true; @Input() selectable = false; @Input() selectionConfig: { repeatable: boolean, listId: string }; - // @Input() previousSelection: ListableObject[] = []; - // allSelected = false; - // selectAllLoading = false; /** * The link type of the listable elements diff --git a/src/app/shared/object-list/selectable-list/selectable-list.actions.ts b/src/app/shared/object-list/selectable-list/selectable-list.actions.ts index 3dedf7e6a2363695c81799df3f4ed4169edab015..010ae5609d45f8e49a24fe40ded5db44dfea3869 100644 --- a/src/app/shared/object-list/selectable-list/selectable-list.actions.ts +++ b/src/app/shared/object-list/selectable-list/selectable-list.actions.ts @@ -55,7 +55,7 @@ export class SelectableListSelectSingleAction extends SelectableListAction { } /** - * Action to deselect objects in a the selectable list + * Action to deselect a single object in a the selectable list */ export class SelectableListDeselectSingleAction extends SelectableListAction { payload: ListableObject; @@ -67,7 +67,7 @@ export class SelectableListDeselectSingleAction extends SelectableListAction { } /** - * Action to deselect a single object in a the selectable list + * Action to deselect objects in a the selectable list */ export class SelectableListDeselectAction extends SelectableListAction { payload: ListableObject[]; diff --git a/src/app/shared/page-size-selector/page-size-selector.component.ts b/src/app/shared/page-size-selector/page-size-selector.component.ts index 799993d35dd2078585b731cdda44ea2f33566f3c..b200c337f83aa86444862e92aac3dcc7b3771213 100644 --- a/src/app/shared/page-size-selector/page-size-selector.component.ts +++ b/src/app/shared/page-size-selector/page-size-selector.component.ts @@ -14,7 +14,7 @@ import { map } from 'rxjs/operators'; }) /** - * This component represents the part of the search sidebar that contains the general search settings. + * This component represents the part of the search sidebar that contains the page size settings. */ export class PageSizeSelectorComponent implements OnInit { /** diff --git a/src/app/shared/search/search-filters/search-filters.component.ts b/src/app/shared/search/search-filters/search-filters.component.ts index e9b5f46fa83ccef4169b289a963a86992e8b53f3..78c40501e684e241e64409da86e09784814e76a4 100644 --- a/src/app/shared/search/search-filters/search-filters.component.ts +++ b/src/app/shared/search/search-filters/search-filters.component.ts @@ -8,7 +8,7 @@ import { RemoteData } from '../../../core/data/remote-data'; import { SearchFilterConfig } from '../search-filter-config.model'; import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; import { SearchFilterService } from '../../../core/shared/search/search-filter.service'; -import { getSucceededRemoteData, obsLog } from '../../../core/shared/operators'; +import { getSucceededRemoteData } from '../../../core/shared/operators'; import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component'; import { currentPath } from '../../utils/route.utils'; import { Router } from '@angular/router'; diff --git a/src/app/shared/search/search-labels/search-label/search-label.component.ts b/src/app/shared/search/search-labels/search-label/search-label.component.ts index bc3a8b289722b5f10463e8b336e996ce8ebb8f30..956b5b81def5da8efde39852db94ffb914975618 100644 --- a/src/app/shared/search/search-labels/search-label/search-label.component.ts +++ b/src/app/shared/search/search-labels/search-label/search-label.component.ts @@ -26,7 +26,8 @@ export class SearchLabelComponent implements OnInit { * Initialize the instance variable */ constructor( - private searchService: SearchService, private router: Router) { + private searchService: SearchService, + private router: Router) { } ngOnInit(): void { diff --git a/src/app/shared/utils/route.utils.ts b/src/app/shared/utils/route.utils.ts index b0771d4f13044464669a2dab45a0868732a9aa93..6510fb889408a034a2d6a59cac9200b9d98cc926 100644 --- a/src/app/shared/utils/route.utils.ts +++ b/src/app/shared/utils/route.utils.ts @@ -1,5 +1,9 @@ import { Router } from '@angular/router'; +/** + * Util function to retrieve the current path (without query parameters) the user is on + * @param router The router service + */ export function currentPath(router: Router) { const urlTree = router.parseUrl(router.url); return '/' + urlTree.root.children.primary.segments.map((it) => it.path).join('/') diff --git a/src/app/submission/sections/form/section-form.component.ts b/src/app/submission/sections/form/section-form.component.ts index 6c8d7c5468c832837e8285ce2dbec0584eaaca0a..49dbaea807ccb8e9bbafeed70a6b240d684b1776 100644 --- a/src/app/submission/sections/form/section-form.component.ts +++ b/src/app/submission/sections/form/section-form.component.ts @@ -166,8 +166,8 @@ export class SubmissionSectionformComponent extends SectionModelComponent { .subscribe(([sectionData, workspaceItem]: [WorkspaceitemSectionFormObject, WorkspaceItem]) => { if (isUndefined(this.formModel)) { this.sectionData.errors = []; - // Is the first loading so init form this.workspaceItem = workspaceItem; + // Is the first loading so init form this.initForm(sectionData); this.sectionData.data = sectionData; this.subscriptions();