Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
refactor(resource): migrate viewer from UI-lib (DSP-1850) (#504)
* refactor(resource): migrates directives from ui-lib to resources directory * refactor(resource): migrates services from ui-lib to resources directory * refactor(viewer): migrates: - boolean-value comp - color-value comp - date-value comp - jdndatepicker directive - custom-regex - value-error-state-matcher * fix: adds ColorPickerModule to AppModule imports * refactor(viewer): migrates: - decimal-value comp - geoname-value comp - int-value comp - interval-value comp - link-value comp - list-value comp - text-value comp - time-value comp - uri-value comp * refactor(viewer): migrates operations components from viewer module * fix(github-ci): specify timezone for unit tests * refactor(viewer): migrates list-view comp * fix: fix app.module imports * chore(workspace): move multiple-resource-view from dsp-ui (DSP-1857) Co-authored-by: André Kilchenmann <github@milchkannen.ch>
- Loading branch information
1 parent
725c45e
commit b742a98
Showing
142 changed files
with
18,795 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/app/search/services/advanced-search-params.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AdvancedSearchParams, AdvancedSearchParamsService } from './advanced-search-params.service'; | ||
|
||
describe('SearchParamsService', () => { | ||
let service: AdvancedSearchParamsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AdvancedSearchParamsService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should return false when initialized', () => { | ||
const searchParams: AdvancedSearchParams = service.getSearchParams(); | ||
|
||
expect(searchParams.generateGravsearch(0)).toBeFalsy(); | ||
}); | ||
|
||
it('should set the parameters of an advanced search', () => { | ||
const testMethod1 = (offset: number) => 'test1'; | ||
|
||
service.changeSearchParamsMsg(new AdvancedSearchParams(testMethod1)); | ||
|
||
const searchParams: AdvancedSearchParams = service.getSearchParams(); | ||
|
||
expect(searchParams.generateGravsearch(0)).toEqual('test1'); | ||
|
||
// check if value is still present | ||
expect(searchParams.generateGravsearch(0)).toEqual('test1'); | ||
|
||
const testMethod2 = (offset: number) => 'test2'; | ||
|
||
service.changeSearchParamsMsg(new AdvancedSearchParams(testMethod2)); | ||
|
||
const searchParams2: AdvancedSearchParams = service.getSearchParams(); | ||
|
||
expect(searchParams2.generateGravsearch(0)).toEqual('test2'); | ||
|
||
// check if value is still present | ||
expect(searchParams2.generateGravsearch(0)).toEqual('test2'); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
/* | ||
* represents the parameters of an advanced search. | ||
*/ | ||
export class AdvancedSearchParams { | ||
|
||
/** | ||
* | ||
* @param generateGravsearch a function that generates a Gravsearch query. | ||
* | ||
* The function takes the offset | ||
* as a parameter and returns a Gravsearch query string. | ||
* Returns false if not set correctly (init state). | ||
*/ | ||
constructor(public generateGravsearch: (offset: number) => string | boolean) { | ||
|
||
} | ||
|
||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AdvancedSearchParamsService { | ||
|
||
private _currentSearchParams; | ||
|
||
constructor() { | ||
// init with a dummy function that returns false | ||
// if the application is reloaded, this will be returned | ||
this._currentSearchParams = new BehaviorSubject<AdvancedSearchParams>(new AdvancedSearchParams((offset: number) => false)); | ||
} | ||
|
||
/** | ||
* updates the parameters of an advanced search. | ||
* | ||
* @param searchParams new advanced search params. | ||
*/ | ||
changeSearchParamsMsg(searchParams: AdvancedSearchParams): void { | ||
this._currentSearchParams.next(searchParams); | ||
} | ||
|
||
/** | ||
* gets the search params of an advanced search. | ||
* | ||
*/ | ||
getSearchParams(): AdvancedSearchParams { | ||
return this._currentSearchParams.getValue(); | ||
} | ||
|
||
} |
Oops, something went wrong.