From 67074c690ab1fee9afc30e43518f6c0c0fb5bea2 Mon Sep 17 00:00:00 2001 From: matrottier Date: Wed, 7 Aug 2019 10:19:24 -0400 Subject: [PATCH] feat(search): Search setting upgrade (#375) * style(geo.search.search-selector) useless line * feat(geo.search.search-setting) enable/disable search source with checkbox * fix(context): fix minors issues context module * test(geo.search.search-settings) fix test * style(geo.search.search-settings) useless code * style(geo.search.search-selector) useless line * feat(geo.search.search-setting) enable/disable search source with checkbox * test(geo.search.search-settings) fix test * style(geo.search.search-settings) useless code * fix (geo.search.source.ilayer) get title when language service not loaded * style (geo.search.search-settings) de-hardcode xposition menu --- package.json | 3 +- .../src/lib/list/list.component.spec.ts | 61 +++++++++++++--- .../search-selector.component.ts | 42 ----------- .../search-settings.component.html | 28 ++++--- .../search-settings.component.scss | 15 ++++ .../search-settings.component.spec.ts | 73 +++++++++++++++++++ .../search-settings.component.ts | 4 + .../search-settings/search-settings.module.ts | 3 - .../src/lib/search/shared/sources/ilayer.ts | 7 +- 9 files changed, 170 insertions(+), 66 deletions(-) create mode 100644 packages/geo/src/lib/search/search-settings/search-settings.component.spec.ts diff --git a/package.json b/package.json index dc69616f82..eb10c4284a 100644 --- a/package.json +++ b/package.json @@ -142,6 +142,7 @@ "tsickle": "0.34.2", "tslint": "^5.12.1", "typescript": "~3.2.4", - "wait-on": "^3.2.0" + "wait-on": "^3.2.0", + "@ngx-translate/http-loader": "^4.0.0" } } diff --git a/packages/common/src/lib/list/list.component.spec.ts b/packages/common/src/lib/list/list.component.spec.ts index eefc0c9182..776392db7d 100644 --- a/packages/common/src/lib/list/list.component.spec.ts +++ b/packages/common/src/lib/list/list.component.spec.ts @@ -1,25 +1,68 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { IgoLanguageModule } from '@igo2/core'; +import { SearchSettingsComponent } from './search-settings.component'; +import { CommonModule } from '@angular/common'; +import { + MatTooltipModule, + MatIconModule, + MatButtonModule, + MatMenuModule, + MatRadioModule, + MatCheckboxModule +} from '@angular/material'; -import { MatListModule } from '@angular/material'; +import { SearchSourceService } from '../shared/search-source.service'; +import { provideDefaultIChercheSearchResultFormatter } from '../shared/sources/icherche.providers'; +import { provideDefaultCoordinatesSearchResultFormatter } from '../shared/sources/coordinates.providers'; +import { SearchSource } from '../shared/sources/source'; +import { HttpClientModule } from '@angular/common/http'; +import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; +import { HttpClient } from '@angular/common/http'; +import {TranslateHttpLoader} from '@ngx-translate/http-loader'; -import { ListComponent } from './list.component'; +// AoT requires an exported function for factories +export function HttpLoaderFactory(httpClient: HttpClient) { + return new TranslateHttpLoader(httpClient); +} -describe('ListComponent', () => { - let component: ListComponent; - let fixture: ComponentFixture; +describe('SearchSettingsComponent', () => { + let component: SearchSettingsComponent; + let fixture: ComponentFixture; beforeEach(async(() => { + + const spy = jasmine.createSpyObj('SearchSourceService', ['getSources']); + TestBed.configureTestingModule({ imports: [ - MatListModule - ], - declarations: [ ListComponent ] + HttpClientModule, + TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useFactory: HttpLoaderFactory, + deps: [HttpClient] + } + }), + IgoLanguageModule, + CommonModule, + MatTooltipModule, + MatIconModule, + MatButtonModule, + MatMenuModule, + MatRadioModule, + MatCheckboxModule], + declarations: [ SearchSettingsComponent ], + providers: [ + { provide: SearchSourceService, useValue: spy }, + provideDefaultIChercheSearchResultFormatter(), + provideDefaultCoordinatesSearchResultFormatter() + ] }) .compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(ListComponent); + fixture = TestBed.createComponent(SearchSettingsComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/packages/geo/src/lib/search/search-selector/search-selector.component.ts b/packages/geo/src/lib/search/search-selector/search-selector.component.ts index 7c88a7ad6b..39cee64a30 100644 --- a/packages/geo/src/lib/search/search-selector/search-selector.component.ts +++ b/packages/geo/src/lib/search/search-selector/search-selector.component.ts @@ -86,46 +86,4 @@ export class SearchSelectorComponent implements OnInit { this.change.emit(searchType); } - /** - * Get all search sources - * @internal - */ - getSearchSources(): SearchSource[] { - return this.searchSourceService.getSources(); - } - - /** - * Triggered when a setting is checked (checkbox style) - * @internal - */ - settingsValueCheckedCheckbox( - event: MatCheckboxChange, - source: SearchSource, - setting: SearchSourceSettings, - settingValue: SettingOptions - ) { - settingValue.enabled = event.checked; - source.setParamFromSetting(setting); - } - - /** - * Triggered when a setting is checked (radiobutton style) - * @internal - */ - settingsValueCheckedRadioButton( - event: MatRadioChange, - source: SearchSource, - setting: SearchSourceSettings, - settingValue: SettingOptions - ) { - setting.values.forEach( conf => { - if (conf.value !== settingValue.value) { - conf.enabled = !event.source.checked; - } else { - conf.enabled = event.source.checked; - } - }); - source.setParamFromSetting(setting); - } - } diff --git a/packages/geo/src/lib/search/search-settings/search-settings.component.html b/packages/geo/src/lib/search/search-settings/search-settings.component.html index 84efd38e34..2455872f33 100644 --- a/packages/geo/src/lib/search/search-settings/search-settings.component.html +++ b/packages/geo/src/lib/search/search-settings/search-settings.component.html @@ -14,14 +14,25 @@ #searchSettingsMenu="matMenu" class="no-border-radius"> - - + + + + + + +