@@ -2,7 +2,6 @@ import { TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
2
2
import { SortingDirection } from '../../data-operations/sorting-expression.interface' ;
3
3
import { IgxTreeGridComponent } from './tree-grid.component' ;
4
4
import { IgxGridCell , IgxTreeGridModule } from './public_api' ;
5
- import { IgxTreeGridCellComponent } from './tree-cell.component' ;
6
5
import {
7
6
IgxTreeGridSimpleComponent ,
8
7
IgxTreeGridCellSelectionComponent ,
@@ -11,7 +10,8 @@ import {
11
10
IgxTreeGridRowEditingTransactionComponent ,
12
11
IgxTreeGridCustomRowSelectorsComponent ,
13
12
IgxTreeGridCascadingSelectionComponent ,
14
- IgxTreeGridCascadingSelectionTransactionComponent
13
+ IgxTreeGridCascadingSelectionTransactionComponent ,
14
+ IgxTreeGridPrimaryForeignKeyCascadeSelectionComponent
15
15
} from '../../test-utils/tree-grid-components.spec' ;
16
16
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
17
17
import {
@@ -53,7 +53,8 @@ describe('IgxTreeGrid - Selection #tGrid', () => {
53
53
IgxTreeGridRowEditingTransactionComponent ,
54
54
IgxTreeGridCustomRowSelectorsComponent ,
55
55
IgxTreeGridCascadingSelectionComponent ,
56
- IgxTreeGridCascadingSelectionTransactionComponent
56
+ IgxTreeGridCascadingSelectionTransactionComponent ,
57
+ IgxTreeGridPrimaryForeignKeyCascadeSelectionComponent
57
58
] ,
58
59
imports : [ IgxTreeGridModule , NoopAnimationsModule , IgxGridSelectionModule , IgxActionStripModule ]
59
60
} )
@@ -1040,7 +1041,7 @@ describe('IgxTreeGrid - Selection #tGrid', () => {
1040
1041
} ) ) ;
1041
1042
} ) ;
1042
1043
1043
- describe ( 'Cascading Row Selection' , ( ) => {
1044
+ describe ( 'Cascading Row Selection - Child collection data ' , ( ) => {
1044
1045
beforeEach ( fakeAsync ( ( ) => {
1045
1046
fix = TestBed . createComponent ( IgxTreeGridCascadingSelectionComponent ) ;
1046
1047
fix . detectChanges ( ) ;
@@ -1755,6 +1756,185 @@ describe('IgxTreeGrid - Selection #tGrid', () => {
1755
1756
} ) ;
1756
1757
} ) ;
1757
1758
1759
+ describe ( 'Cascading Row Selection - Primary/Foreign key data' , ( ) => {
1760
+ beforeEach ( fakeAsync ( ( ) => {
1761
+ fix = TestBed . createComponent ( IgxTreeGridPrimaryForeignKeyCascadeSelectionComponent ) ;
1762
+ fix . detectChanges ( ) ;
1763
+ treeGrid = fix . componentInstance . treeGrid ;
1764
+ actionStrip = fix . componentInstance . actionStrip ;
1765
+ } ) ) ;
1766
+
1767
+ it ( `Filter out all children for a certain parent, except for one. Select it.
1768
+ Parent should also become selected. Clear filters. Parent should become in
1769
+ indeterminate state as there are non-selected children.` , async ( ) => {
1770
+ treeGrid . filter ( 'ID' , 475 , IgxNumberFilteringOperand . instance ( ) . condition ( 'equals' ) ) ;
1771
+ await wait ( 100 ) ;
1772
+ fix . detectChanges ( ) ;
1773
+
1774
+ treeGrid . selectRows ( [ 475 ] , true ) ;
1775
+ await wait ( 100 ) ;
1776
+ fix . detectChanges ( ) ;
1777
+
1778
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 2 ) ;
1779
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , true , true ) ;
1780
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 1 , true , true ) ;
1781
+
1782
+ treeGrid . clearFilter ( ) ;
1783
+ await wait ( 100 ) ;
1784
+ fix . detectChanges ( ) ;
1785
+
1786
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 1 ) ;
1787
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , null ) ;
1788
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 1 , true , true ) ;
1789
+ } ) ;
1790
+
1791
+ it ( `If there is only one selected leaf row for a particular parent and we filter it out parent's checkbox state -> non-selected.
1792
+ All non-direct parents’ checkbox states should be set correctly as well` , async ( ) => {
1793
+ treeGrid . selectRows ( [ 711 ] , true ) ;
1794
+ fix . detectChanges ( ) ;
1795
+
1796
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 1 ) ;
1797
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , null ) ;
1798
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , false , null ) ;
1799
+
1800
+ treeGrid . filter ( 'ID' , 711 , IgxNumberFilteringOperand . instance ( ) . condition ( 'doesNotEqual' ) ) ;
1801
+ fix . detectChanges ( ) ;
1802
+
1803
+ await wait ( 100 ) ;
1804
+ fix . detectChanges ( ) ;
1805
+
1806
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 0 ) ;
1807
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , false ) ;
1808
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , false , false ) ;
1809
+ } ) ;
1810
+
1811
+ it ( `If there is only one non-selected row for a particular parent and we filter it out parent's checkbox state -> selected.
1812
+ All non-direct parents’ checkbox states should be set correctly as well` , async ( ) => {
1813
+ treeGrid . selectRows ( [ 711 , 998 ] , true ) ;
1814
+ fix . detectChanges ( ) ;
1815
+
1816
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 2 ) ;
1817
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , null ) ;
1818
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , false , null ) ;
1819
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 4 , true , true ) ;
1820
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 5 , true , true ) ;
1821
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 6 , false , false ) ;
1822
+
1823
+ treeGrid . filter ( 'ID' , 299 , IgxNumberFilteringOperand . instance ( ) . condition ( 'doesNotEqual' ) ) ;
1824
+ fix . detectChanges ( ) ;
1825
+
1826
+ await wait ( 200 ) ;
1827
+ fix . detectChanges ( ) ;
1828
+
1829
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 3 ) ;
1830
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , null ) ;
1831
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , true , true ) ;
1832
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 4 , true , true ) ;
1833
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 5 , true , true ) ;
1834
+ } ) ;
1835
+
1836
+ it ( 'After adding a new child row to a selected parent its checkbox state SHOULD be indeterminate.' , async ( ) => {
1837
+ treeGrid . selectRows ( [ 847 ] , true ) ;
1838
+ fix . detectChanges ( ) ;
1839
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 2 ) ;
1840
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 8 , true , true ) ;
1841
+ TreeGridFunctions . verifyHeaderCheckboxSelection ( fix , null ) ;
1842
+
1843
+ const row = treeGrid . gridAPI . get_row_by_index ( 8 ) ;
1844
+ actionStrip . show ( row ) ;
1845
+ fix . detectChanges ( ) ;
1846
+
1847
+ // add new child through the UI
1848
+ const editActions = fix . debugElement . queryAll ( By . css ( `igx-grid-action-button` ) ) ;
1849
+ const addChildBtn = editActions [ 2 ] . componentInstance ;
1850
+ addChildBtn . actionClick . emit ( ) ;
1851
+ fix . detectChanges ( ) ;
1852
+ endTransition ( ) ;
1853
+
1854
+ const addRow = treeGrid . gridAPI . get_row_by_index ( 9 ) ;
1855
+ expect ( addRow . addRowUI ) . toBeTrue ( ) ;
1856
+
1857
+ treeGrid . gridAPI . crudService . endEdit ( true ) ;
1858
+ await wait ( 100 ) ;
1859
+ fix . detectChanges ( ) ;
1860
+ const addedRow = treeGrid . gridAPI . get_row_by_index ( 10 ) ;
1861
+ expect ( addedRow . rowData . Name ) . toBe ( undefined ) ;
1862
+
1863
+ TreeGridFunctions . verifyDataRowsSelection ( fix , [ 9 ] , true ) ;
1864
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 8 , false , null ) ;
1865
+ TreeGridFunctions . verifyHeaderCheckboxSelection ( fix , null ) ;
1866
+ } ) ;
1867
+
1868
+ it ( 'If parent and its children are selected and we delete a child, parent SHOULD be still selected.' , async ( ) => {
1869
+ treeGrid . selectRows ( [ 147 ] , true ) ;
1870
+ fix . detectChanges ( ) ;
1871
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 7 ) ;
1872
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , true , true ) ;
1873
+ TreeGridFunctions . verifyHeaderCheckboxSelection ( fix , null ) ;
1874
+
1875
+ expect ( treeGrid . dataRowList . length ) . toBe ( 10 ) ;
1876
+
1877
+ const childRow = treeGrid . gridAPI . get_row_by_index ( 5 ) ;
1878
+ actionStrip . show ( childRow ) ;
1879
+ fix . detectChanges ( ) ;
1880
+
1881
+ // delete the child through the UI
1882
+ const editActions = fix . debugElement . queryAll ( By . css ( `igx-grid-action-button` ) ) ;
1883
+ const deleteBtn = editActions [ 2 ] . componentInstance ;
1884
+ deleteBtn . actionClick . emit ( ) ;
1885
+ fix . detectChanges ( ) ;
1886
+
1887
+ await wait ( 100 ) ;
1888
+ fix . detectChanges ( ) ;
1889
+
1890
+ expect ( treeGrid . dataRowList . length ) . toBe ( 9 ) ;
1891
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 6 ) ;
1892
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , true , true ) ;
1893
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , true , true ) ;
1894
+ TreeGridFunctions . verifyHeaderCheckboxSelection ( fix , null ) ;
1895
+ } ) ;
1896
+
1897
+ it ( 'If we delete the only selected child of a parent row, the parent checkbox state SHOULD be deselected' , async ( ) => {
1898
+ treeGrid . selectRows ( [ 711 ] , true ) ;
1899
+ fix . detectChanges ( ) ;
1900
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 1 ) ;
1901
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , false , null ) ;
1902
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , null ) ;
1903
+ TreeGridFunctions . verifyHeaderCheckboxSelection ( fix , null ) ;
1904
+
1905
+ expect ( treeGrid . dataRowList . length ) . toBe ( 10 ) ;
1906
+
1907
+ // delete the child through the API
1908
+ const childRow = treeGrid . gridAPI . get_row_by_index ( 4 ) ;
1909
+ childRow . delete ( ) ;
1910
+ fix . detectChanges ( ) ;
1911
+
1912
+ await wait ( 100 ) ;
1913
+ fix . detectChanges ( ) ;
1914
+
1915
+ expect ( treeGrid . dataRowList . length ) . toBe ( 9 ) ;
1916
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 0 ) ;
1917
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , false , false ) ;
1918
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , false ) ;
1919
+ TreeGridFunctions . verifyHeaderCheckboxSelection ( fix , false ) ;
1920
+ } ) ;
1921
+
1922
+ it ( `Set nested child row, that has its own children, as initially selected and verify
1923
+ that both direct and indirect parent's checkboxes are set in the correct state.` , fakeAsync ( ( ) => {
1924
+ treeGrid . selectedRows = [ 317 ] ;
1925
+ fix . detectChanges ( ) ;
1926
+ tick ( 100 ) ;
1927
+ fix . detectChanges ( ) ;
1928
+
1929
+ expect ( getVisibleSelectedRows ( fix ) . length ) . toBe ( 4 ) ;
1930
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 0 , false , null ) ;
1931
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 3 , true , true ) ;
1932
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 4 , true , true ) ;
1933
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 5 , true , true ) ;
1934
+ TreeGridFunctions . verifyRowByIndexSelectionAndCheckboxState ( fix , 6 , true , true ) ;
1935
+ } ) ) ;
1936
+ } ) ;
1937
+
1758
1938
describe ( 'Cascading Row Selection with Transaction' , ( ) => {
1759
1939
beforeEach ( fakeAsync ( ( ) => {
1760
1940
fix = TestBed . createComponent ( IgxTreeGridCascadingSelectionTransactionComponent ) ;
0 commit comments