Skip to content
Snippets Groups Projects
Commit 56d69652 authored by Antoine Snyers's avatar Antoine Snyers
Browse files

Update the search-settings component specs

parent 78a29a87
Branches
Tags
No related merge requests found
......@@ -12,79 +12,87 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EnumKeysPipe } from '../../shared/utils/enum-keys-pipe';
import { By } from '@angular/platform-browser';
import { SearchFilterService } from '../search-filters/search-filter/search-filter.service';
import { hot } from 'jasmine-marbles';
import { VarDirective } from '../../shared/utils/var.directive';
import { first } from 'rxjs/operators';
import { take } from 'rxjs/operators';
import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
describe('SearchSettingsComponent', () => {
let comp: SearchSettingsComponent;
let fixture: ComponentFixture<SearchSettingsComponent>;
let searchServiceObject: SearchService;
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 = ['test', 'data'];
const searchServiceStub = {
searchOptions: { pagination: pagination, sort: sort },
search: () => mockResults
};
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
})
};
let comp:SearchSettingsComponent;
let fixture:ComponentFixture<SearchSettingsComponent>;
let searchServiceObject:SearchService;
let pagination:PaginationComponentOptions;
let sort:SortOptions;
let mockResults;
let searchServiceStub;
let queryParam;
let scopeParam;
let paginatedSearchOptions;
const sidebarService = {
isCollapsed: observableOf(true),
collapse: () => this.isCollapsed = observableOf(true),
expand: () => this.isCollapsed = observableOf(false)
};
let activatedRouteStub;
let sidebarService;
beforeEach(async(() => {
pagination = new PaginationComponentOptions();
pagination.id = 'search-results-pagination';
pagination.currentPage = 1;
pagination.pageSize = 10;
sort = new SortOptions('score', SortDirection.DESC);
mockResults = ['test', 'data'];
searchServiceStub = {
searchOptions: {pagination: pagination, sort: sort},
search: () => mockResults,
};
queryParam = 'test query';
scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
paginatedSearchOptions = {
query: queryParam,
scope: scopeParam,
pagination,
sort,
};
activatedRouteStub = {
queryParams: observableOf({
query: queryParam,
scope: scopeParam,
}),
};
sidebarService = {
isCollapsed: observableOf(true),
collapse: () => this.isCollapsed = observableOf(true),
expand: () => this.isCollapsed = observableOf(false),
};
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
providers: [
{ provide: SearchService, useValue: searchServiceStub },
{provide: SearchService, useValue: searchServiceStub},
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{provide: ActivatedRoute, useValue: activatedRouteStub},
{
provide: SidebarService,
useValue: sidebarService
useValue: sidebarService,
},
{
provide: SearchFilterService,
useValue: {}
useValue: {},
},
{
provide: SEARCH_CONFIG_SERVICE,
useValue: {
paginatedSearchOptions: hot('a', {
a: paginatedSearchOptions
}),
getCurrentScope: hot('a', {
a: 'test-id'
}),
}
paginatedSearchOptions: observableOf(paginatedSearchOptions),
getCurrentScope: observableOf('test-id'),
},
},
],
schemas: [NO_ERRORS_SCHEMA]
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
}));
......@@ -101,42 +109,46 @@ describe('SearchSettingsComponent', () => {
});
it('it should show the order settings with the respective selectable options', () => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => {
it('it should show the order settings with the respective selectable options', (done) => {
(comp as any).searchOptions$.pipe(take(1)).subscribe((options) => {
fixture.detectChanges();
const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings'));
expect(orderSetting).toBeDefined();
const childElements = orderSetting.query(By.css('.form-control')).children;
const childElements = orderSetting.queryAll(By.css('option'));
expect(childElements.length).toEqual(comp.searchOptionPossibilities.length);
done();
});
});
it('it should show the size settings with the respective selectable options', () => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => {
it('it should show the size settings with the respective selectable options', (done) => {
(comp as any).searchOptions$.pipe(take(1)).subscribe((options) => {
fixture.detectChanges();
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings'));
expect(pageSizeSetting).toBeDefined();
const childElements = pageSizeSetting.query(By.css('.form-control')).children;
const childElements = pageSizeSetting.queryAll(By.css('option'));
expect(childElements.length).toEqual(options.pagination.pageSizeOptions.length);
}
)
done();
},
);
});
it('should have the proper order value selected by default', () => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => {
it('should have the proper order value selected by default', (done) => {
(comp as any).searchOptions$.pipe(take(1)).subscribe((options) => {
fixture.detectChanges();
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('option[value="0"][selected="selected"]'));
expect(childElementToBeSelected).toBeDefined();
done();
});
});
it('should have the proper rpp value selected by default', () => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => {
it('should have the proper rpp value selected by default', (done) => {
(comp as any).searchOptions$.pipe(take(1)).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"]'));
const childElementToBeSelected = pageSizeSetting.query(By.css('option[value="10"][selected="selected"]'));
expect(childElementToBeSelected).toBeDefined();
done();
});
});
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment