Skip to content

Commit 85e0906

Browse files
committed
[DSC-648] Fix test
1 parent 19e8bd1 commit 85e0906

12 files changed

Lines changed: 84 additions & 100 deletions

File tree

src/app/entity-groups/research-entities/item-list-elements/search-result-list-elements/org-unit/org-unit-search-result-list-element.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class="lead"
88
[innerHTML]="firstMetadataValue('dc.title')"></span>
99
<span class="text-muted">
10-
<span *ngIf="dso.allMetadata(['dc.description']).length > 0"
10+
<span *ngIf="dso.allMetadata(['dc.description.*']).length > 0"
1111
class="item-list-org-unit-description">
1212
<ds-truncatable-part [id]="dso.id" [minLines]="3"><span
1313
[innerHTML]="firstMetadataValue('dc.description.abstract')"></span>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Component } from '@angular/core';
22
import { ViewMode } from '../../../../../core/shared/view-mode.model';
3-
import { listableObjectComponent } from '../../../../../shared/object-collection/shared/listable-object/listable-object.decorator';
4-
import { ItemSearchResultListElementComponent } from '../../../../../shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component';
5-
import { TruncatableService } from '../../../../../shared/truncatable/truncatable.service';
6-
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
3+
import {
4+
listableObjectComponent
5+
} from '../../../../../shared/object-collection/shared/listable-object/listable-object.decorator';
6+
import {
7+
ItemSearchResultListElementComponent
8+
} from '../../../../../shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component';
79

