import { Key } from 'protractor' ; import { imageCompare } from '../../common/image-compare' ; import { InfiniteScrollFullscreenPage } from './infinite-scroll-fullscreen.po.spec' ; describe ( 'Infinite Scroll (Fullscreen) Tests' , ( ) => { let page ; beforeEach ( async ( ) => { page = new InfiniteScrollFullscreenPage ( ) ; await page . getPage ( ) ; } ) ; it ( 'should have correct initial states' , async ( ) => { expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 20 ) ; expect ( await page . confirmLoadMoreIsVisible ( ) ) . toBeFalsy ( ) ; expect ( await page . confirmLoadOnScrollIsChecked ( ) ) . toBeTruthy ( ) ; expect ( await page . confirmPageSizeButtonIsDisabled ( 'up' ) ) . toBeFalsy ( ) ; expect ( await page . confirmPageSizeButtonIsDisabled ( 'down' ) ) . toBeFalsy ( ) ; expect ( await page . confirmValueIsInvalid ( ) ) . toBeFalsy ( ) ; expect ( await imageCompare ( 'infinite-scroll-fullscreen-initial' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should display correct text for employee details' , async ( ) => { for ( let i = 0 ; i < 20 ; i ++ ) { expect ( await page . getEmployeeText ( i ) ) . toBe ( 'employee_' + i ) ; } for ( let i = 0 ; i < 20 ; i ++ ) { expect ( await page . getDepartmentText ( i ) ) . toBe ( '(department_' + i + ')' ) ; } for ( let i = 0 ; i < 20 ; i ++ ) { expect ( await page . getEmailText ( i ) ) . toBe ( 'employee_' + i + '@business.com' ) ; } for ( let i = 0 ; i < 20 ; i ++ ) { expect ( await page . getEmployeeIDNumber ( i ) ) . toBe ( i . toString ( ) ) ; } } ) ; it ( 'should react to clicking on the loadOnScroll checkbox' , async ( ) => { await page . clickOnLoadOnScroll ( ) ; expect ( await page . confirmLoadOnScrollIsChecked ( ) ) . toBeFalsy ( ) ; await page . clickOnLoadOnScroll ( ) ; expect ( await page . confirmLoadOnScrollIsChecked ( ) ) . toBeTruthy ( ) ; } ) ; it ( 'should display more employees when the LOAD MORE button is clicked' , async ( ) => { await page . clickOnLoadOnScroll ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 20 ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 20 ) ; await page . loadMoreButton . click ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 40 ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 40 ) ; await page . loadMoreButton . click ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 60 ) ; } ) ; it ( 'should display the LOAD MORE button when appropriate' , async ( ) => { await page . clickOnLoadOnScroll ( ) ; expect ( await page . confirmLoadMoreIsVisible ( ) ) . toBeTruthy ( ) ; await page . clickOnLoadOnScroll ( ) ; expect ( await page . confirmLoadMoreIsVisible ( ) ) . toBeFalsy ( ) ; await page . clickOnLoadOnScroll ( ) ; await page . clickOnPageSize ( ) ; await page . getPageSize ( ) . clear ( ) ; await page . getPageSize ( ) . sendKeys ( '110' ) ; expect ( await page . confirmLoadMoreIsVisible ( ) ) . toBeTruthy ( ) ; await page . loadMoreButton . click ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 111 ) ; expect ( await page . confirmLoadMoreIsVisible ( ) ) . toBeFalsy ( ) ; } ) ; it ( 'should display more employees when scrolling down' , async ( ) => { await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 40 ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 60 ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 80 ) ; } ) ; it ( 'should be possible to change the page size' , async ( ) => { await page . clickOnIncrementPageSize ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 21 ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 42 ) ; await page . clickOnDecrementPageSize ( ) ; await page . clickOnDecrementPageSize ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 19 ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 38 ) ; await page . clickOnPageSize ( ) ; await page . getPageSize ( ) . clear ( ) ; await page . getPageSize ( ) . sendKeys ( '39' ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 39 ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 78 ) ; } ) ; it ( 'should be possible to filter employees using entered text' , async ( ) => { await page . filter . click ( ) ; await page . filter . sendKeys ( '-' ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 0 ) ; await page . filter . clear ( ) ; await page . filter . sendKeys ( 'Y' ) ; expect ( await page . getEmployeeText ( 0 ) ) . toBe ( 'employee_0' ) ; expect ( await page . getEmployeeText ( 1 ) ) . toBe ( 'employee_1' ) ; expect ( await page . getEmployeeText ( 19 ) ) . toBe ( 'employee_19' ) ; await page . filter . clear ( ) ; await page . filter . sendKeys ( 'e' ) ; expect ( await page . getEmployeeText ( 0 ) ) . toBe ( 'employee_0' ) ; expect ( await page . getEmployeeText ( 1 ) ) . toBe ( 'employee_1' ) ; expect ( await page . getEmployeeText ( 19 ) ) . toBe ( 'employee_19' ) ; await page . filter . clear ( ) ; await page . filter . sendKeys ( '_1' ) ; expect ( await page . getEmployeeText ( 0 ) ) . toBe ( 'employee_1' ) ; expect ( await page . getEmployeeText ( 1 ) ) . toBe ( 'employee_10' ) ; expect ( await page . getEmployeeText ( 19 ) ) . toBe ( 'employee_108' ) ; } ) ; it ( 'should be possible to us filtering and page sizing simultaneously' , async ( ) => { await page . filter . sendKeys ( '0' ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 20 ) ; expect ( await page . getEmployeeText ( 0 ) ) . toBe ( 'employee_0' ) ; expect ( await page . getEmployeeText ( 1 ) ) . toBe ( 'employee_10' ) ; expect ( await page . getEmployeeText ( 19 ) ) . toBe ( 'employee_109' ) ; await page . hoverOverLastEmployee ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 21 ) ; expect ( await page . getEmployeeText ( 20 ) ) . toBe ( 'employee_110' ) ; await page . clickOnLoadOnScroll ( ) ; await page . clickOnPageSize ( ) ; await page . getPageSize ( ) . clear ( ) ; await page . getPageSize ( ) . sendKeys ( '2' ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 2 ) ; expect ( await page . getEmployeeText ( 0 ) ) . toBe ( 'employee_0' ) ; expect ( await page . getEmployeeText ( 1 ) ) . toBe ( 'employee_10' ) ; await page . loadMoreButton . click ( ) ; expect ( await page . getNumberOfEmployees ( ) ) . toEqual ( 4 ) ; expect ( await page . getEmployeeText ( 2 ) ) . toBe ( 'employee_20' ) ; expect ( await page . getEmployeeText ( 3 ) ) . toBe ( 'employee_30' ) ; } ) ; } ) ;