Skip to content
Snippets Groups Projects
Commit 78567383 authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

56434: FilteredSearchPageComponent tests

parent a66007c1
No related branches found
No related tags found
No related merge requests found
import { FilteredSearchPageComponent } from './filtered-search-page.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { configureSearchComponentTestingModule } from './search-page.component.spec';
import { SearchConfigurationService } from './search-service/search-configuration.service';
describe('FilteredSearchPageComponent', () => {
let comp: FilteredSearchPageComponent;
let fixture: ComponentFixture<FilteredSearchPageComponent>;
let searchConfigService: SearchConfigurationService;
beforeEach(async(() => {
configureSearchComponentTestingModule(FilteredSearchPageComponent);
}));
beforeEach(() => {
fixture = TestBed.createComponent(FilteredSearchPageComponent);
comp = fixture.componentInstance;
searchConfigService = (comp as any).searchConfigService;
fixture.detectChanges();
});
describe('when fixedFilterQuery is defined', () => {
const fixedFilterQuery = 'fixedFilterQuery';
beforeEach(() => {
spyOn(searchConfigService, 'updateFixedFilter').and.callThrough();
comp.fixedFilterQuery = fixedFilterQuery;
comp.ngOnInit();
fixture.detectChanges();
});
it('should update the paginated search options', () => {
expect(searchConfigService.updateFixedFilter).toHaveBeenCalledWith(fixedFilterQuery);
});
});
});
import { CommunityDataService } from '../core/data/community-data.service';
import { HostWindowService } from '../shared/host-window.service';
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
import { SearchService } from './search-service/search.service';
import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
import { SearchPageComponent } from './search-page.component';
import { ChangeDetectionStrategy, Component, Injectable, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { pushInOut } from '../shared/animations/push';
import { RouteService } from '../shared/services/route.service';
import { SearchConfigurationService } from './search-service/search-configuration.service';
import { switchMap, tap } from 'rxjs/operators';
import { getSucceededRemoteData } from '../core/shared/operators';
import { Observable } from 'rxjs/Observable';
import { PaginatedSearchOptions } from './paginated-search-options.model';
import { isNotEmpty } from '../shared/empty.util';
/**
* This component renders a simple item page.
......
......@@ -23,100 +23,110 @@ import { SearchConfigurationService } from './search-service/search-configuratio
import { RemoteData } from '../core/data/remote-data';
import { RouteService } from '../shared/services/route.service';
describe('SearchPageComponent', () => {
let comp: SearchPageComponent;
let fixture: ComponentFixture<SearchPageComponent>;
let searchServiceObject: SearchService;
const store: Store<SearchPageComponent> = jasmine.createSpyObj('store', {
/* tslint:disable:no-empty */
dispatch: {},
/* tslint:enable:no-empty */
select: Observable.of(true)
});
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 mockResults = Observable.of(new RemoteData(false, false, true, null, ['test', 'data']));
const searchServiceStub = jasmine.createSpyObj('SearchService', {
search: mockResults,
getSearchLink: '/search',
getScopes: Observable.of(['test-scope'])
});
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const paginatedSearchOptions = {
let comp: SearchPageComponent;
let fixture: ComponentFixture<SearchPageComponent>;
let searchServiceObject: SearchService;
const store: Store<SearchPageComponent> = jasmine.createSpyObj('store', {
/* tslint:disable:no-empty */
dispatch: {},
/* tslint:enable:no-empty */
select: Observable.of(true)
});
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 mockResults = Observable.of(new RemoteData(false, false, true, null, ['test', 'data']));
const searchServiceStub = jasmine.createSpyObj('SearchService', {
search: mockResults,
getSearchLink: '/search',
getScopes: Observable.of(['test-scope'])
});
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const fixedFilter = 'fixed filter';
const paginatedSearchOptions = {
query: queryParam,
scope: scopeParam,
fixedFilter: fixedFilter,
pagination,
sort
};
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam,
pagination,
sort
};
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
scope: scopeParam
})
};
const sidebarService = {
isCollapsed: Observable.of(true),
collapse: () => this.isCollapsed = Observable.of(true),
expand: () => this.isCollapsed = Observable.of(false)
};
const routeServiceStub = {
getRouteParameterValue: () => {
return Observable.of('');
}
};
scope: scopeParam
})
};
const sidebarService = {
isCollapsed: Observable.of(true),
collapse: () => this.isCollapsed = Observable.of(true),
expand: () => this.isCollapsed = Observable.of(false)
};
const routeServiceStub = {
getRouteParameterValue: () => {
return Observable.of('');
}
};
export function configureSearchComponentTestingModule(compType) {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, NgbCollapseModule.forRoot()],
declarations: [compType],
providers: [
{ provide: SearchService, useValue: searchServiceStub },
{
provide: CommunityDataService,
useValue: jasmine.createSpyObj('communityService', ['findById', 'findAll'])
},
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{
provide: Store, useValue: store
},
{
provide: HostWindowService, useValue: jasmine.createSpyObj('hostWindowService',
{
isXs: Observable.of(true),
isSm: Observable.of(false),
isXsOrSm: Observable.of(true)
})
},
{
provide: SearchSidebarService,
useValue: sidebarService
},
{
provide: SearchFilterService,
useValue: {}
},
{
provide: SearchConfigurationService,
useValue: {
paginatedSearchOptions: hot('a', {
a: paginatedSearchOptions
}),
getCurrentScope: (a) => Observable.of('test-id'),
/* tslint:disable:no-empty */
updateFixedFilter: (newFilter) => {}
/* tslint:enable:no-empty */
}
},
{
provide: RouteService,
useValue: routeServiceStub
}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(compType, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
}
describe('SearchPageComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, NgbCollapseModule.forRoot()],
declarations: [SearchPageComponent],
providers: [
{ provide: SearchService, useValue: searchServiceStub },
{
provide: CommunityDataService,
useValue: jasmine.createSpyObj('communityService', ['findById', 'findAll'])
},
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{
provide: Store, useValue: store
},
{
provide: HostWindowService, useValue: jasmine.createSpyObj('hostWindowService',
{
isXs: Observable.of(true),
isSm: Observable.of(false),
isXsOrSm: Observable.of(true)
})
},
{
provide: SearchSidebarService,
useValue: sidebarService
},
{
provide: SearchFilterService,
useValue: {}
},
{
provide: SearchConfigurationService,
useValue: {
paginatedSearchOptions: hot('a', {
a: paginatedSearchOptions
}),
getCurrentScope: (a) => Observable.of('test-id')
}
},
{
provide: RouteService,
useValue: routeServiceStub
}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(SearchPageComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
configureSearchComponentTestingModule(SearchPageComponent);
}));
beforeEach(() => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment