import { TestPage } from "./lforms_testpage.po" ; import { RxTerms } from "./rxterms.po" ; import TestUtil from "./util" ; import { browser , logging , element , by , WebElementPromise , ExpectedConditions } from 'protractor' ; import { protractor } from 'protractor/built/ptor' ; describe ( 'autocomp list' , function ( ) { let tp ; let ff ; let LForms = ( global as any ) . LForms ; beforeAll ( async ( ) => { await browser . waitForAngularEnabled ( false ) ; tp = new TestPage ( ) ; ff = tp . Autocomp ; } ) ; it ( 'should not be visible when the form loads' , function ( ) { tp . LoadForm . openUSSGFHTVertical ( ) ; expect ( ff . searchResults . isDisplayed ( ) ) . toBeFalsy ( ) ; } ) ; it ( 'should be visible after the user clicks in a field' , function ( ) { ff . listField . click ( ) ; browser . wait ( function ( ) { return ff . searchResults . isDisplayed ( ) ; } , tp . WAIT_TIMEOUT_2 ) ; expect ( ff . searchResults . isDisplayed ( ) ) . toBeTruthy ( ) ; } ) ; it ( 'should work with multiple-select fields' , function ( ) { expect ( ff . raceField . isDisplayed ( ) ) . toBeTruthy ( ) ; expect ( browser . driver . executeScript ( 'return typeof jQuery(document.getElementById("/54126-8/54134-2/1/1"))[0].autocomp' ) ) . toBe ( 'object' ) ; } ) ; it ( 'should interoperate with score rules' , function ( ) { tp . LoadForm . openGlasgowForm ( ) ; browser . wait ( function ( ) { return ff . eyeField . isDisplayed ( ) ; } , tp . WAIT_TIMEOUT_2 ) ; ff . eyeField . click ( ) ; browser . wait ( function ( ) { return ff . searchResults . isDisplayed ( ) ; } , tp . WAIT_TIMEOUT_2 ) ; expect ( TestUtil . getAttribute ( ff . scoreField , 'value' ) ) . toEqual ( '0' ) ; element ( by . css ( '#searchResults li:first-child' ) ) . click ( ) ; ff . scoreField . click ( ) ; expect ( TestUtil . getAttribute ( ff . scoreField , 'value' ) ) . toEqual ( '1' ) ; ff . eyeField . click ( ) ; ff . eyeField . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . eyeField . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . eyeField . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . eyeField . sendKeys ( protractor . Key . TAB ) ; expect ( TestUtil . getAttribute ( ff . eyeField , 'value' ) ) . toBe ( "3. Eye opening to verbal command - 3" ) ; expect ( TestUtil . getAttribute ( ff . scoreField , 'value' ) ) . toEqual ( '3' ) ; ff . eyeField . click ( ) ; ff . eyeField . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . eyeField . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . eyeField . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . eyeField . sendKeys ( protractor . Key . ARROW_DOWN ) ; ff . eyeField . sendKeys ( protractor . Key . TAB ) ; expect ( TestUtil . getAttribute ( ff . eyeField , 'value' ) ) . toBe ( "4. Eyes open spontaneously - 4" ) ; expect ( TestUtil . getAttribute ( ff . scoreField , 'value' ) ) . toEqual ( '4' ) ; } ) ; it ( 'should receive default values set via defaultAnswer' , function ( ) { tp . LoadForm . openFullFeaturedForm ( ) ; expect ( TestUtil . getAttribute ( tp . FullFeaturedForm . cneField , 'value' ) ) . toEqual ( 'Answer 2' ) ; } ) ; it ( 'should set column headers when specified' , function ( ) { tp . LoadForm . openHL7GeneticPanel ( ) ; var kindField = tp . HL7GeneticPanel . kindOfMutations ; browser . wait ( function ( ) { return kindField . isDisplayed ( ) ; } , tp . WAIT_TIMEOUT_2 ) ; kindField . click ( ) ; kindField . sendKeys ( protractor . Key . ARROW_DOWN ) ; kindField . sendKeys ( protractor . Key . TAB ) ; var varIDField = tp . HL7GeneticPanel . variantID ; browser . wait ( function ( ) { return varIDField . isDisplayed ( ) ; } , tp . WAIT_TIMEOUT_2 ) ; varIDField . click ( ) ; varIDField . sendKeys ( 'ar' ) ; var searchRes = tp . Autocomp . searchResults ; var EC = protractor . ExpectedConditions ; browser . wait ( function ( ) { return searchRes . isDisplayed ( ) ; } , tp . WAIT_TIMEOUT_2 ) ; let result = element ( by . css ( '#searchResults th:first-child' ) ) ; expect ( result . getText ( ) ) . toBe ( 'Variant ID <a>' ) ; } ) ; it ( 'should autofill lists when there is just one item' , function ( ) { tp . LoadForm . openRxTerms ( ) ; var rxterms = new RxTerms ( ) ; tp . Autocomp . helpers . autocompPickFirst ( rxterms . drugName , 'AZELEX' ) ; expect ( TestUtil . getAttribute ( rxterms . strengthAndForm , 'value' ) ) . toEqual ( '20% Cream' ) ; } ) ; it ( 'should not display SeqNum on answers that one of them has a numeric value' , function ( ) { tp . LoadForm . openFullFeaturedForm ( ) ; var numericAnswer = element ( by . id ( '/numeric_answer/1' ) ) ; TestUtil . scrollIntoView ( numericAnswer ) ; numericAnswer . click ( ) ; expect ( element ( by . css ( '#searchResults #completionOptions ul li:first-child' ) ) . getText ( ) ) . toBe ( '1' ) ; expect ( element ( by . css ( '#searchResults #completionOptions ul li:nth-child(2)' ) ) . getText ( ) ) . toBe ( 'Answer 2' ) ; expect ( element ( by . css ( '#searchResults #completionOptions ul li:nth-child(3)' ) ) . getText ( ) ) . toBe ( 'Answer 3' ) ; var textAnswer = element ( by . id ( '/type9/1' ) ) ; textAnswer . click ( ) ; expect ( element ( by . css ( '#searchResults #completionOptions ul li:first-child' ) ) . getText ( ) ) . toBe ( '1:  Answer 1' ) ; expect ( element ( by . css ( '#searchResults #completionOptions ul li:nth-child(2)' ) ) . getText ( ) ) . toBe ( '2:  Answer 2' ) ; expect ( element ( by . css ( '#searchResults #completionOptions ul li:nth-child(3)' ) ) . getText ( ) ) . toBe ( '3:  Answer 3' ) ; } ) ; } ) ;