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);
|
||||
});
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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