Skip to content

Commit 193d56d

Browse files
Merge branch 'refactor-comcol-pages_contribute-7.6' into refactor-comcol-pages_contribute-main
2 parents 645024d + 6e29f30 commit 193d56d

95 files changed

Lines changed: 1247 additions & 858 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cypress/e2e/browse-by-author.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ describe('Browse By Author', () => {
55
cy.visit('/browse/author');
66

77
// Wait for <ds-browse-by-metadata-page> to be visible
8-
cy.get('ds-browse-by-metadata-page').should('be.visible');
8+
cy.get('ds-browse-by-metadata').should('be.visible');
99

1010
// Analyze <ds-browse-by-metadata-page> for accessibility
11-
testA11y('ds-browse-by-metadata-page');
11+
testA11y('ds-browse-by-metadata');
1212
});
1313
});

cypress/e2e/browse-by-dateissued.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ describe('Browse By Date Issued', () => {
55
cy.visit('/browse/dateissued');
66

77
// Wait for <ds-browse-by-date-page> to be visible
8-
cy.get('ds-browse-by-date-page').should('be.visible');
8+
cy.get('ds-browse-by-date').should('be.visible');
99

1010
// Analyze <ds-browse-by-date-page> for accessibility
11-
testA11y('ds-browse-by-date-page');
11+
testA11y('ds-browse-by-date');
1212
});
1313
});

cypress/e2e/browse-by-subject.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ describe('Browse By Subject', () => {
55
cy.visit('/browse/subject');
66

77
// Wait for <ds-browse-by-metadata-page> to be visible
8-
cy.get('ds-browse-by-metadata-page').should('be.visible');
8+
cy.get('ds-browse-by-metadata').should('be.visible');
99

1010
// Analyze <ds-browse-by-metadata-page> for accessibility
11-
testA11y('ds-browse-by-metadata-page');
11+
testA11y('ds-browse-by-metadata');
1212
});
1313
});

cypress/e2e/browse-by-title.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ describe('Browse By Title', () => {
55
cy.visit('/browse/title');
66

77
// Wait for <ds-browse-by-title-page> to be visible
8-
cy.get('ds-browse-by-title-page').should('be.visible');
8+
cy.get('ds-browse-by-title').should('be.visible');
99

1010
// Analyze <ds-browse-by-title-page> for accessibility
11-
testA11y('ds-browse-by-title-page');
11+
testA11y('ds-browse-by-title');
1212
});
1313
});

src/app/browse-by/browse-by-date-page/browse-by-date-page.component.spec.ts renamed to src/app/browse-by/browse-by-date/browse-by-date.component.spec.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowseByDatePageComponent } from './browse-by-date-page.component';
1+
import { BrowseByDateComponent } from './browse-by-date.component';
22
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
33
import { CommonModule } from '@angular/common';
44
import { RouterTestingModule } from '@angular/router/testing';
@@ -15,18 +15,19 @@ import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
1515
import { Community } from '../../core/shared/community.model';
1616
import { Item } from '../../core/shared/item.model';
1717
import { BrowseEntrySearchOptions } from '../../core/browse/browse-entry-search-options.model';
18-
import { toRemoteData } from '../browse-by-metadata-page/browse-by-metadata-page.component.spec';
18+
import { toRemoteData } from '../browse-by-metadata/browse-by-metadata.component.spec';
1919
import { VarDirective } from '../../shared/utils/var.directive';
2020
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
2121
import { PaginationService } from '../../core/pagination/pagination.service';
2222
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
2323
import { APP_CONFIG } from '../../../config/app-config.interface';
2424
import { environment } from '../../../environments/environment';
2525
import { SortDirection } from '../../core/cache/models/sort-options.model';
26+
import { cold } from 'jasmine-marbles';
2627

