mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-10847] Location filter breaks the page when user value used (#11667)
* [ACS-10847] Location filter breaks the page when user value used * [ACS-10847] simplify the ternary
This commit is contained in:
+35
-1
@@ -19,7 +19,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { SearchFilterAutocompleteChipsComponent } from './search-filter-autocomplete-chips.component';
|
import { SearchFilterAutocompleteChipsComponent } from './search-filter-autocomplete-chips.component';
|
||||||
import { EMPTY, of, ReplaySubject } from 'rxjs';
|
import { EMPTY, of, ReplaySubject } from 'rxjs';
|
||||||
import { AutocompleteField } from '../../models/autocomplete-option.interface';
|
import { AutocompleteField, AutocompleteOption } from '../../models/autocomplete-option.interface';
|
||||||
import { TagService } from '../../../tag/services/tag.service';
|
import { TagService } from '../../../tag/services/tag.service';
|
||||||
import { SitesService } from '../../../common/services/sites.service';
|
import { SitesService } from '../../../common/services/sites.service';
|
||||||
import { SitePaging } from '@alfresco/js-api';
|
import { SitePaging } from '@alfresco/js-api';
|
||||||
@@ -212,6 +212,18 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use id if present, otherwise value, in LOCATION query fragment', () => {
|
||||||
|
component.settings.field = AutocompleteField.LOCATION;
|
||||||
|
component.settings.autocompleteOptions = [];
|
||||||
|
component.selectedOptions = [
|
||||||
|
{ id: 'site1', value: 'Marketing' },
|
||||||
|
{ value: 'custom' }
|
||||||
|
];
|
||||||
|
component.submitValues();
|
||||||
|
expect(component.context.queryFragments[component.id])
|
||||||
|
.toBe('SITE:"site1" OR SITE:"custom"');
|
||||||
|
});
|
||||||
|
|
||||||
it('should still call sitesService.getSites when input is empty for LOCATION field', () => {
|
it('should still call sitesService.getSites when input is empty for LOCATION field', () => {
|
||||||
component.settings.field = AutocompleteField.LOCATION;
|
component.settings.field = AutocompleteField.LOCATION;
|
||||||
const getSitesSpy = spyOn(sitesService, 'getSites').and.returnValue(
|
const getSitesSpy = spyOn(sitesService, 'getSites').and.returnValue(
|
||||||
@@ -238,4 +250,26 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
|
|||||||
|
|
||||||
expect(searchSpy).toHaveBeenCalledWith('', 0, 15);
|
expect(searchSpy).toHaveBeenCalledWith('', 0, 15);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('optionComparator', () => {
|
||||||
|
it('should return false if either option is undefined', () => {
|
||||||
|
expect(component.optionComparator(undefined, { value: 'A' })).toBe(false);
|
||||||
|
expect(component.optionComparator({ value: 'A' }, undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should compare by id if both have id', () => {
|
||||||
|
expect(component.optionComparator({ id: 'abc', value: 'B' } , { id: 'ABC', value: 'B' })).toBe(true);
|
||||||
|
expect(component.optionComparator({ id: 'abc', value: 'B' }, { id: 'def', value: 'B' })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should compare by value if both have value and one has no id', () => {
|
||||||
|
expect(component.optionComparator({ value: 'A', id: 'id1' }, { value: 'a' })).toBe(true);
|
||||||
|
expect(component.optionComparator({ value: 'A', id: 'id1' }, { value: 'B' })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if only one has id or value', () => {
|
||||||
|
expect(component.optionComparator({ id: 'abc' } as AutocompleteOption, { value: 'abc' })).toBe(false);
|
||||||
|
expect(component.optionComparator({ value: 'abc' }, { id: 'abc' } as AutocompleteOption)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+9
-2
@@ -130,7 +130,14 @@ export class SearchFilterAutocompleteChipsComponent implements SearchWidget, OnI
|
|||||||
}
|
}
|
||||||
|
|
||||||
optionComparator(option1: AutocompleteOption, option2: AutocompleteOption): boolean {
|
optionComparator(option1: AutocompleteOption, option2: AutocompleteOption): boolean {
|
||||||
return option1.id ? option1.id.toUpperCase() === option2.id.toUpperCase() : option1.value.toUpperCase() === option2.value.toUpperCase();
|
if (!option1 || !option2) return false;
|
||||||
|
if (option1.id && option2.id) {
|
||||||
|
return option1.id.toUpperCase() === option2.id.toUpperCase();
|
||||||
|
}
|
||||||
|
if (option1.value && option2.value) {
|
||||||
|
return option1.value.toUpperCase() === option2.value.toUpperCase();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateQuery(updateContext = true) {
|
private updateQuery(updateContext = true) {
|
||||||
@@ -143,7 +150,7 @@ export class SearchFilterAutocompleteChipsComponent implements SearchWidget, OnI
|
|||||||
queryFragments = this.selectedOptions.map((val) => `${this.settings.field}:"workspace://SpacesStore/${val.id}"`);
|
queryFragments = this.selectedOptions.map((val) => `${this.settings.field}:"workspace://SpacesStore/${val.id}"`);
|
||||||
break;
|
break;
|
||||||
case AutocompleteField.LOCATION:
|
case AutocompleteField.LOCATION:
|
||||||
queryFragments = this.selectedOptions.map((val) => val.query ?? `${this.settings.field}:"${val.id}"`);
|
queryFragments = this.selectedOptions.map((val) => val.query ?? `${this.settings.field}:"${val.id || val.value}"`);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
queryFragments = this.selectedOptions.map((val) => val.query ?? `${this.settings.field}:"${val.value}"`);
|
queryFragments = this.selectedOptions.map((val) => val.query ?? `${this.settings.field}:"${val.value}"`);
|
||||||
|
|||||||
Reference in New Issue
Block a user