import { $ , browser , Key } from 'protractor' ; import { imageCompare } from '../../common/image-compare' ; import { PopoverPage } from './popover.po.spec' ; describe ( 'Popover' , ( ) => { let page ; beforeEach ( async ( ) => { page = new PopoverPage ( ) ; await page . getPage ( ) ; } ) ; it ( 'should have correct initial states' , async ( ) => { expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( false ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( false ) ; expect ( await imageCompare ( 'popover-initial' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should show popover on mouse click' , async ( ) => { await page . showPopoverBtn . click ( ) ; expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( true ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; expect ( await imageCompare ( 'popover-open' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should hide popover on mouse click' , async ( ) => { await page . showPopoverBtn . click ( ) ; expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( true ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; await page . showPopoverBtn . click ( ) ; expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( true ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( false ) ; } ) ; it ( 'should be able to programmatically show the popover' , async ( ) => { await page . showPopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; } ) ; it ( 'should be able to programmatically hide the popover' , async ( ) => { await page . showPopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; await page . hidePopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( false ) ; } ) ; it ( 'should be able to programmatically toggle the popover' , async ( ) => { await page . togglePopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; await page . togglePopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( false ) ; await page . togglePopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; } ) ; it ( 'should be able to position the popover' , async ( ) => { expect ( await page . getPopoverPlacement ( ) ) . toBe ( 'top' ) ; await page . placementRightBtn . click ( ) ; expect ( await page . getPopoverPlacement ( ) ) . toBe ( 'right' ) ; await page . placementBottomBtn . click ( ) ; expect ( await page . getPopoverPlacement ( ) ) . toBe ( 'bottom' ) ; await page . placementLeftBtn . click ( ) ; expect ( await page . getPopoverPlacement ( ) ) . toBe ( 'left' ) ; await page . placementTopBtn . click ( ) ; expect ( await page . getPopoverPlacement ( ) ) . toBe ( 'top' ) ; } ) ; it ( 'should show the correct content' , async ( ) => { expect ( await page . getPopoverContent ( ) ) . toBe ( 'Some content here' ) ; } ) ; it ( 'should allow a custom class' , async ( ) => { expect ( await page . popoverHasClass ( 'my-custom-class' ) ) . toBe ( false ) ; await page . customClasssBtn . click ( ) ; expect ( await page . popoverHasClass ( 'my-custom-class' ) ) . toBe ( true ) ; expect ( await imageCompare ( 'popover-custom-class' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should allow a TemplateRef to be used' , async ( ) => { expect ( await page . getPopoverContent ( ) ) . toBe ( 'Some content here' ) ; await page . templateRefBtn . click ( ) ; expect ( await page . getPopoverContent ( ) ) . toBe ( 'My Template Here' ) ; } ) ; it ( 'should show a title when specified' , async ( ) => { await page . showPopover ( ) ; expect ( await page . popoverTitle . isPresent ( ) ) . toBe ( false ) ; await page . setTitleBtn . click ( ) ; await page . showPopover ( ) ; expect ( await page . popoverTitle . isPresent ( ) ) . toBe ( true ) ; expect ( await page . popoverTitle . getAttribute ( 'textContent' ) ) . toBe ( 'Popover Title' ) ; } ) ; it ( 'should close when escape is pressed' , async ( ) => { await page . showPopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; await browser . actions ( ) . sendKeys ( Key . ESCAPE ) . perform ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( false ) ; } ) ; it ( 'should close when a click outside occurs' , async ( ) => { await page . showPopover ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( true ) ; await browser . actions ( ) . click ( $ ( 'body' ) ) . perform ( ) ; expect ( await page . popover . isPresent ( ) ) . toBe ( false ) ; } ) ; } ) ;