import { SelectionPage } from './selection.po.spec' ; describe ( 'Selection Tests' , ( ) => { let page ; beforeEach ( async ( ) => { page = new SelectionPage ( ) ; await page . getPage ( ) ; } ) ; it ( 'should have correct initial state' , async ( ) => { page . rows . forEach ( async ( row ) => expect ( await row . isPresent ( ) ) . toBeTruthy ( ) ) ; page . rows . forEach ( async ( row ) => expect ( await page . getRowButtonTabIndex ( row ) ) . toBe ( '-1' ) ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeFalsy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; } ) ; it ( 'should select a row on click (simple)' , async ( ) => { await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should toggle a row on double click (simple)' , async ( ) => { await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; } ) ; it ( 'should allow multiple click selections (simple)' , async ( ) => { await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . clickSelectRow ( page . row1 ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should allow select all (simple)' , async ( ) => { await page . selectAll ( ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeTruthy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true }, { "name": "Document 4", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should allow deselect all (simple)' , async ( ) => { await page . selectAll ( ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeTruthy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true }, { "name": "Document 4", "author": "John Smith", "selected": true } ]' ) ; await page . deselectAll ( ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeFalsy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; } ) ; it ( 'should toggle the state using spacebar (simple)' , async ( ) => { expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . spacebar ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; } ) ; it ( 'should allow keyboard navigation (simple)' , async ( ) => { expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . arrowDown ( ) ; await page . spacebar ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true } ]' ) ; await page . arrowUp ( ) ; await page . spacebar ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 2", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should allow keyboard navigation (row-alt)' , async ( ) => { await page . setRowAltMode ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row2 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row3 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' , '1. initial click' ) ; await page . arrowDown ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row2 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row3 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 2", "author": "John Smith", "selected": true } ]' , '2. down' ) ; await page . arrowDown ( true ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row2 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row3 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true } ]' , '3. shift+down' ) ; await page . arrowDown ( false , true ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row2 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row3 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true } ]' , '4. ctrl+down' ) ; await page . spacebar ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row2 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row3 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true }, { "name": "Document 4", "author": "John Smith", "selected": true } ]' , '5. space' ) ; await page . arrowDown ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row2 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row3 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 4", "author": "John Smith", "selected": true } ]' , '6. down' ) ; } ) ; it ( 'should select a row on click (row)' , async ( ) => { await page . setRowMode ( ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should not toggle a row on double click (row)' , async ( ) => { await page . setRowMode ( ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should not allow multiple click selections (row)' , async ( ) => { await page . setRowMode ( ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . clickSelectRow ( page . row1 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 2", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should allow select all (row)' , async ( ) => { await page . setRowMode ( ) ; await page . selectAll ( ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeTruthy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true }, { "name": "Document 4", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should allow deselect all (row)' , async ( ) => { await page . setRowMode ( ) ; await page . selectAll ( ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeTruthy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true }, { "name": "Document 4", "author": "John Smith", "selected": true } ]' ) ; await page . deselectAll ( ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeFalsy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; } ) ; it ( 'should toggle the state using spacebar (row)' , async ( ) => { await page . setRowMode ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . spacebar ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; } ) ; it ( 'should allow keyboard navigation (row)' , async ( ) => { await page . setRowMode ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . arrowDown ( ) ; await page . spacebar ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeFalsy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 2", "author": "John Smith", "selected": true } ]' ) ; await page . arrowUp ( ) ; await page . spacebar ( ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should allow multiple click selection with ctrl key down (row)' , async ( ) => { await page . setRowMode ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . clickSelectRow ( page . row1 , false , true ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . isRowSelected ( page . row1 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should allow group click selection with shift key down (row)' , async ( ) => { await page . setRowMode ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; await page . clickSelectRow ( page . row3 , true ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeTruthy ( ) ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true }, { "name": "Document 4", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should restore tabindex on focused rows' , async ( ) => { expect < any > ( page . getRowButtonTabIndex ( page . row0 ) ) . toBe ( '-1' ) ; await page . clickSelectRow ( page . row0 ) ; expect < any > ( page . getRowButtonTabIndex ( page . row0 ) ) . toBe ( '5' ) ; await page . clickSelectRow ( page . row1 ) ; expect < any > ( page . getRowButtonTabIndex ( page . row0 ) ) . toBe ( '-1' ) ; expect < any > ( page . getRowButtonTabIndex ( page . row1 ) ) . toBe ( '5' ) ; } ) ; it ( 'should allow individual items to be disabled' , async ( ) => { await page . addDisabledItem ( ) ; await page . clickSelectRow ( page . row4 ) ; expect ( await page . isRowSelected ( page . row4 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[]' ) ; await page . clickSelectRow ( page . row0 ) ; expect ( await page . isRowSelected ( page . row0 ) ) . toBeTruthy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true } ]' ) ; } ) ; it ( 'should not allow select all on individually disabled items' , async ( ) => { await page . addDisabledItem ( ) ; await page . selectAll ( ) ; page . rows . forEach ( async ( row ) => expect ( await page . isRowSelected ( row ) ) . toBeTruthy ( ) ) ; expect ( await page . isRowSelected ( page . row4 ) ) . toBeFalsy ( ) ; expect ( await page . getSelection ( ) ) . toBe ( '[ { "name": "Document 1", "author": "John Smith", "selected": true }, { "name": "Document 2", "author": "John Smith", "selected": true }, { "name": "Document 3", "author": "John Smith", "selected": true }, { "name": "Document 4", "author": "John Smith", "selected": true } ]' ) ; } ) ; } ) ;