fixed some tests

This commit is contained in:
lotte
2019-11-25 11:09:44 +01:00
parent 3487231af1
commit cbfc396b29
12 changed files with 162 additions and 54 deletions

View File

@@ -15,7 +15,11 @@ module.exports = function (config) {
}; };
var configuration = { var configuration = {
client: {
jasmine: {
random: false
}
},
// base path that will be used to resolve all patterns (e.g. files, exclude) // base path that will be used to resolve all patterns (e.g. files, exclude)
basePath: '', basePath: '',

View File

@@ -76,7 +76,7 @@ const ENTITY_IMPORTS = [
IMPORTS.push( IMPORTS.push(
StoreDevtoolsModule.instrument({ StoreDevtoolsModule.instrument({
maxAge: 100, maxAge: 1000,
logOnly: ENV_CONFIG.production, logOnly: ENV_CONFIG.production,
}) })
); );

View File

@@ -53,7 +53,8 @@ class DummyChangeAnalyzer implements ChangeAnalyzer<NormalizedTestObject> {
} }
} }
fdescribe('DataService', () => {
describe('DataService', () => {
let service: TestService; let service: TestService;
let options: FindAllOptions; let options: FindAllOptions;
const requestService = {generateRequestId: () => uuidv4()} as RequestService; const requestService = {generateRequestId: () => uuidv4()} as RequestService;
@@ -89,6 +90,7 @@ fdescribe('DataService', () => {
comparator, comparator,
); );
} }
service = initTestService(); service = initTestService();
describe('getFindAllHref', () => { describe('getFindAllHref', () => {
@@ -190,7 +192,7 @@ fdescribe('DataService', () => {
dso2.self = selfLink; dso2.self = selfLink;
dso2.metadata = [{ key: 'dc.title', value: name2 }]; dso2.metadata = [{ key: 'dc.title', value: name2 }];
spyOn(service, 'findById').and.returnValues(observableOf(dso)); spyOn(service, 'findByHref').and.returnValues(observableOf(dso));
spyOn(objectCache, 'getObjectBySelfLink').and.returnValues(observableOf(dso)); spyOn(objectCache, 'getObjectBySelfLink').and.returnValues(observableOf(dso));
spyOn(objectCache, 'addPatch'); spyOn(objectCache, 'addPatch');
}); });

View File

@@ -3,7 +3,7 @@ import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { hasValue, hasValueOperator, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util'; import { hasValue, hasValueOperator, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util';
import { distinctUntilChanged, filter, map, mergeMap, startWith, switchMap, take, tap } from 'rxjs/operators'; import { distinctUntilChanged, filter, map, mergeMap, skipWhile, startWith, switchMap, take, tap } from 'rxjs/operators';
import { configureRequest, getRemoteDataPayload, getResponseFromEntry, getSucceededRemoteData } from '../shared/operators'; import { configureRequest, getRemoteDataPayload, getResponseFromEntry, getSucceededRemoteData } from '../shared/operators';
import { DeleteRequest, FindAllOptions, PostRequest, RestRequest } from './request.models'; import { DeleteRequest, FindAllOptions, PostRequest, RestRequest } from './request.models';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
@@ -137,7 +137,7 @@ export class RelationshipService extends DataService<Relationship> {
this.requestService.hasByHrefObservable(item.self) this.requestService.hasByHrefObservable(item.self)
).pipe( ).pipe(
filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC), filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC),
take(1), tap(t => console.log(t)),
switchMap(() => this.itemService.findByHref(item.self).pipe(take(1))) switchMap(() => this.itemService.findByHref(item.self).pipe(take(1)))
).subscribe(); ).subscribe();
} }
@@ -318,8 +318,6 @@ export class RelationshipService extends DataService<Relationship> {
}) })
) )
), ),
tap(() => this.removeRelationshipItemsFromCache(item1)),
tap(() => this.removeRelationshipItemsFromCache(item2)),
switchMap((relationshipAndType: { relation: Relationship, type: RelationshipType }) => { switchMap((relationshipAndType: { relation: Relationship, type: RelationshipType }) => {
const { relation, type } = relationshipAndType; const { relation, type } = relationshipAndType;
let updatedRelationship; let updatedRelationship;
@@ -329,7 +327,16 @@ export class RelationshipService extends DataService<Relationship> {
updatedRelationship = Object.assign(new Relationship(), relation, { leftwardValue: nameVariant }); updatedRelationship = Object.assign(new Relationship(), relation, { leftwardValue: nameVariant });
} }
return this.update(updatedRelationship); return this.update(updatedRelationship);
}) }),
// skipWhile((relationshipRD: RemoteData<Relationship>) => !relationshipRD.isSuccessful)
tap((relationshipRD: RemoteData<Relationship>) => {
console.log(relationshipRD.payload);
if (relationshipRD.hasSucceeded) {
this.removeRelationshipItemsFromCache(item1);
this.removeRelationshipItemsFromCache(item2);
}
}),
) )
} }
} }

