Update the search-settings component specs

This commit is contained in:
Antoine Snyers
2019-11-15 12:00:55 +01:00
parent 78a29a8770
commit 56d6965233

View File

@@ -12,9 +12,8 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EnumKeysPipe } from '../../shared/utils/enum-keys-pipe'; import { EnumKeysPipe } from '../../shared/utils/enum-keys-pipe';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { SearchFilterService } from '../search-filters/search-filter/search-filter.service'; import { SearchFilterService } from '../search-filters/search-filter/search-filter.service';
import { hot } from 'jasmine-marbles';
import { VarDirective } from '../../shared/utils/var.directive'; 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'; import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
describe('SearchSettingsComponent', () => { describe('SearchSettingsComponent', () => {
@@ -23,40 +22,53 @@ describe('SearchSettingsComponent', () => {
let fixture:ComponentFixture<SearchSettingsComponent>; let fixture:ComponentFixture<SearchSettingsComponent>;
let searchServiceObject:SearchService; let searchServiceObject:SearchService;
const pagination: PaginationComponentOptions = new PaginationComponentOptions(); let pagination:PaginationComponentOptions;
let sort:SortOptions;
let mockResults;
let searchServiceStub;
let queryParam;
let scopeParam;
let paginatedSearchOptions;
let activatedRouteStub;
let sidebarService;
beforeEach(async(() => {
pagination = new PaginationComponentOptions();
pagination.id = 'search-results-pagination'; pagination.id = 'search-results-pagination';
pagination.currentPage = 1; pagination.currentPage = 1;
pagination.pageSize = 10; pagination.pageSize = 10;
const sort: SortOptions = new SortOptions('score', SortDirection.DESC); sort = new SortOptions('score', SortDirection.DESC);
const mockResults = ['test', 'data']; mockResults = ['test', 'data'];
const searchServiceStub = { searchServiceStub = {
searchOptions: {pagination: pagination, sort: sort}, searchOptions: {pagination: pagination, sort: sort},
search: () => mockResults search: () => mockResults,
}; };
const queryParam = 'test query'; queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const paginatedSearchOptions = { paginatedSearchOptions = {
query: queryParam, query: queryParam,
scope: scopeParam, scope: scopeParam,
pagination, pagination,
sort sort,
}; };
const activatedRouteStub = { activatedRouteStub = {
queryParams: observableOf({ queryParams: observableOf({
query: queryParam, query: queryParam,
scope: scopeParam scope: scopeParam,
}) }),
}; };
const sidebarService = { sidebarService = {
isCollapsed: observableOf(true), isCollapsed: observableOf(true),
collapse: () => this.isCollapsed = observableOf(true), collapse: () => this.isCollapsed = observableOf(true),
expand: () => this.isCollapsed = observableOf(false) expand: () => this.isCollapsed = observableOf(false),
}; };
beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective], declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
@@ -66,25 +78,21 @@ describe('SearchSettingsComponent', () => {
{provide: ActivatedRoute, useValue: activatedRouteStub}, {provide: ActivatedRoute, useValue: activatedRouteStub},
{ {
provide: SidebarService, provide: SidebarService,
useValue: sidebarService useValue: sidebarService,
}, },
{ {
provide: SearchFilterService, provide: SearchFilterService,
useValue: {} useValue: {},
}, },
{ {
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'
}),
}
}, },
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA],
}).compileComponents(); }).compileComponents();
})); }));
@@ -101,42 +109,46 @@ 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(take(1)).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.queryAll(By.css('option'));
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 with the respective selectable options', (done) => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => { (comp as any).searchOptions$.pipe(take(1)).subscribe((options) => {
fixture.detectChanges(); fixture.detectChanges();
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings')); const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings'));
expect(pageSizeSetting).toBeDefined(); 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); expect(childElements.length).toEqual(options.pagination.pageSizeOptions.length);
} done();
) },
);
}); });
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(take(1)).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('option[value="0"][selected="selected"]'));
expect(childElementToBeSelected).toBeDefined(); expect(childElementToBeSelected).toBeDefined();
done();
}); });
}); });
it('should have the proper rpp value selected by default', () => { it('should have the proper rpp value selected by default', (done) => {
(comp as any).searchOptions$.pipe(first()).subscribe((options) => { (comp as any).searchOptions$.pipe(take(1)).subscribe((options) => {
fixture.detectChanges(); fixture.detectChanges();
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings')); 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(); expect(childElementToBeSelected).toBeDefined();
done();
}); });
}); });