package Ġcom . z ach k li pp . compose worksheet . ui Ċ Ċ import Ġandroid . view . KeyEvent . ACTION _ DOWN Ċ import Ġandroid . view . KeyEvent . ACTION _ UP Ċ import Ġandroid . view . KeyEvent . KEYCODE _ DEL Ċ import Ġandroid . view . KeyEvent . KEYCODE _ DP AD _ DOWN Ċ import Ġandroid . view . KeyEvent . KEYCODE _ DP AD _ UP Ċ import Ġandroidx . compose . runtime . Composable Ċ import Ġandroidx . compose . runtime . Stable Ċ import Ġandroidx . compose . runtime . getValue Ċ import Ġandroidx . compose . runtime . mutable State Of Ċ import Ġandroidx . compose . runtime . setValue Ċ import Ġandroidx . compose . ui . Modifier Ċ import Ġandroidx . compose . ui . focus . Focus Direction Ċ import Ġandroidx . compose . ui . input . key . KeyEvent Ċ import Ġandroidx . compose . ui . input . key . Native KeyEvent Ċ import Ġandroidx . compose . ui . semantics . Semantics Properties Ċ import Ġandroidx . compose . ui . test . Experimental Test Api Ċ import Ġandroidx . compose . ui . test . Semantics Matcher Ċ import Ġandroidx . compose . ui . test . Semantics Matcher . Companion . expect Value Ċ import Ġandroidx . compose . ui . test . assert Ċ import Ġandroidx . compose . ui . test . assert Content Description Equals Ċ import Ġandroidx . compose . ui . test . assertIs Displayed Ċ import Ġandroidx . compose . ui . test . assert Text Equals Ċ import Ġandroidx . compose . ui . test . junit 4 . create Compose Rule Ċ import Ġandroidx . compose . ui . test . on Node With Text Ċ import Ġandroidx . compose . ui . test . perform KeyPress Ċ import Ġandroidx . compose . ui . test . perform TextInput Ċ import Ġandroidx . compose . ui . test . perform TextInput Selection Ċ import Ġandroidx . compose . ui . text . Text Range Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . z ach k li pp . compose worksheet . Value Ċ import Ġcom . z ach k li pp . compose worksheet . Work sheet . Error Ċ import Ġcom . z ach k li pp . compose worksheet . Work sheet . Row Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ @ Suppress (" Test FunctionName ") Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠWork sheet Row Editor Test Ġ{ ĊĊĠ Ġ@ get : Rule Ġval Ġrule Ġ= Ġcreate Compose Rule () ĊĠ Ġprivate Ġval Ġis Editable Ġ= ĠSem antics Matcher . key Is Defined ( Semantics Properties . Editable Text ) ĊĊĠ Ġ@ Test Ġfun Ġdisplays _ row _ data _ and _ semantics () Ġ{ ĊĠĠĠ Ġval Ġrow Ġ= ĠTest Row (). apply Ġ{ ĊĠĠĠĠĠ Ġinput Ġ= Ġ" hello Ġworld " ĊĠĠĠĠĠ Ġresult Ġ= ĠValue . Integer ( 4 2 ) ĊĠĠĠĠĠ Ġerrors Ġ= ĠlistOf ( Error (" o ops ie ", Ġ 0 .. 0 )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġrule . setContent Ġ{ ĊĠĠĠĠĠ ĠWork sheet Row Editor ( row ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. assertIs Displayed () ĊĠĠĠĠĠ Ġ. assert Text Equals (" hello Ġworld ") ĊĠĠĠĠĠ Ġ. assert ( expect Value ( Semantics Properties . Error , Ġ" o ops ie ")) ĊĠĠĠ Ġrule . on Node With Text (" = 4 2 "). assertIs Displayed () ĊĠĠĠĠĠ Ġ. assert Content Description Equals (" result Ġis Ġ 4 2 ") ĊĠĠĠ Ġrule . on Node With Text (" o ops ie "). assertIs Displayed () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġedits _ invoke _ event _ handler () Ġ{ ĊĠĠĠ Ġval Ġrow Ġ= ĠTest Row () ĊĠĠĠ Ġrule . setContent Ġ{ ĊĠĠĠĠĠ ĠWork sheet Row Editor ( row ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform TextInput (" hello ") ĊĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. assertIs Displayed () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġarrow _ keys _ request _ previous _ and _ next focus () Ġ{ ĊĠĠĠ Ġval Ġrow Ġ= ĠTest Row () ĊĠĠĠ Ġval Ġfocus Moves Ġ= Ġmutable ListOf < Focus Direction >() ĊĠĠĠ Ġrule . setContent Ġ{ ĊĠĠĠĠĠ ĠWork sheet Row Editor ( row , Ġon Move Focus Ġ= Ġ{ Ġfocus Moves Ġ+= Ġit Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ DOWN , ĠKEY CODE _ DP AD _ DOWN ))) ĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ UP , ĠKEY CODE _ DP AD _ DOWN ))) ĊĠĠĠ ĠassertEquals ( listOf ( Focus Direction . Down ), Ġfocus Moves ) ĊĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ DOWN , ĠKEY CODE _ DP AD _ UP ))) ĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ UP , ĠKEY CODE _ DP AD _ UP ))) ĊĠĠĠ ĠassertEquals ( listOf ( Focus Direction . Up ), Ġfocus Moves ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġback space _ in _ empty _ row _ re moves () Ġ{ ĊĠĠĠ Ġval Ġrow Ġ= ĠTest Row () ĊĠĠĠ Ġvar Ġremove Count Ġ= Ġ 0 ĊĠĠĠ Ġrule . setContent Ġ{ ĊĠĠĠĠĠ ĠWork sheet Row Editor ( row , Ġon Remove Line Ġ= Ġ{ Ġremove Count ++ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ DOWN , ĠKEY CODE _ DEL ))) ĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ UP , ĠKEY CODE _ DEL ))) ĊĠĠĠ ĠassertEquals ( 1 , Ġremove Count ) ĊĠ Ġ} ĊĊĠ Ġ@ Opt In ( Experimental Test Api :: class ) ĊĠ Ġ@ Test Ġfun Ġback space _ in _ none mpty _ row _ does nt _ remove () Ġ{ ĊĠĠĠ Ġval Ġrow Ġ= ĠTest Row (). apply Ġ{ ĊĠĠĠĠĠ Ġinput Ġ= Ġ" hello " ĊĠĠĠ Ġ} ĊĠĠĠ Ġvar Ġremove Count Ġ= Ġ 0 ĊĠĠĠ Ġrule . setContent Ġ{ ĊĠĠĠĠĠ ĠWork sheet Row Editor ( row , Ġon Remove Line Ġ= Ġ{ Ġremove Count ++ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠEnsure Ġthe Ġcursor Ġis Ġat Ġthe Ġbeginning Ġof Ġthe Ġline . ĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform TextInput Selection ( Text Range . Zero ) ĊĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ DOWN , ĠKEY CODE _ DEL ))) ĊĠĠĠ Ġrule . on Node ( is Editable ) ĊĠĠĠĠĠ Ġ. perform KeyPress ( KeyEvent ( Native KeyEvent ( ACTION _ UP , ĠKEY CODE _ DEL ))) ĊĠĠĠ ĠassertEquals ( 0 , Ġremove Count ) ĊĠ Ġ} ĊĊĠ Ġ@ Stable ĊĠ Ġprivate Ġclass ĠTest Row ( override Ġval Ġid : ĠAny Ġ= ĠUnit ) Ġ: ĠRow Ġ{ ĊĠĠĠ Ġoverride Ġvar Ġinput : ĠString Ġby Ġmutable State Of ("") ĊĠĠĠ Ġoverride Ġvar Ġerrors : ĠList < Error > Ġby Ġmutable State Of ( emptyList ()) ĊĠĠĠ Ġoverride Ġvar Ġresult : ĠValue ? Ġby Ġmutable State Of ( null ) ĊĠ Ġ} ĊĊĠ Ġ@ Composable Ġprivate Ġfun ĠWork sheet Row Editor ( ĊĠĠĠ Ġrow : ĠRow , ĊĠĠĠ Ġformat Result : Ġ( Value ?) Ġ-> ĠString Ġ= Ġ{ Ġit . toString () Ġ}, ĊĠĠĠ Ġon Input Change : Ġ( String ) Ġ-> ĠUnit Ġ= Ġ{}, ĊĠĠĠ Ġon Add Line : Ġ() Ġ-> ĠUnit Ġ= Ġ{}, ĊĠĠĠ Ġon Remove Line : Ġ() Ġ-> ĠUnit Ġ= Ġ{}, ĊĠĠĠ Ġon Move Focus : Ġ( Focus Direction ) Ġ-> ĠUnit Ġ= Ġ{}, ĊĠ Ġ) Ġ{ ĊĠĠĠ ĠWork sheet Row Editor ( ĊĠĠĠĠĠ Ġrow , ĊĠĠĠĠĠ Ġformat Result , ĊĠĠĠĠĠ Ġon Input Change , ĊĠĠĠĠĠ Ġon Add Line , ĊĠĠĠĠĠ Ġon Remove Line , ĊĠĠĠĠĠ Ġon Move Focus , ĊĠĠĠĠĠ Ġmodifier Ġ= ĠModifier ĊĠĠĠ Ġ) ĊĠ Ġ} Ċ }