Merge remote-tracking branch 'origin/main' into w2p-90978_Improve-initial-page-load_PR

This commit is contained in:
Yura Bondarenko
2022-05-13 09:32:34 +02:00
156 changed files with 2469 additions and 548 deletions

View File

@@ -13,8 +13,10 @@ import { SearchConfigurationService } from '../../core/shared/search/search-conf
import { PaginationServiceStub } from '../testing/pagination-service.stub';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
import { FindListOptions } from '../../core/data/find-list-options.model';
import { BrowserOnlyMockPipe } from '../testing/browser-only-mock.pipe';
import { SearchServiceStub } from '../testing/search-service.stub';
import { Router } from '@angular/router';
import { RouterStub } from '../testing/router.stub';
describe('SearchFormComponent', () => {
let comp: SearchFormComponent;
@@ -22,21 +24,23 @@ describe('SearchFormComponent', () => {
let de: DebugElement;
let el: HTMLElement;
const router = new RouterStub();
const searchService = new SearchServiceStub();
const paginationService = new PaginationServiceStub();
const searchConfigService = {paginationID: 'test-id'};
const searchConfigService = { paginationID: 'test-id' };
const dspaceObjectService = {
findById: () => createSuccessfulRemoteDataObject$(undefined),
};
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [FormsModule, RouterTestingModule, TranslateModule.forRoot()],
providers: [
{
provide: SearchService,
useValue: {}
},
{ provide: Router, useValue: router },
{ provide: SearchService, useValue: searchService },
{ provide: PaginationService, useValue: paginationService },
{ provide: SearchConfigurationService, useValue: searchConfigService },
{ provide: DSpaceObjectDataService, useValue: { findById: () => createSuccessfulRemoteDataObject$(undefined)} }
{ provide: DSpaceObjectDataService, useValue: dspaceObjectService },
],
declarations: [
SearchFormComponent,
@@ -94,6 +98,81 @@ describe('SearchFormComponent', () => {
expect(scopeSelect.textContent).toBe(testCommunity.name);
}));
describe('updateSearch', () => {
const query = 'THOR';
const scope = 'MCU';
let searchQuery = {};
it('should navigate to the search page even when no parameters are provided', () => {
comp.updateSearch(searchQuery);
expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), {
queryParams: searchQuery,
queryParamsHandling: 'merge'
});
});
it('should navigate to the search page with parameters only query if only query is provided', () => {
searchQuery = {
query: query
};
comp.updateSearch(searchQuery);
expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), {
queryParams: searchQuery,
queryParamsHandling: 'merge'
});
});
it('should navigate to the search page with parameters only query if only scope is provided', () => {
searchQuery = {
scope: scope
};
comp.updateSearch(searchQuery);
expect(router.navigate).toHaveBeenCalledWith(comp.getSearchLinkParts(), {
queryParams: searchQuery,
queryParamsHandling: 'merge'
});
});
});
describe('when the scope variable is used', () => {
const query = 'THOR';
const scope = 'MCU';
let searchQuery = {};
beforeEach(() => {
spyOn(comp, 'updateSearch');
});
it('should only search in the provided scope', () => {
searchQuery = {
query: query,
scope: scope
};
comp.scope = scope;
comp.onSubmit(searchQuery);
expect(comp.updateSearch).toHaveBeenCalledWith(searchQuery);
});
it('should not create searchQuery with the scope if an empty scope is provided', () => {
searchQuery = {
query: query
};
comp.scope = '';
comp.onSubmit(searchQuery);
expect(comp.updateSearch).toHaveBeenCalledWith(searchQuery);
});
});
// it('should call updateSearch when clicking the submit button with correct parameters', fakeAsync(() => {
// comp.query = 'Test String'
// fixture.detectChanges();
@@ -116,7 +195,7 @@ describe('SearchFormComponent', () => {
//
// expect(comp.updateSearch).toHaveBeenCalledWith({ scope: scope, query: query });
// }));
});
});
export const objects: DSpaceObject[] = [
Object.assign(new Community(), {