Skip to content

Commit

Permalink
test(state): refactor test to generate state #7025
Browse files Browse the repository at this point in the history
  • Loading branch information
hanastasov committed Jun 24, 2020
1 parent 9b9a715 commit 01bce6d
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('IgxGridState - input properties #grid', () => {
});

it('getState should return corect JSON string', () => {
const initialGridState = '{"columns":[{"pinned":true,"sortable":true,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"testCss","headerGroupClasses":"","maxWidth":"300px","groupable":false,"movable":true,"hidden":false,"dataType":"number","hasSummary":false,"field":"ProductID","width":"150px","header":"Product ID","resizable":true,"searchable":false},{"pinned":false,"sortable":true,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","maxWidth":"300px","groupable":true,"movable":true,"hidden":false,"dataType":"string","hasSummary":false,"field":"ProductName","width":"150px","header":"Prodyct Name","resizable":true,"searchable":true,"selectable":false},{"pinned":false,"sortable":false,"filterable":true,"editable":true,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","maxWidth":"300px","groupable":false,"movable":false,"hidden":false,"dataType":"boolean","hasSummary":true,"field":"InStock","width":"140px","header":"In Stock","resizable":true,"searchable":true},{"pinned":false,"sortable":true,"filterable":false,"editable":true,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","maxWidth":"300px","groupable":true,"movable":false,"hidden":false,"dataType":"date","hasSummary":false,"field":"OrderDate","width":"110px","header":"Date ordered","resizable":false,"searchable":true}],"filtering":{"filteringOperands":[],"operator":0},"sorting":[],"groupBy":{"expressions":[],"expansion":[],"defaultExpanded":true},"paging":{"index":0,"recordsPerPage":15,"metadata":{"countPages":1,"countRecords":10,"error":0}},"cellSelection":[],"rowSelection":[],"columnSelection":[],"rowPinning":[],"expansion":[]}';
const initialGridState = '{"columns":[{"pinned":true,"sortable":true,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"testCss","headerGroupClasses":"","maxWidth":"300px","groupable":false,"movable":true,"hidden":false,"dataType":"number","hasSummary":false,"field":"ProductID","width":"150px","header":"Product ID","resizable":true,"searchable":false},{"pinned":false,"sortable":true,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","maxWidth":"300px","groupable":true,"movable":true,"hidden":false,"dataType":"string","hasSummary":false,"field":"ProductName","width":"150px","header":"Prodyct Name","resizable":true,"searchable":true,"selectable":false},{"pinned":false,"sortable":false,"filterable":true,"editable":true,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","maxWidth":"300px","groupable":false,"movable":false,"hidden":false,"dataType":"boolean","hasSummary":true,"field":"InStock","width":"140px","header":"In Stock","resizable":true,"searchable":true},{"pinned":false,"sortable":true,"filterable":false,"editable":true,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","maxWidth":"300px","groupable":true,"movable":false,"hidden":false,"dataType":"date","hasSummary":false,"field":"OrderDate","width":"110px","header":"Date ordered","resizable":false,"searchable":true}],"filtering":{"filteringOperands":[],"operator":0},"advancedFiltering":{},"sorting":[],"groupBy":{"expressions":[],"expansion":[],"defaultExpanded":true},"paging":{"index":0,"recordsPerPage":15,"metadata":{"countPages":1,"countRecords":10,"error":0}},"cellSelection":[],"rowSelection":[],"columnSelection":[],"rowPinning":[],"expansion":[]}';
const fix = TestBed.createComponent(IgxGridStateComponent);
fix.detectChanges();

Expand Down Expand Up @@ -131,7 +131,6 @@ describe('IgxGridState - input properties #grid', () => {
HelperFunctions.verifyGroupingExpressions(groupBy, gridState);
HelperFunctions.verifyGroupingExpansion(groupByExpansion, gridState.groupBy);
HelperFunctions.verifyFilteringExpressions(filtering, gridState);
HelperFunctions.verifyAdvancedFilteringExpressions(advancedFiltering, gridState);
});

it('getState should return corect IGridState object when options are not default', () => {
Expand Down Expand Up @@ -474,7 +473,7 @@ describe('IgxGridState - input properties #grid', () => {
const state = fix.componentInstance.state;
// tslint:disable-next-line:max-line-length
const advFilteringState = '{"advancedFiltering":{"filteringOperands":[{"fieldName":"InStock","condition":{"name":"true","isUnary":true,"iconName":"is_true"},"searchVal":null,"ignoreCase":true},{"fieldName":"ProductID","condition":{"name":"greaterThan","isUnary":false,"iconName":"greater_than"},"searchVal":"3","ignoreCase":true}],"operator":0,"type":1}}';
const initialState = '{}';
const initialState = '{"advancedFiltering":{}}';

let gridState = state.getState(true, 'advancedFiltering');
expect(gridState).toBe(initialState);
Expand All @@ -493,7 +492,7 @@ describe('IgxGridState - input properties #grid', () => {
const state = fix.componentInstance.state;
// tslint:disable-next-line:max-line-length
const advFilteringState = '{"advancedFiltering":{"filteringOperands":[{"fieldName":"InStock","condition":{"name":"true","isUnary":true,"iconName":"is_true"},"searchVal":null,"ignoreCase":true},{"fieldName":"ProductID","condition":{"name":"greaterThan","isUnary":false,"iconName":"greater_than"},"searchVal":"3","ignoreCase":true}],"operator":0,"type":1}}';
const initialState = '{}';
const initialState = '{"advancedFiltering":{}}';
const advFilteringStateObject = JSON.parse(advFilteringState);

let gridState = state.getState(true, 'advancedFiltering');
Expand Down
8 changes: 6 additions & 2 deletions projects/igniteui-angular/src/lib/grids/state.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,17 @@ namespace Features {

public getFeatureState(context: IgxGridStateDirective): IGridState {
const filteringState = context.currGrid.advancedFilteringExpressionsTree;
let advancedFiltering: any;
if (filteringState) {
delete filteringState.owner;
for (const item of filteringState.filteringOperands) {
delete (item as IFilteringExpressionsTree).owner;
}
advancedFiltering = filteringState;
} else {
advancedFiltering = {};
}
return { advancedFiltering: filteringState };
return { advancedFiltering: advancedFiltering };
}

public restoreFeatureState(context: IgxGridStateDirective, state: FilteringExpressionsTree): void {
Expand Down Expand Up @@ -520,6 +524,7 @@ namespace Features {
}

public restoreFeatureState(context: IgxGridStateDirective, state: string[]): void {
context.currGrid.deselectAllColumns();
context.currGrid.selectColumns(state);
}
}
Expand Down Expand Up @@ -613,7 +618,6 @@ namespace Features {
grid = grid.parent;
}
return grid.hgridAPI.getParentRowId(childGrid);
// return (childRow.hGridApi as IgxHierarchicalGridAPIService).getParentRowId(childGrid);
}
}

Expand Down
Loading

0 comments on commit 01bce6d

Please sign in to comment.