mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-6645][ADW] Search Feature Stabilisation (#9701)
* [ACS-6645] override input fields * [ACS-6645] update test and documentation
This commit is contained in:
@@ -11,8 +11,9 @@ A minimalistic search input component that formats user query according to the p
|
|||||||
</adf-search-input>
|
</adf-search-input>
|
||||||
```
|
```
|
||||||
|
|
||||||
> Notes: this component does not perform search operations.
|
> Notes:
|
||||||
> It handles the user input, formats and produces the search query to use with `Search Query Builder` or other services.
|
> - This component does not perform search operations. It handles the user input, formats and produces the search query to use with [Search Query Builder](../services/search-query-builder.service.md) or other services.
|
||||||
|
> - If [search configuration](https://github.com/Alfresco/alfresco-ng2-components/blob/develop/lib/content-services/src/lib/search/models/search-configuration.interface.ts) contains `app:fields` param set its value will override `fields` input of this component.
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
|
@@ -15,17 +15,19 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { SearchConfiguration, SearchInputComponent } from '@alfresco/adf-content-services';
|
||||||
import { MatInputHarness } from '@angular/material/input/testing';
|
import { AppConfigService } from '@alfresco/adf-core';
|
||||||
import { SearchInputComponent } from '@alfresco/adf-content-services';
|
|
||||||
import { HarnessLoader } from '@angular/cdk/testing';
|
import { HarnessLoader } from '@angular/cdk/testing';
|
||||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { MatInputHarness } from '@angular/material/input/testing';
|
||||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||||
|
|
||||||
describe('SearchInputComponent', () => {
|
describe('SearchInputComponent', () => {
|
||||||
let loader: HarnessLoader;
|
let loader: HarnessLoader;
|
||||||
let component: SearchInputComponent;
|
let component: SearchInputComponent;
|
||||||
let fixture: ComponentFixture<SearchInputComponent>;
|
let fixture: ComponentFixture<SearchInputComponent>;
|
||||||
|
let appConfig: AppConfigService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the search input value
|
* Sets the search input value
|
||||||
@@ -50,6 +52,7 @@ describe('SearchInputComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||||
|
appConfig = TestBed.inject(AppConfigService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show custom placeholder', async () => {
|
it('should show custom placeholder', async () => {
|
||||||
@@ -74,6 +77,21 @@ describe('SearchInputComponent', () => {
|
|||||||
expect(formatted).toBe('(cm:description:"test*" OR TAG:"test*")');
|
expect(formatted).toBe('(cm:description:"test*" OR TAG:"test*")');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should override input fields if search configuration is set', () => {
|
||||||
|
appConfig.config = {
|
||||||
|
search: {
|
||||||
|
'app:fields': ['TEXT', 'description']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expect(component.fields).toEqual(['cm:name']);
|
||||||
|
const config = appConfig.get<SearchConfiguration>('search');
|
||||||
|
const destFields = config['app:fields'];
|
||||||
|
|
||||||
|
component.ngOnInit();
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.fields).toEqual(destFields);
|
||||||
|
});
|
||||||
|
|
||||||
it('should emit changed event with [cm:name]', async () => {
|
it('should emit changed event with [cm:name]', async () => {
|
||||||
let formatted = '';
|
let formatted = '';
|
||||||
component.changed.subscribe((val) => (formatted = val));
|
component.changed.subscribe((val) => (formatted = val));
|
||||||
|
@@ -15,11 +15,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { AppConfigService } from '@alfresco/adf-core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
|
||||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
import { MatInputModule } from '@angular/material/input';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { SearchConfiguration } from '../../models';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-search-input',
|
selector: 'adf-search-input',
|
||||||
@@ -29,7 +31,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||||||
styleUrls: ['./search-input.component.scss'],
|
styleUrls: ['./search-input.component.scss'],
|
||||||
encapsulation: ViewEncapsulation.None
|
encapsulation: ViewEncapsulation.None
|
||||||
})
|
})
|
||||||
export class SearchInputComponent {
|
export class SearchInputComponent implements OnInit {
|
||||||
@Input()
|
@Input()
|
||||||
value = '';
|
value = '';
|
||||||
|
|
||||||
@@ -45,6 +47,15 @@ export class SearchInputComponent {
|
|||||||
@Output()
|
@Output()
|
||||||
changed = new EventEmitter<string>();
|
changed = new EventEmitter<string>();
|
||||||
|
|
||||||
|
constructor(private appConfig: AppConfigService) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
const searchConfig = this.appConfig.get<SearchConfiguration>('search') || {};
|
||||||
|
if (searchConfig['app:fields']) {
|
||||||
|
this.fields = searchConfig['app:fields'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onSearchInputChanged(event: Event) {
|
onSearchInputChanged(event: Event) {
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as HTMLInputElement;
|
||||||
const searchTerm = input.value;
|
const searchTerm = input.value;
|
||||||
|
Reference in New Issue
Block a user