View File

@@ -1,6 +1,8 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NameVariantModalComponent } from './name-variant-modal.component'; import { NameVariantModalComponent } from './name-variant-modal.component';
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
describe('NameVariantModalComponent', () => { describe('NameVariantModalComponent', () => {
let component: NameVariantModalComponent; let component: NameVariantModalComponent;
@@ -8,9 +10,11 @@ describe('NameVariantModalComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ NameVariantModalComponent ] declarations: [NameVariantModalComponent],
imports: [NgbModule.forRoot(), TranslateModule.forRoot()],
providers: [NgbActiveModal]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@@ -9,8 +9,7 @@ import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
export class NameVariantModalComponent implements OnInit { export class NameVariantModalComponent implements OnInit {
@Input() value: string; @Input() value: string;
constructor(private modalService: NgbModal, constructor(public modal: NgbActiveModal) {
public modal: NgbActiveModal) {
} }
ngOnInit() { ngOnInit() {

View File

@@ -14,7 +14,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ItemDataService } from '../../../../../core/data/item-data.service'; import { ItemDataService } from '../../../../../core/data/item-data.service';
import { SelectableListService } from '../../../../../shared/object-list/selectable-list/selectable-list.service'; import { SelectableListService } from '../../../../../shared/object-list/selectable-list/selectable-list.service';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '../../../../../app.reducer'; import { createSuccessfulRemoteDataObject$ } from '../../../../../shared/testing/utils';
let personListElementComponent: PersonSearchResultListSubmissionElementComponent; let personListElementComponent: PersonSearchResultListSubmissionElementComponent;
let fixture: ComponentFixture<PersonSearchResultListSubmissionElementComponent>; let fixture: ComponentFixture<PersonSearchResultListSubmissionElementComponent>;
@@ -23,7 +23,7 @@ const mockItemWithMetadata: ItemSearchResult = Object.assign(
new ItemSearchResult(), new ItemSearchResult(),
{ {
indexableObject: Object.assign(new Item(), { indexableObject: Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: createSuccessfulRemoteDataObject$([]),
metadata: { metadata: {
'dc.title': [ 'dc.title': [
{ {
@@ -44,7 +44,7 @@ const mockItemWithoutMetadata: ItemSearchResult = Object.assign(
new ItemSearchResult(), new ItemSearchResult(),
{ {
indexableObject: Object.assign(new Item(), { indexableObject: Object.assign(new Item(), {
bitstreams: observableOf({}), bitstreams: createSuccessfulRemoteDataObject$([]),
metadata: { metadata: {
'dc.title': [ 'dc.title': [
{ {
@@ -61,7 +61,7 @@ const mockRelationshipService = {
getNameVariant: () => observableOf(nameVariant) getNameVariant: () => observableOf(nameVariant)
}; };
describe('PersonSearchResultListElementComponent', () => { describe('PersonSearchResultListElementSubmissionComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [PersonSearchResultListSubmissionElementComponent, TruncatePipe], declarations: [PersonSearchResultListSubmissionElementComponent, TruncatePipe],

View File

@@ -1,5 +1,5 @@
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA, DebugElement, SimpleChange } from '@angular/core'; import { CUSTOM_ELEMENTS_SCHEMA, DebugElement, NgZone, SimpleChange } from '@angular/core';
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing'; import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
@@ -65,6 +65,12 @@ import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic
import { RelationshipService } from '../../../../core/data/relationship.service'; import { RelationshipService } from '../../../../core/data/relationship.service';
import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service'; import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service';
import { ItemDataService } from '../../../../core/data/item-data.service'; import { ItemDataService } from '../../../../core/data/item-data.service';
import { Store } from '@ngrx/store';
import { SubmissionObjectDataService } from '../../../../core/submission/submission-object-data.service';
import { Item } from '../../../../core/shared/item.model';
import { WorkspaceItem } from '../../../../core/submission/models/workspaceitem.model';
import { of as observableOf } from 'rxjs';
import { createSuccessfulRemoteDataObject } from '../../../testing/utils';
describe('DsDynamicFormControlContainerComponent test suite', () => { describe('DsDynamicFormControlContainerComponent test suite', () => {
@@ -103,7 +109,7 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
repeatable: false, repeatable: false,
submissionId: '1234' submissionId: '1234'
}), }),
new DynamicTagModel({ id: 'tag', metadataFields: [], repeatable: false, submissionId: '1234'}), new DynamicTagModel({ id: 'tag', metadataFields: [], repeatable: false, submissionId: '1234' }),
new DynamicListCheckboxGroupModel({ new DynamicListCheckboxGroupModel({
id: 'checkboxList', id: 'checkboxList',
authorityOptions: authorityOptions, authorityOptions: authorityOptions,
@@ -126,7 +132,7 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
repeatable: false, repeatable: false,
metadataFields: [] metadataFields: []
}), }),
new DynamicDsDatePickerModel({ id: 'datepicker'}), new DynamicDsDatePickerModel({ id: 'datepicker' }),
new DynamicLookupModel({ id: 'lookup', metadataFields: [], repeatable: false, submissionId: '1234' }), new DynamicLookupModel({ id: 'lookup', metadataFields: [], repeatable: false, submissionId: '1234' }),
new DynamicLookupNameModel({ id: 'lookupName', metadataFields: [], repeatable: false, submissionId: '1234' }), new DynamicLookupNameModel({ id: 'lookupName', metadataFields: [], repeatable: false, submissionId: '1234' }),
new DynamicQualdropModel({ id: 'combobox', readOnly: false, required: false }) new DynamicQualdropModel({ id: 'combobox', readOnly: false, required: false })
@@ -137,7 +143,9 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
let component: DsDynamicFormControlContainerComponent; let component: DsDynamicFormControlContainerComponent;
let debugElement: DebugElement; let debugElement: DebugElement;
let testElement: DebugElement; let testElement: DebugElement;
const testItem: Item = new Item();
const testWSI: WorkspaceItem = new WorkspaceItem();
testWSI.item = observableOf(createSuccessfulRemoteDataObject(testItem));
beforeEach(async(() => { beforeEach(async(() => {
TestBed.overrideModule(BrowserDynamicTestingModule, { TestBed.overrideModule(BrowserDynamicTestingModule, {
@@ -156,20 +164,33 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
DynamicFormsCoreModule.forRoot(), DynamicFormsCoreModule.forRoot(),
SharedModule, SharedModule,
TranslateModule.forRoot(), TranslateModule.forRoot(),
TextMaskModule TextMaskModule,
], ],
providers: [ providers: [
DsDynamicFormControlContainerComponent, DsDynamicFormControlContainerComponent,
DynamicFormService, DynamicFormService,
{ provide: RelationshipService, useValue: {} }, { provide: RelationshipService, useValue: {} },
{ provide: SelectableListService, useValue: {} }, { provide: SelectableListService, useValue: {} },
{ provide: ItemDataService, useValue: {} } { provide: ItemDataService, useValue: {} },
{ provide: Store, useValue: {} },
{ provide: RelationshipService, useValue: {} },
{ provide: SelectableListService, useValue: {} },
{
provide: SubmissionObjectDataService,
useValue: {
findById: () => observableOf(createSuccessfulRemoteDataObject(testWSI))
}
},
{ provide: NgZone, useValue: new NgZone({}) }
], ],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents().then(() => { }).compileComponents().then(() => {
fixture = TestBed.createComponent(DsDynamicFormControlContainerComponent); fixture = TestBed.createComponent(DsDynamicFormControlContainerComponent);
const ngZone = TestBed.get(NgZone);
spyOn(ngZone, 'runOutsideAngular').and.callFake((fn: Function) => fn());
component = fixture.componentInstance; component = fixture.componentInstance;
debugElement = fixture.debugElement; debugElement = fixture.debugElement;
}); });

View File

@@ -71,10 +71,8 @@ import { DsDynamicRelationGroupComponent } from './models/relation-group/dynamic
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './models/relation-group/dynamic-relation-group.model'; import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './models/relation-group/dynamic-relation-group.model';
import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component'; import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component';
import { map, switchMap, take, tap } from 'rxjs/operators'; import { map, switchMap, take, tap } from 'rxjs/operators';
import { zip as observableZip } from 'rxjs'; import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
import { combineLatest as observableCombineLatest } from 'rxjs';
import { SelectableListState } from '../../../object-list/selectable-list/selectable-list.reducer'; import { SelectableListState } from '../../../object-list/selectable-list/selectable-list.reducer';
import { Observable } from 'rxjs';
import { SearchResult } from '../../../search/search-result.model'; import { SearchResult } from '../../../search/search-result.model';
import { DSpaceObject } from '../../../../core/shared/dspace-object.model'; import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
@@ -96,7 +94,6 @@ import { PaginatedList } from '../../../../core/data/paginated-list';
import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model';
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model'; import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
import { MetadataValue } from '../../../../core/shared/metadata.models'; import { MetadataValue } from '../../../../core/shared/metadata.models';
import * as uuidv4 from 'uuid/v4';
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null { export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
switch (model.type) { switch (model.type) {
@@ -208,7 +205,6 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
protected validationService: DynamicFormValidationService, protected validationService: DynamicFormValidationService,
protected translateService: TranslateService, protected translateService: TranslateService,
private modalService: NgbModal, private modalService: NgbModal,
private relationService: RelationshipService,
private selectableListService: SelectableListService, private selectableListService: SelectableListService,
private itemService: ItemDataService, private itemService: ItemDataService,
private relationshipService: RelationshipService, private relationshipService: RelationshipService,
@@ -220,7 +216,6 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
} }
ngOnInit(): void { ngOnInit(): void {
const q = uuidv4();
this.hasRelationLookup = hasValue(this.model.relationship); this.hasRelationLookup = hasValue(this.model.relationship);
if (this.hasRelationLookup) { if (this.hasRelationLookup) {
this.listId = 'list-' + this.model.relationship.relationshipType; this.listId = 'list-' + this.model.relationship.relationshipType;
@@ -231,7 +226,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload()))); switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
this.item$.pipe( this.item$.pipe(
take(1), take(1),
switchMap((item: Item) => this.relationService.getRelatedItemsByLabel(item, this.model.relationship.relationshipType)), switchMap((item: Item) => this.relationshipService.getRelatedItemsByLabel(item, this.model.relationship.relationshipType)),
map((items: RemoteData<PaginatedList<Item>>) => items.payload.page.map((item) => Object.assign(new ItemSearchResult(), { indexableObject: item }))), map((items: RemoteData<PaginatedList<Item>>) => items.payload.page.map((item) => Object.assign(new ItemSearchResult(), { indexableObject: item }))),
).subscribe((relatedItems: SearchResult<Item>[]) => this.selectableListService.select(this.listId, relatedItems)); ).subscribe((relatedItems: SearchResult<Item>[]) => this.selectableListService.select(this.listId, relatedItems));

View File

@@ -9,6 +9,7 @@ import { hasNoValue, hasValue, hasValueOperator } from '../../../../empty.util';
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model'; import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model'; import { RelationshipType } from '../../../../../core/shared/item-relationships/relationship-type.model';
import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service'; import { RelationshipTypeService } from '../../../../../core/data/relationship-type.service';
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../../core/shared/operators';
const DEBOUNCE_TIME = 5000; const DEBOUNCE_TIME = 5000;
@@ -85,7 +86,7 @@ export class RelationshipEffects {
this.nameVariantUpdates[identifier] = nameVariant; this.nameVariantUpdates[identifier] = nameVariant;
} else { } else {
this.relationshipService.updateNameVariant(item1, item2, relationshipType, nameVariant) this.relationshipService.updateNameVariant(item1, item2, relationshipType, nameVariant)
.pipe(take(1)) .pipe()
.subscribe(); .subscribe();
} }
} }

View File

@@ -0,0 +1,89 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { of as observableOf } from 'rxjs';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { ActivatedRoute } from '@angular/router';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser';
import { first, take } from 'rxjs/operators';
import { PageSizeSelectorComponent } from './page-size-selector.component';
import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
import { EnumKeysPipe } from '../utils/enum-keys-pipe';
import { VarDirective } from '../utils/var.directive';
import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
describe('PageSizeSelectorComponent', () => {
let comp: PageSizeSelectorComponent;
let fixture: ComponentFixture<PageSizeSelectorComponent>;
const pagination: PaginationComponentOptions = new PaginationComponentOptions();
pagination.id = 'search-results-pagination';
pagination.currentPage = 1;
pagination.pageSize = 10;
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const paginatedSearchOptions = {
query: queryParam,
scope: scopeParam,
pagination,
sort
};
const activatedRouteStub = {
queryParams: observableOf({
query: queryParam,
scope: scopeParam
})
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [PageSizeSelectorComponent, EnumKeysPipe, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{
provide: SEARCH_CONFIG_SERVICE,
useValue: {
paginatedSearchOptions: observableOf(paginatedSearchOptions),
}
},
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PageSizeSelectorComponent);
comp = fixture.componentInstance;
// SearchPageComponent test instance
fixture.detectChanges();
});
it('it should show the size settings with the respective selectable options', (done) => {
(comp as any).paginationOptions$.pipe(first()).subscribe((options) => {
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings'));
expect(pageSizeSetting).toBeDefined();
const childElements = pageSizeSetting.query(By.css('.form-control')).children;
expect(childElements.length).toEqual(options.pageSizeOptions.length);
done()
}
)
});
it('should have the proper rpp value selected by default', (done) => {
(comp as any).paginationOptions$.pipe(take(1)).subscribe((options) => {
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings'));
const childElementToBeSelected = pageSizeSetting.query(By.css('.form-control option[value="10"][selected="selected"]'));
expect(childElementToBeSelected).toBeDefined();
done();
});
});
});

View File

@@ -12,7 +12,6 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EnumKeysPipe } from '../../utils/enum-keys-pipe'; import { EnumKeysPipe } from '../../utils/enum-keys-pipe';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { SearchFilterService } from '../../../core/shared/search/search-filter.service'; import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
import { hot } from 'jasmine-marbles';
import { VarDirective } from '../../utils/var.directive'; import { VarDirective } from '../../utils/var.directive';
import { first } from 'rxjs/operators'; import { first } from 'rxjs/operators';
import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component'; import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component';
@@ -75,12 +74,8 @@ describe('SearchSettingsComponent', () => {
{ {
provide: SEARCH_CONFIG_SERVICE, provide: SEARCH_CONFIG_SERVICE,
useValue: { useValue: {
paginatedSearchOptions: hot('a', { paginatedSearchOptions: observableOf(paginatedSearchOptions),
a: paginatedSearchOptions getCurrentScope: observableOf('test-id')
}),
getCurrentScope: hot('a', {
a: 'test-id'
}),
} }
}, },
], ],
@@ -100,43 +95,34 @@ describe('SearchSettingsComponent', () => {
}); });
it('it should show the order settings with the respective selectable options', () => { it('it should show the order settings with the respective selectable options', (done) => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => { (comp as any).searchOptions$.pipe(first()).subscribe((options) => {
fixture.detectChanges(); fixture.detectChanges();
const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings')); const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings'));
expect(orderSetting).toBeDefined(); expect(orderSetting).toBeDefined();
const childElements = orderSetting.query(By.css('.form-control')).children; const childElements = orderSetting.query(By.css('.form-control')).children;
expect(childElements.length).toEqual(comp.searchOptionPossibilities.length); expect(childElements.length).toEqual(comp.searchOptionPossibilities.length);
done();
}); });
}); });
it('it should show the size settings with the respective selectable options', () => { it('it should show the size settings', (done) => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => { (comp as any).searchOptions$.pipe(first()).subscribe((options) => {
fixture.detectChanges(); fixture.detectChanges();
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings')); const pageSizeSetting = fixture.debugElement.query(By.css('page-size-settings'));
expect(pageSizeSetting).toBeDefined(); expect(pageSizeSetting).toBeDefined();
const childElements = pageSizeSetting.query(By.css('.form-control')).children; done();
expect(childElements.length).toEqual(options.pagination.pageSizeOptions.length);
} }
) )
}); });
it('should have the proper order value selected by default', () => { it('should have the proper order value selected by default', (done) => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => { (comp as any).searchOptions$.pipe(first()).subscribe((options) => {
fixture.detectChanges(); fixture.detectChanges();
const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings')); const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings'));
const childElementToBeSelected = orderSetting.query(By.css('.form-control option[value="0"][selected="selected"]')); const childElementToBeSelected = orderSetting.query(By.css('.form-control option[value="0"][selected="selected"]'));
expect(childElementToBeSelected).toBeDefined(); expect(childElementToBeSelected).toBeDefined();
done();
}); });
}); });
it('should have the proper rpp value selected by default', () => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => {
fixture.detectChanges();
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings'));
const childElementToBeSelected = pageSizeSetting.query(By.css('.form-control option[value="10"][selected="selected"]'));
expect(childElementToBeSelected).toBeDefined();
});
});
}); });