810
@listableObjectComponent('OrgUnitSearchResult', ViewMode.ListElement)
911
@Component({
@@ -15,9 +17,4 @@ import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service
1517
* The component for displaying a list element for an item search result of the type Organisation Unit
1618
*/
1719
export class OrgUnitSearchResultListElementComponent extends ItemSearchResultListElementComponent {
18-
19-
public constructor(protected truncatableService: TruncatableService, protected dsoNameService: DSONameService) {
20-
super(truncatableService, dsoNameService);
21-
}
22-
2320
}

src/app/item-page/item-page.resolver.spec.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ import { ItemDataService } from '../core/data/item-data.service';
33
import { Item } from '../core/shared/item.model';
44
import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
55
import { ItemPageResolver } from './item-page.resolver';
6-
6+
import { TestBed } from '@angular/core/testing';
7+
import { RouterTestingModule } from '@angular/router/testing';
8+
import { Router } from '@angular/router';
79

810
describe('ItemPageResolver', () => {
11+
beforeEach(() => {
12+
TestBed.configureTestingModule({
13+
imports: [RouterTestingModule.withRoutes([{
14+
path: 'entities/:entity-type/:id',
15+
component: {} as any
16+
}])]
17+
});
18+
});
19+
920
describe('resolve', () => {
1021
let resolver: ItemPageResolver;
1122
let itemService: ItemDataService;
@@ -44,21 +55,16 @@ describe('ItemPageResolver', () => {
4455
describe('When item has custom url', () => {
4556

4657
beforeEach(() => {
47-
58+
router = TestBed.inject(Router);
4859
itemService = {
4960
findById: (id: string) => createSuccessfulRemoteDataObject$(item)
5061
} as any;
5162

52-
// (itemService.findById as any).and.returnValue(createSuccessfulRemoteDataObject$(item));
53-
5463
store = jasmine.createSpyObj('store', {
5564
dispatch: {},
5665
});
5766

58-
router = jasmine.createSpyObj('Router', {
59-
navigateByUrl: jasmine.createSpy('navigateByUrl')
60-
});
61-
67+
spyOn(router, 'navigateByUrl');
6268
resolver = new ItemPageResolver(itemService, store, router);
6369
});
6470

@@ -111,7 +117,7 @@ describe('ItemPageResolver', () => {
111117
describe('When item has no custom url', () => {
112118

113119
beforeEach(() => {
114-
120+
router = TestBed.inject(Router);
115121
itemService = {
116122
findById: (id: string) => createSuccessfulRemoteDataObject$(noMetadataItem)
117123
} as any;
@@ -120,10 +126,7 @@ describe('ItemPageResolver', () => {
120126
dispatch: {},
121127
});
122128

123-
router = jasmine.createSpyObj('Router', {
124-
navigateByUrl: jasmine.createSpy('navigateByUrl')
125-
});
126-
129+
spyOn(router, 'navigateByUrl');
127130
resolver = new ItemPageResolver(itemService, store, router);
128131
});
129132

src/app/item-page/item-page.resolver.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class ItemPageResolver extends ItemResolver {
3535
return super.resolve(route, state).pipe(
3636
map((rd: RemoteData<Item>) => {
3737
if (rd.hasSucceeded && hasValue(rd.payload)) {
38-
const itemRoute = getItemPageRoute(rd.payload);
3938
// Check if custom url not empty and if the current id parameter is different from the custom url redirect to custom url
4039
if (hasValue(rd.payload.metadata) && isNotEmpty(rd.payload.metadata['cris.customurl'])) {
4140
if (route.params.id !== rd.payload.metadata['cris.customurl'][0].value) {
@@ -45,11 +44,11 @@ export class ItemPageResolver extends ItemResolver {
4544
} else {
4645
const thisRoute = state.url;
4746

48-
// Angular uses a custom function for encodeURIComponent, (e.g. it doesn't encode commas
49-
// or semicolons) and thisRoute has been encoded with that function. If we want to compare
50-
// it with itemRoute, we have to run itemRoute through Angular's version as well to ensure
51-
// the same characters are encoded the same way.
52-
const itemRoute = this.router.parseUrl(getItemPageRoute(rd.payload)).toString();
47+
// Angular uses a custom function for encodeURIComponent, (e.g. it doesn't encode commas
48+
// or semicolons) and thisRoute has been encoded with that function. If we want to compare
49+
// it with itemRoute, we have to run itemRoute through Angular's version as well to ensure
50+
// the same characters are encoded the same way.
51+
const itemRoute = this.router.parseUrl(getItemPageRoute(rd.payload)).toString();
5352

5453
if (!thisRoute.startsWith(itemRoute)) {
5554
const itemId = rd.payload.uuid;

src/app/shared/context-menu/orcid-view-page/orcid-view-page-menu.component.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
77
import { TranslateModule } from '@ngx-translate/core';
88

99
import { OrcidViewPageMenuComponent } from './orcid-view-page-menu.component';
10-
import { DsoPageOrcidButtonComponent } from '../../dso-page/dso-page-orcid-button/dso-page-orcid-button.component';
1110
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
1211
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
1312
import { Item } from '../../../core/shared/item.model';
1413
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
1514
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
1615

1716
describe('OrcidViewPageMenuComponent', () => {
18-
let component: DsoPageOrcidButtonComponent;
19-
let fixture: ComponentFixture<DsoPageOrcidButtonComponent>;
17+
let component: OrcidViewPageMenuComponent;
18+
let fixture: ComponentFixture<OrcidViewPageMenuComponent>;
2019

2120
let authorizationService: AuthorizationDataService;
2221
let dso: DSpaceObject;
@@ -32,7 +31,7 @@ describe('OrcidViewPageMenuComponent', () => {
3231
isAuthorized: observableOf(true)
3332
});
3433
TestBed.configureTestingModule({
35-
declarations: [DsoPageOrcidButtonComponent],
34+
declarations: [OrcidViewPageMenuComponent],
3635
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NgbModule],
3736
providers: [
3837
{ provide: 'contextMenuObjectProvider', useValue: dso },
@@ -43,7 +42,7 @@ describe('OrcidViewPageMenuComponent', () => {
4342
}));
4443

4544
beforeEach(() => {
46-
fixture = TestBed.createComponent(DsoPageOrcidButtonComponent);
45+
fixture = TestBed.createComponent(OrcidViewPageMenuComponent);
4746
component = fixture.componentInstance;
4847
fixture.detectChanges();
4948
});

src/app/shared/explore/section-component/facet-section/facet-section.component.spec.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { CommonModule } from '@angular/common';
22
import { NO_ERRORS_SCHEMA } from '@angular/core';
3-
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
4-
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
3+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
54
import { BrowserModule, By } from '@angular/platform-browser';
65
import { RouterTestingModule } from '@angular/router/testing';
7-
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
86
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
97
import { Observable } from 'rxjs';
108
import { RemoteData } from '../../../../core/data/remote-data';
@@ -15,12 +13,10 @@ import { FacetValue } from '../../../search/models/facet-value.model';
1513
import { FilterType } from '../../../search/models/filter-type.model';
1614
import { SearchFilterConfig } from '../../../search/models/search-filter-config.model';
1715
import { FacetSectionComponent } from './facet-section.component';
18-
import {SEARCH_CONFIG_SERVICE} from '../../../../my-dspace-page/my-dspace-page.component';
19-
import {SearchConfigurationServiceStub} from '../../../testing/search-configuration-service.stub';
20-
import {StoreModule} from '@ngrx/store';
21-
import {authReducer} from '../../../../core/auth/auth.reducer';
22-
import {storeModuleConfig} from '../../../../app.reducer';
23-
import {isNotNull} from '../../../empty.util';
16+
import { StoreModule } from '@ngrx/store';
17+
import { authReducer } from '../../../../core/auth/auth.reducer';
18+
import { storeModuleConfig } from '../../../../app.reducer';
19+
import { isNotNull } from '../../../empty.util';
2420

2521
describe('FacetSectionComponent', () => {
2622
let component: FacetSectionComponent;
@@ -113,7 +109,7 @@ describe('FacetSectionComponent', () => {
113109
values: [pieChartFacetValue]
114110
}
115111
});
116-
beforeEach(async(() => {
112+
beforeEach(waitForAsync(() => {
117113

118114
searchServiceStub = {
119115
searchFacets(scope?: string, configurationName?: string): Observable<RemoteData<SearchFilterConfig[]>> {
@@ -125,7 +121,9 @@ describe('FacetSectionComponent', () => {
125121
};
126122

127123
TestBed.configureTestingModule({
128-
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule, RouterTestingModule,
124+
imports: [CommonModule,
125+
BrowserModule,
126+
RouterTestingModule,
129127
StoreModule.forRoot({ auth: authReducer }, storeModuleConfig),
130128
TranslateModule.forRoot({
131129
loader: {
@@ -135,9 +133,9 @@ describe('FacetSectionComponent', () => {
135133
}),
136134
],
137135
declarations: [FacetSectionComponent],
138-
providers: [FacetSectionComponent,
139-
{ provide: SearchService, useValue: searchServiceStub },
140-
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }],
136+
providers: [
137+
{ provide: SearchService, useValue: searchServiceStub }
138+
],
141139
schemas: [NO_ERRORS_SCHEMA]
142140
}).compileComponents();
143141

@@ -158,9 +156,9 @@ describe('FacetSectionComponent', () => {
158156
fixture.detectChanges();
159157
});
160158

161-
it('should create FacetSectionComponent', inject([FacetSectionComponent], (comp: FacetSectionComponent) => {
162-
expect(comp).toBeDefined();
163-
}));
159+
it('should create FacetSectionComponent', () => {
160+
expect(component).toBeDefined();
161+
});
164162

165163
it('should create a facet section foreach not empty filter configs', () => {
166164
// graph facets control

src/app/shared/explore/section-component/facet-section/facet-section.component.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Inject, Input, OnInit } from '@angular/core';
1+
import { Component, Input, OnInit } from '@angular/core';
22

33
import { BehaviorSubject } from 'rxjs';
44

@@ -9,21 +9,13 @@ import { SearchFilterConfig } from '../../../search/models/search-filter-config.
99
import { FilterType } from '../../../search/models/filter-type.model';
1010
import { FacetValue } from '../../../search/models/facet-value.model';
1111
import { getFacetValueForTypeAndLabel } from '../../../search/search.utils';
12-
import { SEARCH_CONFIG_SERVICE } from '../../../../my-dspace-page/my-dspace-page.component';
13-
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
1412

1513
/**
1614
* Component representing the Facet component section.
1715
*/
1816
@Component({
1917
selector: 'ds-facet-section',
2018
templateUrl: './facet-section.component.html',
21-
providers: [
22-
{
23-
provide: SEARCH_CONFIG_SERVICE,
24-
useClass: SearchConfigurationService
25-
}
26-
]
2719
})
2820
export class FacetSectionComponent implements OnInit {
2921

@@ -38,9 +30,7 @@ export class FacetSectionComponent implements OnInit {
3830
facets: SearchFilterConfig[] = [];
3931
facets$ = new BehaviorSubject(this.facets);
4032

41-
constructor(public searchService: SearchService,
42-
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
43-
) {
33+
constructor(public searchService: SearchService) {
4434

4535
}
4636

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import {inject, TestBed} from '@angular/core/testing';
1+
import { inject, TestBed } from '@angular/core/testing';
22

33
import {
4+
DISABLED_MATCHER_PROVIDER,
45
DynamicFormControlRelation,
56
DynamicFormRelationService,
7+
HIDDEN_MATCHER,
8+
HIDDEN_MATCHER_PROVIDER,
69
MATCH_VISIBLE,
710
OR_OPERATOR,
8-
HIDDEN_MATCHER,
9-
HIDDEN_MATCHER_PROVIDER, REQUIRED_MATCHER_PROVIDER, DISABLED_MATCHER_PROVIDER,
11+
REQUIRED_MATCHER_PROVIDER,
1012
} from '@ng-dynamic-forms/core';
1113

12-
import {
13-
mockInputWithTypeBindModel, MockRelationModel, mockDcTypeInputModel
14-
} from '../../../mocks/form-models.mock';
15-
import {DsDynamicTypeBindRelationService} from './ds-dynamic-type-bind-relation.service';
16-
import {FormFieldMetadataValueObject} from '../models/form-field-metadata-value.model';
17-
import {FormControl, ReactiveFormsModule} from '@angular/forms';
18-
import {FormBuilderService} from '../form-builder.service';
19-
import {getMockFormBuilderService} from '../../../mocks/form-builder-service.mock';
20-
import {Injector} from '@angular/core';
14+
import { mockInputWithTypeBindModel, MockRelationModel } from '../../../mocks/form-models.mock';
15+
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
16+
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
17+
import { FormControl, ReactiveFormsModule } from '@angular/forms';
18+
import { FormBuilderService } from '../form-builder.service';
19+
import { getMockFormBuilderService } from '../../../mocks/form-builder-service.mock';
20+
import { Injector } from '@angular/core';
2121

2222
describe('DSDynamicTypeBindRelationService test suite', () => {
2323
let service: DsDynamicTypeBindRelationService;
@@ -47,14 +47,14 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
4747
describe('Test getTypeBindValue method', () => {
4848
it('Should get type bind "boundType" from the given metadata object value', () => {
4949
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
50-
'boundType', null, null, 'Bound Type'
50+
'boundType', null, null, null,'Bound Type'
5151
);
5252
const bindType = service.getTypeBindValue(mockMetadataValueObject);
5353
expect(bindType).toBe('boundType');
5454
});
5555
it('Should get type authority key "bound-auth-key" from the given metadata object value', () => {
5656
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
57-
'boundType', null, 'bound-auth-key', 'Bound Type'
57+
'boundType', null, null, 'bound-auth-key', 'Bound Type'
5858
);
5959
const bindType = service.getTypeBindValue(mockMetadataValueObject);
6060
expect(bindType).toBe('bound-auth-key');

src/app/shared/search/search.utils.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { SearchFilterConfig } from './models/search-filter-config.model';
33
import {
44
addOperatorToFilterValue,
55
escapeRegExp,
6-
getFacetValueForType, getFacetValueForTypeAndLabel,
6+
getFacetValueForType,
7+
getFacetValueForTypeAndLabel,
78
stripOperatorFromFilterValue
89
} from './search.utils';
910

@@ -56,7 +57,7 @@ describe('Search Utils', () => {
5657

5758
beforeEach(() => {
5859
facetValueWithSearchHref = Object.assign(new FacetValue(), {
59-
label: 'Facet Label',
60+
label: 'Facet Label with search href',
6061
_links: {
6162
search: {
6263
href: 'rest/api/search?f.otherFacet=Other facet value,operator&f.facetName=Facet Label with search href,operator'
@@ -72,7 +73,7 @@ describe('Search Utils', () => {
7273
});
7374

7475
it('should retrieve the correct value from the search href', () => {
75-
expect(getFacetValueForTypeAndLabel(facetValueWithSearchHref, searchFilterConfig)).toEqual('Facet Label with search href,operator');
76+
expect(getFacetValueForTypeAndLabel(facetValueWithSearchHref, searchFilterConfig)).toEqual('Facet Label with search href,equals');
7677
});
7778

7879
it('should return the facet value with an equals operator by default', () => {

src/app/shared/search/search.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function getFacetValueForTypeAndLabel(facetValue: FacetValue, searchFilte
2323
}
2424

2525
function _createValue(paramName: string, facetValueLinks, value, authorityKey) {
26-
const regex = new RegExp(`[?|&]${escapeRegExp(paramName)}=(${escapeRegExp(value)}[^&]*)`, 'g');
26+
const regex = new RegExp(`[?|&]${escapeRegExp(encodeURIComponent(paramName))}=(${escapeRegExp(encodeURIComponent(value))}[^&]*)`, 'g');
2727
if (isNotEmpty(facetValueLinks)) {
2828
const values = regex.exec(facetValueLinks.search.href);
2929
if (isNotEmpty(values)) {

0 commit comments

Comments
 (0)