Files
alfresco-ng2-components/lib/content-services/search/components/search-check-list/search-check-list.component.spec.ts
Denys Vuika dbe88a5efc [ADF-2846] new facets (#3251)
* schema and configuration improvements

* check list search widget

* "Clear all" button to reset the list

* page size and "show more" for response facet fields

* test fixes

* fix tests

* fix pagination bug (skipCount reseting)

* integrate date range picker from #3248

* i18n support for date and number range

* some docs for search filter

* docs update

* docs update

* cleanup code as per review
2018-05-01 14:49:03 +01:00

119 lines
3.6 KiB
TypeScript

/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SearchCheckListComponent } from './search-check-list.component';
describe('SearchCheckListComponent', () => {
let component: SearchCheckListComponent;
beforeEach(() => {
component = new SearchCheckListComponent();
});
it('should setup options from settings', () => {
const options: any = [
{ 'name': 'Folder', 'value': "TYPE:'cm:folder'" },
{ 'name': 'Document', 'value': "TYPE:'cm:content'" }
];
component.settings = <any> { options: options };
component.ngOnInit();
expect(component.options).toEqual(options);
});
it('should setup operator from the settings', () => {
component.settings = <any> { operator: 'AND' };
component.ngOnInit();
expect(component.operator).toBe('AND');
});
it('should use OR operator by default', () => {
component.settings = <any> { operator: null };
component.ngOnInit();
expect(component.operator).toBe('OR');
});
it('should update query builder on checkbox change', () => {
component.options = [
{ name: 'Folder', value: "TYPE:'cm:folder'", checked: false },
{ name: 'Document', value: "TYPE:'cm:content'", checked: false }
];
component.id = 'checklist';
component.context = <any> {
queryFragments: {},
update() {}
};
component.ngOnInit();
spyOn(component.context, 'update').and.stub();
component.changeHandler(
<any> { checked: true },
component.options[0]
);
expect(component.context.queryFragments[component.id]).toEqual(`TYPE:'cm:folder'`);
component.changeHandler(
<any> { checked: true },
component.options[1]
);
expect(component.context.queryFragments[component.id]).toEqual(
`TYPE:'cm:folder' OR TYPE:'cm:content'`
);
});
it('should reset selected boxes', () => {
component.options = [
{ name: 'Folder', value: "TYPE:'cm:folder'", checked: true },
{ name: 'Document', value: "TYPE:'cm:content'", checked: true }
];
component.reset();
expect(component.options[0].checked).toBeFalsy();
expect(component.options[1].checked).toBeFalsy();
});
it('should update query builder on reset', () => {
component.id = 'checklist';
component.context = <any> {
queryFragments: {
'checklist': 'query'
},
update() {}
};
spyOn(component.context, 'update').and.stub();
component.ngOnInit();
component.options = [
{ name: 'Folder', value: "TYPE:'cm:folder'", checked: true },
{ name: 'Document', value: "TYPE:'cm:content'", checked: true }
];
component.reset();
expect(component.context.update).toHaveBeenCalled();
expect(component.context.queryFragments[component.id]).toBe('');
});
});