import { Key } from 'protractor' ; import { imageCompare } from '../common/image-compare' ; import { FloatLabelPage } from './float-label.po.spec' ; describe ( 'Float Label' , ( ) => { let page ; beforeEach ( async ( ) => { page = new FloatLabelPage ( ) ; await page . getPage ( ) ; } ) ; describe ( 'with mode = input' , ( ) => { it ( 'should be hidden on focus' , async ( ) => { expect ( page . usernameLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; await page . usernameInput . click ( ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; await page . locationInput . click ( ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; expect ( await imageCompare ( 'float-label-initial' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should be visible while input has text' , async ( ) => { await page . usernameInput . click ( ) ; await page . usernameInput . sendKeys ( 'A' ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . locationInput . click ( ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . usernameInput . click ( ) ; await page . usernameInput . sendKeys ( Key . BACK_SPACE ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; expect ( await imageCompare ( 'float-label-raised' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should become visible when `raised` becomes true' , async ( ) => { expect ( page . locationLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; await page . locationButton . click ( ) ; expect ( page . locationLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; } ) ; it ( 'should be visible for an input with initial value' , async ( ) => { expect ( await page . initialInput . getAttribute ( 'value' ) ) . toBe ( 'A' ) ; expect ( page . initialLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . initialInput . click ( ) ; await page . initialInput . sendKeys ( Key . BACK_SPACE ) ; expect ( page . initialLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; } ) ; } ) ; describe ( 'with mode = focus' , ( ) => { beforeEach ( async ( ) => { await page . modeFocusButton . click ( ) ; } ) ; it ( 'should be visible on focus' , async ( ) => { expect ( page . usernameLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; await page . usernameInput . click ( ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . locationInput . click ( ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; } ) ; it ( 'should be visible while input has text' , async ( ) => { await page . usernameInput . click ( ) ; await page . usernameInput . sendKeys ( 'A' ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . locationInput . click ( ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . usernameInput . click ( ) ; await page . usernameInput . sendKeys ( Key . BACK_SPACE ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . locationInput . click ( ) ; expect ( page . usernameLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; } ) ; it ( 'should become visible when `raised` becomes true' , async ( ) => { expect ( page . locationLabel . getAttribute ( 'class' ) ) . not . toContain ( 'ux-float-label-raised' ) ; await page . locationButton . click ( ) ; expect ( page . locationLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; } ) ; it ( 'should be visible for an input with initial value' , async ( ) => { expect ( await page . initialInput . getAttribute ( 'value' ) ) . toBe ( 'A' ) ; expect ( page . initialLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; await page . initialInput . click ( ) ; await page . initialInput . sendKeys ( Key . BACK_SPACE ) ; expect ( page . initialLabel . getAttribute ( 'class' ) ) . toContain ( 'ux-float-label-raised' ) ; } ) ; } ) ; } ) ;