27-
describe('BrowseByDatePageComponent', () => {
28-
let comp: BrowseByDatePageComponent;
29-
let fixture: ComponentFixture<BrowseByDatePageComponent>;
28+
describe('BrowseByDateComponent', () => {
29+
let comp: BrowseByDateComponent;
30+
let fixture: ComponentFixture<BrowseByDateComponent>;
3031
let route: ActivatedRoute;
3132
let paginationService;
3233

@@ -86,7 +87,7 @@ describe('BrowseByDatePageComponent', () => {
8687
beforeEach(waitForAsync(() => {
8788
TestBed.configureTestingModule({
8889
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
89-
declarations: [BrowseByDatePageComponent, EnumKeysPipe, VarDirective],
90+
declarations: [BrowseByDateComponent, EnumKeysPipe, VarDirective],
9091
providers: [
9192
{ provide: ActivatedRoute, useValue: activatedRouteStub },
9293
{ provide: BrowseService, useValue: mockBrowseService },
@@ -101,7 +102,7 @@ describe('BrowseByDatePageComponent', () => {
101102
}));
102103

103104
beforeEach(() => {
104-
fixture = TestBed.createComponent(BrowseByDatePageComponent);
105+
fixture = TestBed.createComponent(BrowseByDateComponent);
105106
const browseService = fixture.debugElement.injector.get(BrowseService);
106107
spyOn(browseService, 'getFirstItemFor')
107108
// ok to expect the default browse as first param since we just need the mock items obtained via sort direction.
@@ -112,9 +113,13 @@ describe('BrowseByDatePageComponent', () => {
112113
fixture.detectChanges();
113114
});
114115

115-
it('should initialize the list of items', () => {
116+
it('should initialize the list of items', (done: DoneFn) => {
117+
expect(comp.loading$).toBeObservable(cold('(a|)', {
118+
a: false,
119+
}));
116120
comp.items$.subscribe((result) => {
117121
expect(result.payload.page).toEqual([firstItem]);
122+
done();
118123
});
119124
});
120125

src/app/browse-by/browse-by-date-page/browse-by-date-page.component.ts renamed to src/app/browse-by/browse-by-date/browse-by-date.component.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
2-
import {
3-
BrowseByMetadataPageComponent,
4-
browseParamsToOptions,
5-
getBrowseSearchOptions
6-
} from '../browse-by-metadata-page/browse-by-metadata-page.component';
7-
import { combineLatest as observableCombineLatest } from 'rxjs';
2+
import { BrowseByMetadataComponent, browseParamsToOptions, getBrowseSearchOptions } from '../browse-by-metadata/browse-by-metadata.component';
3+
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
84
import { hasValue, isNotEmpty } from '../../shared/empty.util';
95
import { ActivatedRoute, Params, Router } from '@angular/router';
106
import { BrowseService } from '../../core/browse/browse.service';
@@ -23,31 +19,32 @@ import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
2319
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
2420

2521
@Component({
26-
selector: 'ds-browse-by-date-page',
27-
styleUrls: ['../browse-by-metadata-page/browse-by-metadata-page.component.scss'],
28-
templateUrl: '../browse-by-metadata-page/browse-by-metadata-page.component.html'
22+
selector: 'ds-browse-by-date',
23+
styleUrls: ['../browse-by-metadata/browse-by-metadata.component.scss'],
24+
templateUrl: '../browse-by-metadata/browse-by-metadata.component.html',
2925
})
3026
/**
3127
* Component for browsing items by metadata definition of type 'date'
3228
* A metadata definition (a.k.a. browse id) is a short term used to describe one or multiple metadata fields.
3329
* An example would be 'dateissued' for 'dc.date.issued'
3430
*/
3531
@rendersBrowseBy(BrowseByDataType.Date)
36-
export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent implements OnInit {
32+
export class BrowseByDateComponent extends BrowseByMetadataComponent implements OnInit {
3733

3834
/**
3935
* The default metadata keys to use for determining the lower limit of the StartsWith dropdown options
4036
*/
4137
defaultMetadataKeys = ['dc.date.issued'];
4238

43-
public constructor(protected route: ActivatedRoute,
44-
protected browseService: BrowseService,
45-
protected dsoService: DSpaceObjectDataService,
46-
protected router: Router,
47-
protected paginationService: PaginationService,
48-
protected cdRef: ChangeDetectorRef,
49-
@Inject(APP_CONFIG) public appConfig: AppConfig,
50-
public dsoNameService: DSONameService,
39+
public constructor(
40+
protected route: ActivatedRoute,
41+
protected browseService: BrowseService,
42+
protected dsoService: DSpaceObjectDataService,
43+
protected paginationService: PaginationService,
44+
protected router: Router,
45+
@Inject(APP_CONFIG) public appConfig: AppConfig,
46+
public dsoNameService: DSONameService,
47+
protected cdRef: ChangeDetectorRef,
5148
) {
5249
super(route, browseService, dsoService, paginationService, router, appConfig, dsoNameService);
5350
}
@@ -60,19 +57,17 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent imp
6057
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
6158
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
6259
this.subs.push(
63-
observableCombineLatest([this.route.params, this.route.queryParams, this.route.data,
60+
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data,
6461
this.currentPagination$, this.currentSort$]).pipe(
65-
map(([routeParams, queryParams, data, currentPage, currentSort]) => {
66-
return [Object.assign({}, routeParams, queryParams, data), currentPage, currentSort];
62+
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => {
63+
return [Object.assign({}, routeParams, queryParams, data), scope, currentPage, currentSort];
6764
})
68-
).subscribe(([params, currentPage, currentSort]: [Params, PaginationComponentOptions, SortOptions]) => {
65+
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
6966
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;
7067
this.browseId = params.id || this.defaultBrowseId;
7168
this.startsWith = +params.startsWith || params.startsWith;
72-
const searchOptions = browseParamsToOptions(params, currentPage, currentSort, this.browseId, this.fetchThumbnails);
69+
const searchOptions = browseParamsToOptions(params, scope, currentPage, currentSort, this.browseId, this.fetchThumbnails);
7370
this.updatePageWithItems(searchOptions, this.value, undefined);
74-
this.updateParent(params.scope);
75-
this.updateLogo();
7671
this.updateStartsWithOptions(this.browseId, metadataKeys, params.scope);
7772
}));
7873
}
@@ -88,12 +83,21 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent imp
8883
* @param scope The scope under which to fetch the earliest item for
8984
*/
9085
updateStartsWithOptions(definition: string, metadataKeys: string[], scope?: string) {
91-
const firstItemRD = this.browseService.getFirstItemFor(definition, scope, SortDirection.ASC);
92-
const lastItemRD = this.browseService.getFirstItemFor(definition, scope, SortDirection.DESC);
86+
const firstItemRD$: Observable<RemoteData<Item>> = this.browseService.getFirstItemFor(definition, scope, SortDirection.ASC);
87+
const lastItemRD$: Observable<RemoteData<Item>> = this.browseService.getFirstItemFor(definition, scope, SortDirection.DESC);
88+
this.loading$ = observableCombineLatest([
89+
firstItemRD$,
90+
lastItemRD$,
91+
]).pipe(
92+
map(([firstItemRD, lastItemRD]: [RemoteData<Item>, RemoteData<Item>]) => firstItemRD.isLoading || lastItemRD.isLoading)
93+
);
9394
this.subs.push(
94-
observableCombineLatest([firstItemRD, lastItemRD]).subscribe(([firstItem, lastItem]) => {
95-
let lowerLimit: number = this.getLimit(firstItem, metadataKeys, this.appConfig.browseBy.defaultLowerLimit);
96-
let upperLimit: number = this.getLimit(lastItem, metadataKeys, new Date().getUTCFullYear());
95+
observableCombineLatest([
96+
firstItemRD$,
97+
lastItemRD$,
98+
]).subscribe(([firstItemRD, lastItemRD]: [RemoteData<Item>, RemoteData<Item>]) => {
99+
let lowerLimit: number = this.getLimit(firstItemRD, metadataKeys, this.appConfig.browseBy.defaultLowerLimit);
100+
let upperLimit: number = this.getLimit(lastItemRD, metadataKeys, new Date().getUTCFullYear());
97101
const options: number[] = [];
98102
const oneYearBreak: number = Math.floor((upperLimit - this.appConfig.browseBy.oneYearLimit) / 5) * 5;
99103
const fiveYearBreak: number = Math.floor((upperLimit - this.appConfig.browseBy.fiveYearLimit) / 10) * 10;

src/app/browse-by/browse-by-guard.spec.ts

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { first } from 'rxjs/operators';
22
import { BrowseByGuard } from './browse-by-guard';
3-
import { of as observableOf } from 'rxjs';
43
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
54
import { BrowseByDataType } from './browse-by-switcher/browse-by-data-type';
65
import { ValueListBrowseDefinition } from '../core/shared/value-list-browse-definition.model';
7-
import { DSONameServiceMock } from '../shared/mocks/dso-name.service.mock';
8-
import { DSONameService } from '../core/breadcrumbs/dso-name.service';
96
import { RouterStub } from '../shared/testing/router.stub';
107

118
describe('BrowseByGuard', () => {
129
describe('canActivate', () => {
1310
let guard: BrowseByGuard;
14-
let dsoService: any;
1511
let translateService: any;
1612
let browseDefinitionService: any;
1713
let router: any;
@@ -25,10 +21,6 @@ describe('BrowseByGuard', () => {
2521
const browseDefinition = Object.assign(new ValueListBrowseDefinition(), { type: BrowseByDataType.Metadata, metadataKeys: ['dc.contributor'] });
2622

2723
beforeEach(() => {
28-
dsoService = {
29-
findById: (dsoId: string) => observableOf({ payload: { name: name }, hasSucceeded: true })
30-
};
31-
3224
translateService = {
3325
instant: () => field
3426
};
@@ -39,7 +31,7 @@ describe('BrowseByGuard', () => {
3931

4032
router = new RouterStub() as any;
4133

42-
guard = new BrowseByGuard(dsoService, translateService, browseDefinitionService, new DSONameServiceMock() as DSONameService, router);
34+
guard = new BrowseByGuard(translateService, browseDefinitionService, router);
4335
});
4436

4537
it('should return true, and sets up the data correctly, with a scope and value', () => {
@@ -48,6 +40,7 @@ describe('BrowseByGuard', () => {
4840
title: field,
4941
browseDefinition,
5042
},
43+
parent: null,
5144
params: {
5245
id,
5346
},
@@ -64,7 +57,7 @@ describe('BrowseByGuard', () => {
6457
title,
6558
id,
6659
browseDefinition,
67-
collection: name,
60+
scope,
6861
field,
6962
value: '"' + value + '"'
7063
};
@@ -97,7 +90,7 @@ describe('BrowseByGuard', () => {
9790
title,
9891
id,
9992
browseDefinition,
100-
collection: name,
93+
scope,
10194
field,
10295
value: ''
10396
};
@@ -108,12 +101,48 @@ describe('BrowseByGuard', () => {
108101
);
109102
});
110103

104+
it('should return true, and sets up the data correctly using the community/collection page id, with a scope and without value', () => {
105+
const scopedNoValueRoute = {
106+
data: {
107+
title: field,
108+
browseDefinition,
109+
},
110+
parent: {
111+
params: {
112+
id: scope,
113+
},
114+
},
115+
params: {
116+
id,
117+
},
118+
queryParams: {
119+
},
120+
};
121+
122+
guard.canActivate(scopedNoValueRoute as any, undefined).pipe(
123+
first(),
124+
).subscribe((canActivate) => {
125+
const result = {
126+
title,
127+
id,
128+
browseDefinition,
129+
scope,
130+
field,
131+
value: '',
132+
};
133+
expect(scopedNoValueRoute.data).toEqual(result);
134+
expect(router.navigate).not.toHaveBeenCalled();
135+
expect(canActivate).toEqual(true);
136+
});
137+
});
138+
111139
it('should return true, and sets up the data correctly, without a scope and with a value', () => {
112140
const route = {
113141
data: {
114142
title: field,
115143
browseDefinition,
116144
},
145+
parent: null,
117146
params: {
118147
id,
119148
},
@@ -129,7 +158,7 @@ describe('BrowseByGuard', () => {
129158
title,
130159
id,
131160
browseDefinition,
132-
collection: '',
161+
scope: undefined,
133162
field,
134163
value: '"' + value + '"'
135164
};
@@ -147,6 +176,7 @@ describe('BrowseByGuard', () => {
147176
data: {
148177
title: field,
149178
},
179+
parent: null,
150180
params: {
151181
id,
152182
},

0 commit comments

Comments
 (0)