mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Update the search-settings component specs
This commit is contained in:
@@ -12,9 +12,8 @@ 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', () => {
|
||||
@@ -23,40 +22,53 @@ describe('SearchSettingsComponent', () => {
|
||||
let fixture:ComponentFixture<SearchSettingsComponent>;
|
||||
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.currentPage = 1;
|
||||
pagination.pageSize = 10;
|
||||
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
|
||||
const mockResults = ['test', 'data'];
|
||||
const searchServiceStub = {
|
||||
sort = new SortOptions('score', SortDirection.DESC);
|
||||
mockResults = ['test', 'data'];
|
||||
searchServiceStub = {
|
||||
searchOptions: {pagination: pagination, sort: sort},
|
||||
search: () => mockResults
|
||||
search: () => mockResults,
|
||||
};
|
||||
|
||||
const queryParam = 'test query';
|
||||
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
|
||||
const paginatedSearchOptions = {
|
||||
queryParam = 'test query';
|
||||
scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
|
||||
paginatedSearchOptions = {
|
||||
query: queryParam,
|
||||
scope: scopeParam,
|
||||
pagination,
|
||||
sort
|
||||
sort,
|
||||
};
|
||||
|
||||
const activatedRouteStub = {
|
||||
activatedRouteStub = {
|
||||
queryParams: observableOf({
|
||||
query: queryParam,
|
||||
scope: scopeParam
|
||||
})
|
||||
scope: scopeParam,
|
||||
}),
|
||||
};
|
||||
|
||||
const sidebarService = {
|
||||
sidebarService = {
|
||||
isCollapsed: observableOf(true),
|
||||
collapse: () => this.isCollapsed = observableOf(true),
|
||||
expand: () => this.isCollapsed = observableOf(false)
|
||||
expand: () => this.isCollapsed = observableOf(false),
|
||||
};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
||||
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
|
||||
@@ -66,25 +78,21 @@ describe('SearchSettingsComponent', () => {
|
||||
{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();
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user