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,79 +12,87 @@ 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', () => {
|
||||||
|
|
||||||
let comp: SearchSettingsComponent;
|
let comp:SearchSettingsComponent;
|
||||||
let fixture: ComponentFixture<SearchSettingsComponent>;
|
let fixture:ComponentFixture<SearchSettingsComponent>;
|
||||||
let searchServiceObject: SearchService;
|
let searchServiceObject:SearchService;
|
||||||
|
|
||||||
const pagination: PaginationComponentOptions = new PaginationComponentOptions();
|
let pagination:PaginationComponentOptions;
|
||||||
pagination.id = 'search-results-pagination';
|
let sort:SortOptions;
|
||||||
pagination.currentPage = 1;
|
let mockResults;
|
||||||
pagination.pageSize = 10;
|
let searchServiceStub;
|
||||||
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';
|
let queryParam;
|
||||||
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
|
let scopeParam;
|
||||||
const paginatedSearchOptions = {
|
let paginatedSearchOptions;
|
||||||
query: queryParam,
|
|
||||||
scope: scopeParam,
|
|
||||||
pagination,
|
|
||||||
sort
|
|
||||||
};
|
|
||||||
|
|
||||||
const activatedRouteStub = {
|
let activatedRouteStub;
|
||||||
queryParams: observableOf({
|
|
||||||
query: queryParam,
|
|
||||||
scope: scopeParam
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
const sidebarService = {
|
let sidebarService;
|
||||||
isCollapsed: observableOf(true),
|
|
||||||
collapse: () => this.isCollapsed = observableOf(true),
|
|
||||||
expand: () => this.isCollapsed = observableOf(false)
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
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({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
|
||||||
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
|
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: SearchService, useValue: searchServiceStub },
|
{provide: SearchService, useValue: searchServiceStub},
|
||||||
|
|
||||||
{ 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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user