import { browser , Key } from 'protractor' ; import { imageCompare } from '../../common/image-compare' ; import { TooltipsPage } from './tooltips.po.spec' ; describe ( 'Tooltips' , ( ) => { let page = new TooltipsPage ( ) ; beforeAll ( async ( ) => { await page . getPage ( ) ; } ) ; it ( 'should have correct initial states' , async ( ) => { expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( false ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( false ) ; expect ( await imageCompare ( 'tooltip-initial' ) ) . toEqual ( 0 ) ; await page . reset ( ) ; } ) ; it ( 'should show tooltip on mouse enter' , async ( ) => { await browser . actions ( ) . mouseMove ( page . showTooltipBtn ) . perform ( ) ; expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( true ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; expect ( await imageCompare ( 'tooltip-open' ) ) . toEqual ( 0 ) ; await page . reset ( ) ; } ) ; it ( 'should hide tooltip on mouse leave' , async ( ) => { await browser . actions ( ) . mouseMove ( page . showTooltipBtn ) . perform ( ) ; expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( true ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; await browser . actions ( ) . mouseMove ( page . placementBottomBtn ) . perform ( ) ; expect ( await page . cdkOverlayContainer . isPresent ( ) ) . toBe ( true ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( false ) ; await page . reset ( ) ; } ) ; it ( 'should be able to programmatically show the tooltip' , async ( ) => { await page . showTooltip ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; await page . reset ( ) ; } ) ; it ( 'should be able to programmatically hide the tooltip' , async ( ) => { await page . showTooltip ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; await page . hideTooltip ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( false ) ; await page . reset ( ) ; } ) ; it ( 'should be able to programmatically toggle the tooltip' , async ( ) => { await page . toggleTooltip ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; await page . toggleTooltip ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( false ) ; await page . toggleTooltip ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; await page . reset ( ) ; } ) ; it ( 'should be able to position the tooltip' , async ( ) => { expect ( await page . getTooltipPlacement ( ) ) . toBe ( 'top' ) ; await page . placementRightBtn . click ( ) ; expect ( await page . getTooltipPlacement ( ) ) . toBe ( 'right' ) ; await page . placementBottomBtn . click ( ) ; expect ( await page . getTooltipPlacement ( ) ) . toBe ( 'bottom' ) ; await page . placementLeftBtn . click ( ) ; expect ( await page . getTooltipPlacement ( ) ) . toBe ( 'left' ) ; await page . placementTopBtn . click ( ) ; expect ( await page . getTooltipPlacement ( ) ) . toBe ( 'top' ) ; await page . reset ( ) ; } ) ; it ( 'should show the correct content' , async ( ) => { expect ( await page . getTooltipContent ( ) ) . toBe ( 'Some content here' ) ; await page . reset ( ) ; } ) ; it ( 'should allow a custom class' , async ( ) => { expect ( await page . tooltipHasClass ( 'my-custom-class' ) ) . toBe ( false ) ; await page . customClasssBtn . click ( ) ; expect ( await page . tooltipHasClass ( 'my-custom-class' ) ) . toBe ( true ) ; await page . reset ( ) ; } ) ; it ( 'should allow a TemplateRef to be used' , async ( ) => { expect ( await page . getTooltipContent ( ) ) . toBe ( 'Some content here' ) ; await page . templateRefBtn . click ( ) ; expect ( await page . getTooltipContent ( ) ) . toBe ( 'My Template Here' ) ; await page . reset ( ) ; } ) ; it ( 'should show the tooltip on button focus' , async ( ) => { await page . getPage ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( false ) ; await browser . actions ( ) . sendKeys ( Key . TAB ) . perform ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; await page . reset ( ) ; } ) ; it ( 'should hide the tooltip on button blur' , async ( ) => { await page . getPage ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( false ) ; await browser . actions ( ) . sendKeys ( Key . TAB ) . perform ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( true ) ; await browser . actions ( ) . sendKeys ( Key . TAB ) . perform ( ) ; expect ( await page . tooltip . isPresent ( ) ) . toBe ( false ) ; await page . reset ( ) ; } ) ; } ) ;