mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AAE-1955] [ADF-5082] [AAE-1969] and [AAE-1970] Search Unit test (#5508)
* initial commit * [AAE-1955] Search Categories Unit test * more unit added * check box test added * [AAE-1970] Search Search Filters Facet Container Uni Test * * naming improvements
This commit is contained in:
parent
999e513087
commit
ae38f3f4ac
@ -19,3 +19,4 @@ export * from './document-library.model.mock';
|
||||
export * from './document-list.component.mock';
|
||||
export * from './search.component.mock';
|
||||
export * from './search.service.mock';
|
||||
export * from './search-filter-mock';
|
||||
|
611
lib/content-services/src/lib/mock/search-filter-mock.ts
Normal file
611
lib/content-services/src/lib/mock/search-filter-mock.ts
Normal file
@ -0,0 +1,611 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
export const expandableCategories = [
|
||||
{
|
||||
id: 'cat-1',
|
||||
name: 'category-1',
|
||||
expanded: false,
|
||||
enabled: false,
|
||||
component: {
|
||||
selector: 'cat-1-component',
|
||||
settings: null
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export const disabledCategories = [
|
||||
{
|
||||
id: 'queryType',
|
||||
name: 'Type',
|
||||
expanded: true,
|
||||
enabled: false,
|
||||
component: {
|
||||
selector: 'check-list',
|
||||
settings: {
|
||||
'field': null,
|
||||
'pageSize': 5,
|
||||
'options': [
|
||||
{ 'name': 'Folder', 'value': "TYPE:'cm:folder'" },
|
||||
{ 'name': 'Document', 'value': "TYPE:'cm:content'" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export const expandedCategories = [
|
||||
{
|
||||
id: 'queryType',
|
||||
name: 'Type',
|
||||
expanded: true,
|
||||
enabled: true,
|
||||
component: {
|
||||
selector: 'check-list',
|
||||
settings: {
|
||||
'field': null,
|
||||
'pageSize': 5,
|
||||
'options': [
|
||||
{ 'name': 'Folder', 'value': "TYPE:'cm:folder'" },
|
||||
{ 'name': 'Document', 'value': "TYPE:'cm:content'" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export const simpleCategories = [
|
||||
{
|
||||
id: 'queryName',
|
||||
name: 'Name',
|
||||
expanded: false,
|
||||
enabled: true,
|
||||
component: {
|
||||
selector: 'text',
|
||||
settings: {}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'queryType',
|
||||
name: 'Type',
|
||||
expanded: false,
|
||||
enabled: true,
|
||||
component: {
|
||||
selector: 'check-list',
|
||||
settings: {
|
||||
'field': null,
|
||||
'pageSize': 5,
|
||||
'options': [
|
||||
{ 'name': 'Folder', 'value': "TYPE:'cm:folder'" },
|
||||
{ 'name': 'Document', 'value': "TYPE:'cm:content'" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
export const searchFilter = {
|
||||
'app:fields': [
|
||||
'cm:name'
|
||||
],
|
||||
'include': [
|
||||
'allowableOperations'
|
||||
],
|
||||
'sorting': {
|
||||
'options': [
|
||||
{
|
||||
'key': 'name',
|
||||
'label': 'Name',
|
||||
'type': 'FIELD',
|
||||
'field': 'cm:name',
|
||||
'ascending': true
|
||||
}
|
||||
],
|
||||
'defaults': [
|
||||
{
|
||||
'key': 'score',
|
||||
'type': 'FIELD',
|
||||
'field': 'score',
|
||||
'ascending': false
|
||||
}
|
||||
]
|
||||
},
|
||||
'resetButton': true,
|
||||
'filterQueries': [
|
||||
{
|
||||
'query': "TYPE:'cm:folder' OR TYPE:'cm:content'"
|
||||
},
|
||||
{
|
||||
'query': 'NOT cm:creator:System'
|
||||
}
|
||||
],
|
||||
'facetFields': {
|
||||
'expanded': true,
|
||||
'fields': [
|
||||
{
|
||||
'field': 'content.mimetype',
|
||||
'mincount': 1,
|
||||
'label': 'SEARCH.FACET_FIELDS.TYPE'
|
||||
},
|
||||
{
|
||||
'field': 'content.size',
|
||||
'mincount': 1,
|
||||
'label': 'SEARCH.FACET_FIELDS.SIZE'
|
||||
},
|
||||
{
|
||||
'field': 'creator',
|
||||
'mincount': 1,
|
||||
'label': 'SEARCH.FACET_FIELDS.CREATOR'
|
||||
},
|
||||
{
|
||||
'field': 'modifier',
|
||||
'mincount': 1,
|
||||
'label': 'SEARCH.FACET_FIELDS.MODIFIER'
|
||||
},
|
||||
{
|
||||
'field': 'created',
|
||||
'mincount': 1,
|
||||
'label': 'SEARCH.FACET_FIELDS.CREATED'
|
||||
}
|
||||
]
|
||||
},
|
||||
'facetQueries': {
|
||||
'label': 'SEARCH.FACET_QUERIES.MY_FACET_QUERIES',
|
||||
'pageSize': 5,
|
||||
'expanded': true,
|
||||
'mincount': 1,
|
||||
'queries': [
|
||||
{
|
||||
'query': 'created:2019',
|
||||
'label': 'SEARCH.FACET_QUERIES.CREATED_THIS_YEAR'
|
||||
},
|
||||
{
|
||||
'query': 'content.mimetype:text/html',
|
||||
'label': 'SEARCH.FACET_QUERIES.MIMETYPE',
|
||||
'group': 'Type facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[0 TO 10240]',
|
||||
'label': 'Extra Small',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[10240 TO 102400]',
|
||||
'label': 'SEARCH.FACET_QUERIES.SMALL',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[102400 TO 1048576]',
|
||||
'label': 'SEARCH.FACET_QUERIES.MEDIUM',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[1048576 TO 16777216]',
|
||||
'label': 'SEARCH.FACET_QUERIES.LARGE',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[16777216 TO 134217728]',
|
||||
'label': 'SEARCH.FACET_QUERIES.XTRALARGE',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[134217728 TO MAX]',
|
||||
'label': 'SEARCH.FACET_QUERIES.XXTRALARGE',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[111111 TO MAX]',
|
||||
'label': 'my1',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[222222 TO MAX]',
|
||||
'label': 'my2',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[333333 TO MAX]',
|
||||
'label': 'my3',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[444444 TO MAX]',
|
||||
'label': 'my4',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[5555 TO MAX]',
|
||||
'label': 'my5',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[666666 TO MAX]',
|
||||
'label': 'my6',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[777777 TO MAX]',
|
||||
'label': 'my7',
|
||||
'group': 'Size facet queries'
|
||||
},
|
||||
{
|
||||
'query': 'content.size:[888888 TO MAX]',
|
||||
'label': 'my8',
|
||||
'group': 'Size facet queries'
|
||||
}
|
||||
]
|
||||
},
|
||||
'facetIntervals': {
|
||||
'expanded': true,
|
||||
'intervals': [
|
||||
{
|
||||
'label': 'The Created',
|
||||
'field': 'cm:created',
|
||||
'sets': [
|
||||
{
|
||||
'label': 'lastYear',
|
||||
'start': '2018',
|
||||
'end': '2019',
|
||||
'endInclusive': false
|
||||
},
|
||||
{
|
||||
'label': 'currentYear',
|
||||
'start': 'NOW/YEAR',
|
||||
'end': 'NOW/YEAR+1YEAR'
|
||||
},
|
||||
{
|
||||
'label': 'earlier',
|
||||
'start': '*',
|
||||
'end': '2018',
|
||||
'endInclusive': false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'TheModified',
|
||||
'field': 'cm:modified',
|
||||
'sets': [
|
||||
{
|
||||
'label': '2017',
|
||||
'start': '2017',
|
||||
'end': '2018',
|
||||
'endInclusive': false
|
||||
},
|
||||
{
|
||||
'label': '2017-2018',
|
||||
'start': '2017',
|
||||
'end': '2018',
|
||||
'endInclusive': true
|
||||
},
|
||||
{
|
||||
'label': 'currentYear',
|
||||
'start': 'NOW/YEAR',
|
||||
'end': 'NOW/YEAR+1YEAR'
|
||||
},
|
||||
{
|
||||
'label': 'earlierThan2017',
|
||||
'start': '*',
|
||||
'end': '2017',
|
||||
'endInclusive': false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
'categories': [
|
||||
{
|
||||
'id': 'queryName',
|
||||
'name': 'Name',
|
||||
'enabled': true,
|
||||
'expanded': true,
|
||||
'component': {
|
||||
'selector': 'text',
|
||||
'settings': {
|
||||
'pattern': "cm:name:'(.*?)'",
|
||||
'field': 'cm:name',
|
||||
'placeholder': 'Enter the name'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': 'checkList',
|
||||
'name': 'Check List',
|
||||
'enabled': true,
|
||||
'component': {
|
||||
'selector': 'check-list',
|
||||
'settings': {
|
||||
'pageSize': 5,
|
||||
'operator': 'OR',
|
||||
'options': []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': 'contentSize',
|
||||
'name': 'Content Size',
|
||||
'enabled': true,
|
||||
'component': {
|
||||
'selector': 'slider',
|
||||
'settings': {
|
||||
'field': 'cm:content.size',
|
||||
'min': 0,
|
||||
'max': 18,
|
||||
'step': 1,
|
||||
'thumbLabel': true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': 'contentSizeRange',
|
||||
'name': 'Content Size (range)',
|
||||
'enabled': true,
|
||||
'component': {
|
||||
'selector': 'number-range',
|
||||
'settings': {
|
||||
'field': 'cm:content.size',
|
||||
'format': '[{FROM} TO {TO}]'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': 'createdDateRange',
|
||||
'name': 'Created Date (range)',
|
||||
'enabled': true,
|
||||
'component': {
|
||||
'selector': 'date-range',
|
||||
'settings': {
|
||||
'field': 'cm:created',
|
||||
'dateFormat': 'DD-MMM-YY'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': 'queryType',
|
||||
'name': 'Type',
|
||||
'enabled': true,
|
||||
'component': {
|
||||
'selector': 'radio',
|
||||
'settings': {
|
||||
'field': null,
|
||||
'pageSize': 5,
|
||||
'options': []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const mockSearchResult = {
|
||||
'list': {
|
||||
'pagination': { 'count': 20, 'hasMoreItems': true, 'totalItems': 20284, 'skipCount': 0, 'maxItems': 20 },
|
||||
'context': {
|
||||
'consistency': { 'lastTxId': 122854 },
|
||||
'facets': [
|
||||
{
|
||||
'type': 'query',
|
||||
'label': 'Type facet queries',
|
||||
'buckets': [
|
||||
{
|
||||
'label': 'SEARCH.FACET_QUERIES.MIMETYPE',
|
||||
'filterQuery': 'content.mimetype:text/html',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 13 } }]
|
||||
}]
|
||||
}, {
|
||||
'type': 'query',
|
||||
'label': 'Size facet queries',
|
||||
'buckets': [
|
||||
{
|
||||
'label': 'my1',
|
||||
'filterQuery': 'content.size:[111111 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 806 } }]
|
||||
}, {
|
||||
'label': 'my3',
|
||||
'filterQuery': 'content.size:[333333 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 669 } }]
|
||||
}, {
|
||||
'label': 'my2',
|
||||
'filterQuery': 'content.size:[222222 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 691 } }]
|
||||
}, {
|
||||
'label': 'my5',
|
||||
'filterQuery': 'content.size:[5555 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 1866 } }]
|
||||
}, {
|
||||
'label': 'my4',
|
||||
'filterQuery': 'content.size:[444444 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 665 } }]
|
||||
}, {
|
||||
'label': 'my7',
|
||||
'filterQuery': 'content.size:[777777 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 641 } }]
|
||||
}, {
|
||||
'label': 'SEARCH.FACET_QUERIES.SMALL',
|
||||
'filterQuery': 'content.size:[10240 TO 102400]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 526 } }]
|
||||
}, {
|
||||
'label': 'my6',
|
||||
'filterQuery': 'content.size:[666666 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 652 } }]
|
||||
}, {
|
||||
'label': 'SEARCH.FACET_QUERIES.XTRALARGE',
|
||||
'filterQuery': 'content.size:[16777216 TO 134217728]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 617 } }]
|
||||
}, {
|
||||
'label': 'my8',
|
||||
'filterQuery': 'content.size:[888888 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 641 } }]
|
||||
}, {
|
||||
'label': 'SEARCH.FACET_QUERIES.XXTRALARGE',
|
||||
'filterQuery': 'content.size:[134217728 TO MAX]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 0 } }]
|
||||
}, {
|
||||
'label': 'SEARCH.FACET_QUERIES.MEDIUM',
|
||||
'filterQuery': 'content.size:[102400 TO 1048576]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 630 } }]
|
||||
}, {
|
||||
'label': 'SEARCH.FACET_QUERIES.LARGE',
|
||||
'filterQuery': 'content.size:[1048576 TO 16777216]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 23 } }]
|
||||
}, {
|
||||
'label': 'Extra Small',
|
||||
'filterQuery': 'content.size:[0 TO 10240]',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 10239 } }]
|
||||
}]
|
||||
}, {
|
||||
'type': 'query',
|
||||
'label': 'SEARCH.FACET_QUERIES.MY_FACET_QUERIES',
|
||||
'buckets': [
|
||||
{
|
||||
'label': 'SEARCH.FACET_QUERIES.CREATED_THIS_YEAR',
|
||||
'filterQuery': 'created:2019',
|
||||
'metrics': [{ 'type': 'count', 'value': { 'count': 0 } }]
|
||||
}]
|
||||
},
|
||||
{
|
||||
'type': 'field',
|
||||
'label': 'SEARCH.FACET_FIELDS.SIZE',
|
||||
'buckets': []
|
||||
}, {
|
||||
'type': 'field',
|
||||
'label': 'SEARCH.FACET_FIELDS.CREATED',
|
||||
'buckets': []
|
||||
}, {
|
||||
'type': 'field',
|
||||
'label': 'SEARCH.FACET_FIELDS.TYPE',
|
||||
'buckets': []
|
||||
}, {
|
||||
'type': 'field',
|
||||
'label': 'SEARCH.FACET_FIELDS.MODIFIER',
|
||||
'buckets': []
|
||||
}, {
|
||||
'type': 'field',
|
||||
'label': 'SEARCH.FACET_FIELDS.CREATOR',
|
||||
'buckets': []
|
||||
}, {
|
||||
'type': 'interval',
|
||||
'label': 'TheModified',
|
||||
'buckets': []
|
||||
}, {
|
||||
'type': 'interval',
|
||||
'label': 'The Created',
|
||||
'buckets': []
|
||||
}]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const stepOne = [
|
||||
'Extra Small (10239)',
|
||||
'SEARCH.FACET_QUERIES.SMALL (526)',
|
||||
'SEARCH.FACET_QUERIES.MEDIUM (630)',
|
||||
'SEARCH.FACET_QUERIES.LARGE (23)',
|
||||
'SEARCH.FACET_QUERIES.XTRALARGE (617)'
|
||||
];
|
||||
|
||||
export const stepTwo = [
|
||||
'Extra Small (10239)',
|
||||
'SEARCH.FACET_QUERIES.SMALL (526)',
|
||||
'SEARCH.FACET_QUERIES.MEDIUM (630)',
|
||||
'SEARCH.FACET_QUERIES.LARGE (23)',
|
||||
'SEARCH.FACET_QUERIES.XTRALARGE (617)',
|
||||
'my1 (806)',
|
||||
'my2 (691)',
|
||||
'my3 (669)',
|
||||
'my4 (665)',
|
||||
'my5 (1866)'
|
||||
];
|
||||
|
||||
export const stepThree = [
|
||||
'Extra Small (10239)',
|
||||
'SEARCH.FACET_QUERIES.SMALL (526)',
|
||||
'SEARCH.FACET_QUERIES.MEDIUM (630)',
|
||||
'SEARCH.FACET_QUERIES.LARGE (23)',
|
||||
'SEARCH.FACET_QUERIES.XTRALARGE (617)',
|
||||
'my1 (806)',
|
||||
'my2 (691)',
|
||||
'my3 (669)',
|
||||
'my4 (665)',
|
||||
'my5 (1866)',
|
||||
'my6 (652)',
|
||||
'my7 (641)',
|
||||
'my8 (641)'
|
||||
];
|
||||
|
||||
export const sizeOptions = [
|
||||
{
|
||||
'name': 'Extra Small (10239)',
|
||||
'value': 'Extra Small (10239)'
|
||||
},
|
||||
{
|
||||
'name': 'SEARCH.FACET_QUERIES.SMALL (526)',
|
||||
'value': 'SEARCH.FACET_QUERIES.SMALL (526)'
|
||||
},
|
||||
{
|
||||
'name': 'SEARCH.FACET_QUERIES.MEDIUM (630)',
|
||||
'value': 'SEARCH.FACET_QUERIES.MEDIUM (630)'
|
||||
},
|
||||
{
|
||||
'name': 'SEARCH.FACET_QUERIES.LARGE (23)',
|
||||
'value': 'SEARCH.FACET_QUERIES.LARGE (23)'
|
||||
},
|
||||
{
|
||||
'name': 'SEARCH.FACET_QUERIES.XTRALARGE (617)',
|
||||
'value': 'SEARCH.FACET_QUERIES.XTRALARGE (617)'
|
||||
},
|
||||
{
|
||||
'name': 'my1 (806)',
|
||||
'group': 'my1 (806)'
|
||||
},
|
||||
{
|
||||
'name': 'my2 (691)',
|
||||
'value': 'my2 (691)'
|
||||
},
|
||||
{
|
||||
'name': 'my3 (669)',
|
||||
'value': 'my3 (669)'
|
||||
},
|
||||
{
|
||||
'name': 'my4 (665)',
|
||||
'value': 'my4 (665)'
|
||||
},
|
||||
{
|
||||
'name': 'my5 (1866)',
|
||||
'group': 'my5 (1866)'
|
||||
},
|
||||
{
|
||||
'name': 'my6 (652)',
|
||||
'group': 'my6 (652)'
|
||||
},
|
||||
{
|
||||
'name': 'my7 (641)',
|
||||
'value': 'my7 (641)'
|
||||
},
|
||||
{
|
||||
'name': 'my8 (641)',
|
||||
'value': 'my8 (641)'
|
||||
}
|
||||
];
|
||||
|
||||
export const filteredResult = [
|
||||
'my1 (806)',
|
||||
'my2 (691)',
|
||||
'my3 (669)',
|
||||
'my4 (665)',
|
||||
'my5 (1866)'
|
||||
];
|
@ -17,13 +17,23 @@
|
||||
|
||||
import { SearchCheckListComponent, SearchListOption } from './search-check-list.component';
|
||||
import { SearchFilterList } from '../search-filter/models/search-filter-list.model';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { sizeOptions, stepOne, stepThree } from '../../../mock';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
describe('SearchCheckListComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<SearchCheckListComponent>;
|
||||
let component: SearchCheckListComponent;
|
||||
|
||||
setupTestBed({
|
||||
imports: [ ContentTestingModule ]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
component = new SearchCheckListComponent();
|
||||
fixture = TestBed.createComponent(SearchCheckListComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should setup options from settings', () => {
|
||||
@ -115,4 +125,69 @@ describe('SearchCheckListComponent', () => {
|
||||
expect(component.context.update).toHaveBeenCalled();
|
||||
expect(component.context.queryFragments[component.id]).toBe('');
|
||||
});
|
||||
|
||||
describe('Pagination', () => {
|
||||
it('should show 5 items when pageSize not defined', () => {
|
||||
component.id = 'checklist';
|
||||
component.context = <any> {
|
||||
queryFragments: {
|
||||
'checklist': 'query'
|
||||
},
|
||||
update() {}
|
||||
};
|
||||
component.settings = <any> { options: sizeOptions };
|
||||
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const optionElements = fixture.debugElement.queryAll(By.css('mat-checkbox'));
|
||||
expect(optionElements.length).toEqual(5);
|
||||
const labels = Array.from(optionElements).map(element => element.nativeElement.innerText);
|
||||
expect(labels).toEqual(stepOne);
|
||||
});
|
||||
|
||||
it('should show all items when pageSize is high', () => {
|
||||
component.id = 'checklist';
|
||||
component.context = <any> {
|
||||
queryFragments: {
|
||||
'checklist': 'query'
|
||||
},
|
||||
update() {}
|
||||
};
|
||||
component.settings = <any> { pageSize: 15, options: sizeOptions };
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const optionElements = fixture.debugElement.queryAll(By.css('mat-checkbox'));
|
||||
expect(optionElements.length).toEqual(13);
|
||||
const labels = Array.from(optionElements).map(element => element.nativeElement.innerText);
|
||||
expect(labels).toEqual(stepThree);
|
||||
});
|
||||
});
|
||||
|
||||
it('should able to check/reset the checkbox', () => {
|
||||
component.id = 'checklist';
|
||||
component.context = <any> {
|
||||
queryFragments: {
|
||||
'checklist': 'query'
|
||||
},
|
||||
update: () => {}
|
||||
};
|
||||
component.settings = <any> { options: sizeOptions };
|
||||
spyOn(component, 'flush').and.stub();
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const optionElements = fixture.debugElement.query(By.css('mat-checkbox'));
|
||||
optionElements.triggerEventHandler('change', { checked: true });
|
||||
|
||||
expect(component.flush).toHaveBeenCalled();
|
||||
|
||||
const clearAllElement = fixture.debugElement.query(By.css('button[title="SEARCH.FILTER.ACTIONS.CLEAR-ALL"]'));
|
||||
clearAllElement.triggerEventHandler('click', {} );
|
||||
fixture.detectChanges();
|
||||
|
||||
const selectedElements = fixture.debugElement.queryAll(By.css('.mat-checkbox-checked'));
|
||||
expect(selectedElements.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
@ -17,88 +17,62 @@
|
||||
|
||||
import { SearchFilterComponent } from './search-filter.component';
|
||||
import { SearchQueryBuilderService } from '../../search-query-builder.service';
|
||||
import { AppConfigService, TranslationMock, CoreModule, TranslationService, SearchService } from '@alfresco/adf-core';
|
||||
import { AppConfigService, SearchService, setupTestBed, TranslationService } from '@alfresco/adf-core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { FacetFieldBucket } from '../../facet-field-bucket.interface';
|
||||
import { FacetField } from '../../facet-field.interface';
|
||||
import { SearchFilterList } from './models/search-filter-list.model';
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import {
|
||||
disabledCategories,
|
||||
expandableCategories,
|
||||
expandedCategories,
|
||||
filteredResult,
|
||||
mockSearchResult,
|
||||
searchFilter,
|
||||
simpleCategories,
|
||||
stepOne,
|
||||
stepThree,
|
||||
stepTwo
|
||||
} from '../../../mock';
|
||||
|
||||
describe('SearchFilterComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<SearchFilterComponent>;
|
||||
let component: SearchFilterComponent;
|
||||
let queryBuilder: SearchQueryBuilderService;
|
||||
let appConfig: AppConfigService;
|
||||
const translationMock = new TranslationMock();
|
||||
|
||||
beforeEach(() => {
|
||||
let appConfigService: AppConfigService;
|
||||
const searchMock: any = {
|
||||
dataLoaded: new Subject()
|
||||
};
|
||||
translationMock.instant = (key) => `${key}_translated`;
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
setupTestBed({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
HttpClientModule,
|
||||
NoopAnimationsModule
|
||||
ContentTestingModule
|
||||
],
|
||||
declarations: [SearchFilterComponent],
|
||||
providers: [
|
||||
{ provide: SearchService, useValue: searchMock },
|
||||
{ provide: TranslationService, useValue: translationMock }
|
||||
],
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
{ provide: SearchService, useValue: searchMock }
|
||||
]
|
||||
});
|
||||
|
||||
appConfig = TestBed.get(AppConfigService);
|
||||
appConfig.config.search = {};
|
||||
|
||||
beforeEach(() => {
|
||||
queryBuilder = TestBed.get(SearchQueryBuilderService);
|
||||
|
||||
component = new SearchFilterComponent(queryBuilder, searchMock, translationMock);
|
||||
component.ngOnInit();
|
||||
fixture = TestBed.createComponent(SearchFilterComponent);
|
||||
appConfigService = TestBed.get(AppConfigService);
|
||||
const translationService = fixture.debugElement.injector.get(TranslationService);
|
||||
spyOn(translationService, 'instant').and.callFake((key) => key ? `${key}_translated` : null);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should have expandable categories', async(() => {
|
||||
queryBuilder.categories = [
|
||||
{
|
||||
id: 'cat-1',
|
||||
name: 'category-1',
|
||||
expanded: false,
|
||||
enabled: false,
|
||||
component: {
|
||||
selector: 'cat-1-component',
|
||||
settings: null
|
||||
}
|
||||
}
|
||||
];
|
||||
afterEach(() => fixture.destroy());
|
||||
|
||||
const fixture = TestBed.createComponent(SearchFilterComponent);
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(1);
|
||||
|
||||
const element: HTMLElement = panels[0].nativeElement;
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toBeTruthy();
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toBeFalsy();
|
||||
});
|
||||
}));
|
||||
describe('component', () => {
|
||||
beforeEach(() => fixture.detectChanges());
|
||||
|
||||
it('should subscribe to query builder executed event', () => {
|
||||
spyOn(component, 'onDataLoaded').and.stub();
|
||||
const data = {};
|
||||
const data = { list: {} };
|
||||
queryBuilder.executed.next(data);
|
||||
|
||||
expect(component.onDataLoaded).toHaveBeenCalledWith(data);
|
||||
@ -143,7 +117,7 @@ describe('SearchFilterComponent', () => {
|
||||
|
||||
component.onToggleBucket(event, <any> field, <any> query);
|
||||
|
||||
expect(query.checked).toBeFalsy();
|
||||
expect(query.checked).toEqual(false);
|
||||
expect(queryBuilder.removeUserFacetBucket).toHaveBeenCalledWith(field, query);
|
||||
expect(queryBuilder.update).toHaveBeenCalled();
|
||||
});
|
||||
@ -584,7 +558,7 @@ describe('SearchFilterComponent', () => {
|
||||
buckets: new SearchFilterList<FacetFieldBucket>(buckets)
|
||||
};
|
||||
|
||||
expect(component.canResetSelectedBuckets(field)).toBeFalsy();
|
||||
expect(component.canResetSelectedBuckets(field)).toEqual(false);
|
||||
});
|
||||
|
||||
it('should reset selected buckets', () => {
|
||||
@ -602,8 +576,8 @@ describe('SearchFilterComponent', () => {
|
||||
|
||||
component.resetSelectedBuckets(field);
|
||||
|
||||
expect(buckets[0].checked).toBeFalsy();
|
||||
expect(buckets[1].checked).toBeFalsy();
|
||||
expect(buckets[0].checked).toEqual(false);
|
||||
expect(buckets[1].checked).toEqual(false);
|
||||
});
|
||||
|
||||
it('should update query builder upon resetting buckets', () => {
|
||||
@ -643,7 +617,7 @@ describe('SearchFilterComponent', () => {
|
||||
expect(queryBuilder.update).toHaveBeenCalled();
|
||||
|
||||
for (const entry of component.responseFacets[0].buckets.items) {
|
||||
expect(entry.checked).toBeFalsy();
|
||||
expect(entry.checked).toEqual(false);
|
||||
}
|
||||
});
|
||||
|
||||
@ -734,4 +708,270 @@ describe('SearchFilterComponent', () => {
|
||||
expect(component.responseFacets[0].buckets.length).toEqual(1);
|
||||
expect(component.responseFacets[1].buckets.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('widgets', () => {
|
||||
|
||||
it('should have expandable categories', async(() => {
|
||||
fixture.detectChanges();
|
||||
queryBuilder.categories = expandableCategories;
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(1);
|
||||
|
||||
const element: HTMLElement = panels[0].nativeElement;
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toBeTruthy();
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toEqual(false);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not show the disabled widget', async(() => {
|
||||
appConfigService.config.search = { categories: disabledCategories };
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(0);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the widget in expanded mode', async(() => {
|
||||
appConfigService.config.search = { categories: expandedCategories };
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(1);
|
||||
|
||||
const title = fixture.debugElement.query(By.css('.mat-expansion-panel-header-title'));
|
||||
expect(title.nativeElement.innerText.trim()).toBe('Type');
|
||||
|
||||
const element: HTMLElement = panels[0].nativeElement;
|
||||
expect(element.classList.contains('mat-expanded')).toBeTruthy();
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toEqual(false);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the widgets only if configured', async(() => {
|
||||
appConfigService.config.search = { categories: simpleCategories };
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(2);
|
||||
|
||||
const titleElements = fixture.debugElement.queryAll(By.css('.mat-expansion-panel-header-title'));
|
||||
expect(titleElements.map(title => title.nativeElement.innerText.trim())).toEqual(['Name', 'Type']);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be update the search query when name changed', async( async () => {
|
||||
spyOn(queryBuilder, 'update').and.stub();
|
||||
appConfigService.config.search = searchFilter;
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
let panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(6);
|
||||
|
||||
const inputElement = fixture.debugElement.query(By.css('[data-automation-id="expansion-panel-Name"] input'));
|
||||
inputElement.triggerEventHandler('change', { target: { value: '*' } });
|
||||
expect(queryBuilder.update).toHaveBeenCalled();
|
||||
|
||||
queryBuilder.executed.next(<any> mockSearchResult);
|
||||
fixture.detectChanges();
|
||||
|
||||
panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(16);
|
||||
}));
|
||||
|
||||
it('should show the long facet options list with pagination', () => {
|
||||
const panel = '[data-automation-id="expansion-panel-Size facet queries"]';
|
||||
appConfigService.config.search = searchFilter;
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
queryBuilder.executed.next(<any> mockSearchResult);
|
||||
fixture.detectChanges();
|
||||
|
||||
let sizes = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
expect(sizes).toEqual(stepOne);
|
||||
|
||||
let moreButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-MORE"]`));
|
||||
let lessButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-LESS"]`));
|
||||
|
||||
expect(lessButton).toEqual(null);
|
||||
expect(moreButton).toBeDefined();
|
||||
|
||||
moreButton.triggerEventHandler('click', {});
|
||||
fixture.detectChanges();
|
||||
|
||||
sizes = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
expect(sizes).toEqual(stepTwo);
|
||||
|
||||
moreButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-MORE"]`));
|
||||
lessButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-LESS"]`));
|
||||
expect(lessButton).toBeDefined();
|
||||
expect(moreButton).toBeDefined();
|
||||
|
||||
moreButton.triggerEventHandler('click', {});
|
||||
fixture.detectChanges();
|
||||
sizes = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
|
||||
expect(sizes).toEqual(stepThree);
|
||||
|
||||
moreButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-MORE"]`));
|
||||
lessButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-LESS"]`));
|
||||
expect(lessButton).toBeDefined();
|
||||
expect(moreButton).toEqual(null);
|
||||
|
||||
lessButton.triggerEventHandler('click', {});
|
||||
fixture.detectChanges();
|
||||
|
||||
sizes = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
expect(sizes).toEqual(stepTwo);
|
||||
|
||||
moreButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-MORE"]`));
|
||||
lessButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-LESS"]`));
|
||||
expect(lessButton).toBeDefined();
|
||||
expect(moreButton).toBeDefined();
|
||||
|
||||
lessButton.triggerEventHandler('click', {});
|
||||
fixture.detectChanges();
|
||||
|
||||
sizes = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
expect(sizes).toEqual(stepOne);
|
||||
|
||||
moreButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-MORE"]`));
|
||||
lessButton = fixture.debugElement.query(By.css(`${panel} button[title="SEARCH.FILTER.ACTIONS.SHOW-LESS"]`));
|
||||
expect(lessButton).toEqual(null);
|
||||
expect(moreButton).toBeDefined();
|
||||
});
|
||||
|
||||
it('should not show facets if filter is not available', () => {
|
||||
const panel = '[data-automation-id="expansion-panel-Size facet queries"]';
|
||||
const filter = { ...searchFilter };
|
||||
delete filter.facetQueries;
|
||||
|
||||
appConfigService.config.search = filter;
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
queryBuilder.executed.next(<any> mockSearchResult);
|
||||
fixture.detectChanges();
|
||||
|
||||
const facetElement = fixture.debugElement.query(By.css(panel));
|
||||
expect(facetElement).toEqual(null);
|
||||
});
|
||||
|
||||
it('should search the facets options and select it', () => {
|
||||
const panel = '[data-automation-id="expansion-panel-Size facet queries"]';
|
||||
appConfigService.config.search = searchFilter;
|
||||
queryBuilder.resetToDefaults();
|
||||
fixture.detectChanges();
|
||||
queryBuilder.executed.next(<any> mockSearchResult);
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(queryBuilder, 'update').and.stub();
|
||||
spyOn(component, 'selectFacetBucket').and.callThrough();
|
||||
spyOn(component, 'onToggleBucket').and.callThrough();
|
||||
|
||||
const inputElement = fixture.debugElement.query(By.css(`${panel} input`));
|
||||
inputElement.nativeElement.value = 'Extra';
|
||||
inputElement.nativeElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
|
||||
let filteredMenu = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
expect(filteredMenu).toEqual(['Extra Small (10239)']);
|
||||
|
||||
inputElement.nativeElement.value = 'my';
|
||||
inputElement.nativeElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
|
||||
filteredMenu = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
expect(filteredMenu).toEqual(filteredResult);
|
||||
|
||||
const clearButton = fixture.debugElement.query(By.css(`${panel} button`));
|
||||
clearButton.triggerEventHandler('click', {});
|
||||
fixture.detectChanges();
|
||||
|
||||
filteredMenu = getAllMenus(`${panel} mat-checkbox`, fixture);
|
||||
expect(filteredMenu).toEqual(stepOne);
|
||||
|
||||
const firstOption = fixture.debugElement.query(By.css(`${panel} mat-checkbox`));
|
||||
firstOption.triggerEventHandler('change', { checked: true });
|
||||
fixture.detectChanges();
|
||||
|
||||
const checkedOption = fixture.debugElement.query(By.css(`${panel} mat-checkbox.mat-checkbox-checked`));
|
||||
expect(checkedOption.nativeElement.innerText).toEqual('Extra Small (10239)');
|
||||
|
||||
expect(component.onToggleBucket).toHaveBeenCalledTimes(1);
|
||||
expect(component.selectFacetBucket).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should preserve the filter state if other fields edited', () => {
|
||||
const panel1 = '[data-automation-id="expansion-panel-Size facet queries"]';
|
||||
const panel2 = '[data-automation-id="expansion-panel-Type facet queries"]';
|
||||
appConfigService.config.search = searchFilter;
|
||||
queryBuilder.resetToDefaults();
|
||||
fixture.detectChanges();
|
||||
queryBuilder.executed.next(<any> mockSearchResult);
|
||||
fixture.detectChanges();
|
||||
spyOn(queryBuilder, 'update').and.stub();
|
||||
spyOn(component, 'selectFacetBucket').and.callThrough();
|
||||
spyOn(component, 'onToggleBucket').and.callThrough();
|
||||
|
||||
const inputElement = fixture.debugElement.query(By.css(`${panel1} input`));
|
||||
inputElement.nativeElement.value = 'my';
|
||||
inputElement.nativeElement.dispatchEvent(new Event('input'));
|
||||
fixture.detectChanges();
|
||||
|
||||
let filteredMenu = getAllMenus(`${panel1} mat-checkbox`, fixture);
|
||||
expect(filteredMenu).toEqual(filteredResult);
|
||||
|
||||
const firstOption = fixture.debugElement.query(By.css(`${panel1} mat-checkbox`));
|
||||
firstOption.triggerEventHandler('change', { checked: true });
|
||||
fixture.detectChanges();
|
||||
|
||||
let panel1CheckedOption = fixture.debugElement.query(By.css(`${panel1} mat-checkbox.mat-checkbox-checked`));
|
||||
expect(panel1CheckedOption.nativeElement.innerText).toEqual('my1 (806)');
|
||||
|
||||
const panel2Options = fixture.debugElement.query(By.css(`${panel2} mat-checkbox`));
|
||||
panel2Options.triggerEventHandler('change', { checked: true });
|
||||
fixture.detectChanges();
|
||||
|
||||
const panel2CheckedOption = fixture.debugElement.query(By.css(`${panel2} mat-checkbox.mat-checkbox-checked`));
|
||||
expect(panel2CheckedOption.nativeElement.innerText).toEqual('SEARCH.FACET_QUERIES.MIMETYPE (13)');
|
||||
|
||||
filteredMenu = getAllMenus(`${panel1} mat-checkbox`, fixture);
|
||||
expect(filteredMenu).toEqual(filteredResult);
|
||||
|
||||
panel1CheckedOption = fixture.debugElement.query(By.css(`${panel1} mat-checkbox.mat-checkbox-checked`));
|
||||
expect(panel1CheckedOption.nativeElement.innerText).toEqual('my1 (806)');
|
||||
|
||||
expect(component.onToggleBucket).toHaveBeenCalledTimes(2);
|
||||
expect(component.selectFacetBucket).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
export function getAllMenus(regex, fixture: ComponentFixture<any>): string[] {
|
||||
const elements = fixture.debugElement.queryAll(By.css(regex));
|
||||
return Array.from(elements).map(element => element.nativeElement.innerText);
|
||||
}
|
||||
|
@ -0,0 +1,96 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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 { sizeOptions, stepOne, stepThree } from '../../../mock';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { SearchRadioComponent } from './search-radio.component';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
|
||||
describe('SearchRadioComponent', () => {
|
||||
let fixture: ComponentFixture<SearchRadioComponent>;
|
||||
let component: SearchRadioComponent;
|
||||
|
||||
setupTestBed({
|
||||
imports: [ ContentTestingModule ]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SearchRadioComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
describe('Pagination', () => {
|
||||
it('should show 5 items when pageSize not defined', () => {
|
||||
component.id = 'checklist';
|
||||
component.context = <any> {
|
||||
queryFragments: {
|
||||
'checklist': 'query'
|
||||
},
|
||||
update() {}
|
||||
};
|
||||
component.settings = <any> { options: sizeOptions };
|
||||
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const optionElements = fixture.debugElement.queryAll(By.css('mat-radio-button'));
|
||||
expect(optionElements.length).toEqual(5);
|
||||
const labels = Array.from(optionElements).map(element => element.nativeElement.innerText);
|
||||
expect(labels).toEqual(stepOne);
|
||||
});
|
||||
|
||||
it('should show all items when pageSize is high', () => {
|
||||
component.id = 'checklist';
|
||||
component.context = <any> {
|
||||
queryFragments: {
|
||||
'checklist': 'query'
|
||||
},
|
||||
update() {}
|
||||
};
|
||||
component.settings = <any> { pageSize: 15, options: sizeOptions };
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const optionElements = fixture.debugElement.queryAll(By.css('mat-radio-button'));
|
||||
expect(optionElements.length).toEqual(13);
|
||||
const labels = Array.from(optionElements).map(element => element.nativeElement.innerText);
|
||||
expect(labels).toEqual(stepThree);
|
||||
});
|
||||
});
|
||||
|
||||
it('should able to check the radio button', () => {
|
||||
component.id = 'checklist';
|
||||
component.context = <any> {
|
||||
queryFragments: {
|
||||
'checklist': 'query'
|
||||
},
|
||||
update: () => {}
|
||||
};
|
||||
component.settings = <any> { options: sizeOptions };
|
||||
spyOn(component.context, 'update').and.stub();
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const optionElements = fixture.debugElement.query(By.css('mat-radio-button'));
|
||||
optionElements.triggerEventHandler('change', { checked: true });
|
||||
|
||||
expect(component.context.update).toHaveBeenCalled();
|
||||
expect(component.context.queryFragments[component.id]).toBe(sizeOptions[0].value);
|
||||
});
|
||||
});
|
@ -16,13 +16,21 @@
|
||||
*/
|
||||
|
||||
import { SearchTextComponent } from './search-text.component';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
describe('SearchTextComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<SearchTextComponent>;
|
||||
let component: SearchTextComponent;
|
||||
|
||||
setupTestBed({
|
||||
imports: [ ContentTestingModule ]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
component = new SearchTextComponent();
|
||||
fixture = TestBed.createComponent(SearchTextComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.id = 'text';
|
||||
component.settings = {
|
||||
'pattern': "cm:name:'(.*?)'",
|
||||
@ -38,7 +46,7 @@ describe('SearchTextComponent', () => {
|
||||
|
||||
it('should parse value from the context at startup', () => {
|
||||
component.context.queryFragments[component.id] = "cm:name:'secret.pdf'";
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.value).toEqual('secret.pdf');
|
||||
});
|
||||
@ -46,7 +54,7 @@ describe('SearchTextComponent', () => {
|
||||
it('should not parse value when pattern not defined', () => {
|
||||
component.settings.pattern = null;
|
||||
component.context.queryFragments[component.id] = "cm:name:'secret.pdf'";
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.value).toEqual('');
|
||||
});
|
||||
@ -84,4 +92,25 @@ describe('SearchTextComponent', () => {
|
||||
expect(component.value).toBe('');
|
||||
expect(component.context.queryFragments[component.id]).toBe('');
|
||||
});
|
||||
|
||||
it('should show the custom/default name', async(() => {
|
||||
component.context.queryFragments[component.id] = "cm:name:'secret.pdf'";
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.value).toEqual('secret.pdf');
|
||||
const input = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix input');
|
||||
expect(input.value).toEqual('secret.pdf');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be able to reset by clicking clear button', async(() => {
|
||||
component.context.queryFragments[component.id] = "cm:name:'secret.pdf'";
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const clearElement = fixture.debugElement.nativeElement.querySelector('button');
|
||||
clearElement.click();
|
||||
expect(component.value).toBe('');
|
||||
expect(component.context.queryFragments[component.id]).toBe('');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user