package Ġcom . for s var ir . time tracker Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroidx . compose . ui . test . assert Count Equals Ċ import Ġandroidx . compose . ui . test . junit 4 . Android Compose Test Rule Ċ import Ġandroidx . compose . ui . test . junit 4 . create Android Compose Rule Ċ import Ġandroidx . compose . ui . test . on All Nodes With Text Ċ import Ġandroidx . test . ext . junit . rules . Activity Scenario Rule Ċ import Ġcom . for s var ir . time tracker . control . Current Activity Screen Controller Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . k oin . core . context . Global Context Ċ Ċ class ĠCurrent Activity Transition Tests Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġmain Activity Rule Ġ= Ġcreate Android Compose Rule < MainActivity >() ĊĠĠĠ Ġprivate Ġval Ġcontext : ĠContext Ġ= ĠGlobal Context . get (). get () ĊĠĠĠ Ġprivate Ġval Ġidle Activity Name Ġ= Ġcontext . getString ( R . string . Activity Idle ) ĊĠĠĠ Ġprivate Ġval Ġtrav elling Activity Name Ġ= Ġcontext . getString ( R . string . Activity Tr av elling ) ĊĠĠĠ Ġprivate Ġval Ġsleep ing Activity Name Ġ= Ġcontext . getString ( R . string . Activity Sleep ing ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġselecting New Activity Changes () Ġ{ ĊĠĠĠĠĠĠĠ Ġlaunch Current Activity Screen ( main Activity Rule ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsetCurrent Activity ( sleep ing Activity Name ) ĊĠĠĠĠĠĠĠ Ġ} Ġverify Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Activity Is ( sleep ing Activity Name ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcurrent Activity Pers ists Through Orientation Change () Ġ{ ĊĠĠĠĠĠĠĠ Ġlaunch Current Activity Screen ( main Activity Rule ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsetCurrent Activity ( sleep ing Activity Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġorient ate Land scape () ĊĠĠĠĠĠĠĠ Ġ} Ġverify Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Activity Is ( sleep ing Activity Name ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġchanging Activity Add sTo Previous History () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġinitial Node Count Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġlaunch Current Activity Screen ( main Activity Rule ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate To Activity History Screen () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinitial Node Count Ġ= Ġmain Activity Rule . on All Nodes With Text ( tr av elling Activity Name ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. fetch Semantics Nodes ( at Least One Root Required Ġ= Ġfalse ). size ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate To Current Activity Screen () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsetCurrent Activity ( tr av elling Activity Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsetCurrent Activity ( sleep ing Activity Name ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate To Activity History Screen () ĊĠĠĠĠĠĠĠ Ġ} Ġverify Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmain Activity Rule . on All Nodes With Text ( tr av elling Activity Name ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. assert Count Equals ( initial Node Count Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġchanging Activity Through Unknown Not Tracked On Previous History () Ġ{ ĊĠĠĠĠĠĠĠ Ġlaunch Current Activity Screen ( main Activity Rule ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate To Current Activity Screen () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsetCurrent Activity ( idle Activity Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsetCurrent Activity ( sleep ing Activity Name ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate To Activity History Screen () ĊĠĠĠĠĠĠĠ Ġ} Ġverify Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmain Activity Rule . on All Nodes With Text ( idle Activity Name ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. assert Count Equals ( 0 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġlaunch Current Activity Screen ( ĊĠĠĠĠĠĠĠ Ġrule : ĠAndroid Compose Test Rule < Activity Scenario Rule < MainActivity >, ĠMainActivity >, ĊĠĠĠĠĠĠĠ Ġblock : ĠCurrent Activity Screen Controller . () Ġ-> ĠUnit ĊĠĠĠ Ġ): ĠCurrent Activity Screen Controller Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠCurrent Activity Screen Controller ( rule ). apply ( block ) ĊĠĠĠ Ġ} Ċ }