import { browser , Key } from 'protractor' ; import { imageCompare } from '../common/image-compare' ; import { SelectListPage } from './select-list.po.spec' ; describe ( 'Select List Tests' , ( ) => { let page = new SelectListPage ( ) ; beforeAll ( async ( ) => { await page . getPage ( ) ; } ) ; it ( 'should have correct initial state' , async ( ) => { expect ( await page . getItemCount ( ) ) . toBe ( 20 ) ; expect ( await page . getSelection ( ) ) . toBe ( '' ) ; expect ( await imageCompare ( 'select-list-initial' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should select an item' , async ( ) => { await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . reset ( ) ; } ) ; it ( 'should select one item at a time' , async ( ) => { await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . selectItem ( 9 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Sara Valdez' ) ; await page . reset ( ) ; } ) ; it ( 'should retain selection after search' , async ( ) => { await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . search ( 'lin' ) ; expect ( await page . getItemCount ( ) ) . toBe ( 2 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . reset ( ) ; } ) ; it ( 'should only have one tabbable item' , async ( ) => { expect ( await page . getTabbableItemCount ( ) ) . toBe ( 1 ) ; await page . reset ( ) ; } ) ; it ( 'should make the first item intially tabbable' , async ( ) => { expect ( await page . getTabbableItem ( ) ) . toBe ( 'Linnie Dixon' ) ; await page . reset ( ) ; } ) ; it ( 'should change the tabbable item on selection' , async ( ) => { expect ( await page . getTabbableItem ( ) ) . toBe ( 'Linnie Dixon' ) ; await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . reset ( ) ; } ) ; it ( 'should change the tabbable item when arrow keys are pressed' , async ( ) => { await page . getPage ( ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Linnie Dixon' ) ; await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Margaret Douglas' ) ; browser . actions ( ) . sendKeys ( Key . ARROW_DOWN ) . perform ( ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Lulu Chandler' ) ; browser . actions ( ) . sendKeys ( Key . ARROW_UP ) . perform ( ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . reset ( ) ; } ) ; it ( 'should select an item when multiple select is enabled' , async ( ) => { await page . toggleButton . click ( ) ; await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . reset ( ) ; } ) ; it ( 'should select multiple items at a time when multiple select is enabled' , async ( ) => { await page . toggleButton . click ( ) ; await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . selectItem ( 9 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas, Sara Valdez' ) ; await page . reset ( ) ; } ) ; it ( 'should retain selection after search when multiple select is enabled' , async ( ) => { await page . toggleButton . click ( ) ; await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . search ( 'lin' ) ; expect ( await page . getItemCount ( ) ) . toBe ( 2 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . reset ( ) ; } ) ; it ( 'should only have one tabbable item when multiple select is enabled' , async ( ) => { await page . toggleButton . click ( ) ; expect ( await page . getTabbableItemCount ( ) ) . toBe ( 1 ) ; await page . reset ( ) ; } ) ; it ( 'should make the first item intially tabbable when multiple select is enabled' , async ( ) => { await page . toggleButton . click ( ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Linnie Dixon' ) ; await page . reset ( ) ; } ) ; it ( 'should change the tabbable item on selection when multiple select is enabled' , async ( ) => { await page . toggleButton . click ( ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Linnie Dixon' ) ; await page . selectItem ( 10 ) ; expect ( await page . getSelection ( ) ) . toBe ( 'Margaret Douglas' ) ; expect ( await page . getTabbableItem ( ) ) . toBe ( 'Margaret Douglas' ) ; await page . reset ( ) ; } ) ; } ) ;