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:
@@ -15,17 +15,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatInputHarness } from '@angular/material/input/testing';
|
||||
import { SearchInputComponent } from '@alfresco/adf-content-services';
|
||||
import { SearchConfiguration, SearchInputComponent } from '@alfresco/adf-content-services';
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
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';
|
||||
|
||||
describe('SearchInputComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
let component: SearchInputComponent;
|
||||
let fixture: ComponentFixture<SearchInputComponent>;
|
||||
let appConfig: AppConfigService;
|
||||
|
||||
/**
|
||||
* Sets the search input value
|
||||
@@ -50,6 +52,7 @@ describe('SearchInputComponent', () => {
|
||||
component = fixture.componentInstance;
|
||||
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
});
|
||||
|
||||
it('should show custom placeholder', async () => {
|
||||
@@ -74,6 +77,21 @@ describe('SearchInputComponent', () => {
|
||||
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 () => {
|
||||
let formatted = '';
|
||||
component.changed.subscribe((val) => (formatted = val));
|
||||
|
@@ -15,11 +15,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
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 { MatInputModule } from '@angular/material/input';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { SearchConfiguration } from '../../models';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-search-input',
|
||||
@@ -29,7 +31,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
styleUrls: ['./search-input.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class SearchInputComponent {
|
||||
export class SearchInputComponent implements OnInit {
|
||||
@Input()
|
||||
value = '';
|
||||
|
||||
@@ -45,6 +47,15 @@ export class SearchInputComponent {
|
||||
@Output()
|
||||
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) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const searchTerm = input.value;
|
||||
|
Reference in New Issue
Block a user