import { TestPage } from "./lforms_testpage.po" ; import TestUtil from "./util" ; import { browser , logging , element , by , WebElementPromise , ExpectedConditions } from 'protractor' ; import { protractor } from 'protractor/built/ptor' ; describe ( 'formula' , function ( ) { let tp ; let ff ; let LForms = ( global as any ) . LForms ; beforeAll ( async ( ) => { await browser . waitForAngularEnabled ( false ) ; tp = new TestPage ( ) ; ff = tp . USSGFHTVertical ; } ) ; it ( 'Two BMI formulas should both work' , function ( ) { tp . LoadForm . openUSSGFHTVertical ( ) ; TestUtil . sendKeys ( ff . height1 , "70" ) ; browser . sleep ( 5000 ) ; expect ( TestUtil . getAttribute ( ff . bmi1 , 'value' ) ) . toBe ( "" ) ; TestUtil . sendKeys ( ff . weight1 , "170" ) ; expect ( TestUtil . getAttribute ( ff . bmi1 , 'value' ) ) . toBe ( "24.39" ) ; ff . height1 . clear ( ) ; TestUtil . sendKeys ( ff . height1 , "80" ) ; expect ( TestUtil . getAttribute ( ff . bmi1 , 'value' ) ) . toBe ( "18.68" ) ; ff . heightUnit1 . click ( ) ; ff . heightUnit1 . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . heightUnit1 . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . heightUnit1 . sendKeys ( protractor . Key . TAB ) ; ff . height1 . clear ( ) ; TestUtil . sendKeys ( ff . height1 , "170" ) ; expect ( TestUtil . getAttribute ( ff . bmi1 , 'value' ) ) . toBe ( "26.68" ) ; ff . weightUnit1 . click ( ) ; ff . weightUnit1 . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . weightUnit1 . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . weightUnit1 . sendKeys ( protractor . Key . TAB ) ; ff . weight1 . clear ( ) ; TestUtil . sendKeys ( ff . weight1 , "80" ) ; expect ( TestUtil . getAttribute ( ff . bmi1 , 'value' ) ) . toBe ( "27.68" ) ; TestUtil . sendKeys ( ff . height2 , "70" ) ; expect ( ff . bmi2 . getAttribute ( 'value' ) ) . toBe ( "" ) ; TestUtil . sendKeys ( ff . weight2 , "170" ) ; expect ( ff . bmi2 . getAttribute ( 'value' ) ) . toBe ( "24.39" ) ; ff . height2 . clear ( ) ; TestUtil . sendKeys ( ff . height2 , "80" ) ; expect ( ff . bmi2 . getAttribute ( 'value' ) ) . toBe ( "18.68" ) ; } ) ; it ( 'should work with calculation method having skip logic disabled sources' , function ( ) { tp . openBaseTestPage ( ) ; tp . loadFromTestData ( 'skip-logic-calculation-method.json' ) ; let sklSource = element ( by . id ( 'SKL-CONTROL/1' ) ) ; let sklTarget = element ( by . id ( 'A-ITEM/1' ) ) ; let noSklItem = element ( by . id ( 'B-ITEM/1' ) ) ; let totalScore = element ( by . id ( 'TS/1' ) ) ; expect ( sklSource . isDisplayed ( ) ) . toBe ( true ) ; expect ( TestUtil . getAttribute ( sklSource , 'value' ) ) . toBe ( '' ) ; TestUtil . waitForElementNotPresent ( sklTarget ) ; expect ( noSklItem . isDisplayed ( ) ) . toBe ( true ) ; expect ( TestUtil . getAttribute ( noSklItem , 'value' ) ) . toBe ( '' ) ; expect ( totalScore . isDisplayed ( ) ) . toBe ( true ) ; expect ( TestUtil . getAttribute ( totalScore , 'value' ) ) . toBe ( '0' ) ; noSklItem . click ( ) ; noSklItem . sendKeys ( protractor . Key . ARROW_DOWN ) ; noSklItem . sendKeys ( protractor . Key . ARROW_DOWN ) ; noSklItem . sendKeys ( protractor . Key . ENTER ) ; expect ( TestUtil . getAttribute ( noSklItem , 'value' ) ) . toBe ( '1. B2 - 10' ) ; expect ( TestUtil . getAttribute ( totalScore , 'value' ) ) . toBe ( '10' ) ; sklSource . click ( ) ; sklSource . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklSource . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklSource . sendKeys ( protractor . Key . ENTER ) ; expect ( sklTarget . isDisplayed ( ) ) . toBe ( true ) ; expect ( TestUtil . getAttribute ( totalScore , 'value' ) ) . toBe ( '10' ) ; sklTarget . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklTarget . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklTarget . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklTarget . sendKeys ( protractor . Key . ENTER ) ; expect ( TestUtil . getAttribute ( sklTarget , 'value' ) ) . toBe ( '2. A3 - 20' ) ; expect ( TestUtil . getAttribute ( totalScore , 'value' ) ) . toBe ( '30' ) ; sklSource . click ( ) ; sklSource . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklSource . sendKeys ( protractor . Key . ENTER ) ; TestUtil . waitForElementNotPresent ( sklTarget ) ; expect ( TestUtil . getAttribute ( totalScore , 'value' ) ) . toBe ( '10' ) ; sklSource . click ( ) ; sklSource . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklSource . sendKeys ( protractor . Key . ARROW_DOWN ) ; sklSource . sendKeys ( protractor . Key . ENTER ) ; expect ( sklTarget . isDisplayed ( ) ) . toBe ( true ) ; expect ( TestUtil . getAttribute ( sklTarget , 'value' ) ) . toBe ( '2. A3 - 20' ) ; expect ( TestUtil . getAttribute ( totalScore , 'value' ) ) . toBe ( '30' ) ; } ) ; } ) ;