package Ġcom . squareup . workflow . ui Ċ Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . squareup . workflow . Snapshot Ċ import Ġcom . squareup . workflow . Workflow Host Ċ import Ġcom . squareup . workflow . Workflow Host . Rendering And Snapshot Ċ import Ġkotlinx . coroutines . Dispatch ers . Un conf ined Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . Job Ċ import Ġkotlinx . coroutines . channels . Channel Ċ import Ġkotlinx . coroutines . channels . Channel . Factory . UN LIMIT ED Ċ import Ġkotlinx . coroutines . channels . consume Each Ċ import Ġkotlinx . coroutines . flow . Flow Ċ import Ġkotlinx . coroutines . flow . empty Flow Ċ import Ġkotlinx . coroutines . flow . flow Ċ import Ġorg . junit . Test Ċ Ċ @ Use Experimental ( Experimental Workflow Ui :: class , ĠExperimental Cor outines Api :: class ) Ċ class ĠWorkflow Runner ViewModel Test Ġ{ ĊĊĠ Ġ@ Suppress (" Remove Red undant Spread Operator ") ĊĠ Ġprivate Ġval Ġview Registry Ġ= ĠView Registry (* empty Array < View Binding <* >> ()) ĊĊĠ Ġ@ Test Ġfun Ġhost Started L az ily On Render ings Subscription () Ġ{ ĊĠĠĠ Ġvar Ġstarted Ġ= Ġfalse ĊĠĠĠ Ġval Ġhost Ġ= Ġobject Ġ: ĠWorkflow Host < Nothing , ĠUnit > Ġ{ ĊĠĠĠĠĠ Ġoverride Ġval Ġrender ings And Snapshots : ĠFlow < Rendering And Snapshot < Unit >> Ġ= Ġempty Flow () ĊĠĠĠĠĠ Ġoverride Ġval Ġoutputs : ĠFlow < Nothing > Ġ= Ġempty Flow () ĊĊĠĠĠĠĠ Ġoverride Ġfun Ġstart (): ĠJob Ġ{ ĊĠĠĠĠĠĠĠ Ġstarted Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġreturn ĠJob () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġrunner Ġ= ĠWorkflow Runner ViewModel ( view Registry , Ġhost , ĠUn conf ined ) ĊĊĠĠĠ ĠassertThat ( started ). isFalse () ĊĊĠĠĠ Ġrunner . render ings . test () ĊĠĠĠ ĠassertThat ( started ). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġhost Started L az ily On Outputs Subscription () Ġ{ ĊĠĠĠ Ġvar Ġstarted Ġ= Ġfalse ĊĠĠĠ Ġval Ġhost Ġ= Ġobject Ġ: ĠWorkflow Host < Unit , ĠUnit > Ġ{ ĊĠĠĠĠĠ Ġoverride Ġval Ġrender ings And Snapshots : ĠFlow < Rendering And Snapshot < Unit >> Ġ= Ġempty Flow () ĊĠĠĠĠĠ Ġoverride Ġval Ġoutputs : ĠFlow < Nothing > Ġ= Ġempty Flow () ĊĊĠĠĠĠĠ Ġoverride Ġfun Ġstart (): ĠJob Ġ{ ĊĠĠĠĠĠĠĠ Ġstarted Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġreturn ĠJob () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġrunner Ġ= ĠWorkflow Runner ViewModel ( view Registry , Ġhost , ĠUn conf ined ) ĊĊĠĠĠ ĠassertThat ( started ). isFalse () ĊĊĠĠĠ Ġrunner . output . test () ĊĠĠĠ ĠassertThat ( started ). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġsnapshot Updated On Host E mission () Ġ{ ĊĠĠĠ Ġval Ġsnapshot 1 Ġ= ĠSnapshot . of (" one ") ĊĠĠĠ Ġval Ġsnapshot 2 Ġ= ĠSnapshot . of (" two ") ĊĠĠĠ Ġval Ġsnapshots Channel Ġ= ĠChannel < Rendering And Snapshot < Unit >>( UN LIMIT ED ) ĊĊĠĠĠ Ġval Ġhost Ġ= Ġobject Ġ: ĠWorkflow Host < Unit , ĠUnit > Ġ{ ĊĠĠĠĠĠ Ġoverride Ġval Ġrender ings And Snapshots : ĠFlow < Rendering And Snapshot < Unit >> Ġ= Ġflow Ġ{ ĊĠĠĠĠĠĠĠ Ġsnapshots Channel . consume Each Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġemit ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġoverride Ġval Ġoutputs : ĠFlow < Nothing > Ġ= Ġempty Flow () ĊĊĠĠĠĠĠ Ġoverride Ġfun Ġstart () Ġ= ĠJob () ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġrunner Ġ= ĠWorkflow Runner ViewModel ( view Registry , Ġhost , ĠUn conf ined ) ĊĊĠĠĠ ĠassertThat ( runner . getLast Snapshot For Test ()). isEqualTo ( Snapshot . EMPTY ) ĊĊĠĠĠ Ġsnapshots Channel . offer ( Rendering And Snapshot ( Unit , Ġsnapshot 1 )) ĊĠĠĠ ĠassertThat ( runner . getLast Snapshot For Test ()). isEqualTo ( snapshot 1 ) ĊĊĠĠĠ Ġsnapshots Channel . offer ( Rendering And Snapshot ( Unit , Ġsnapshot 2 )) ĊĠĠĠ ĠassertThat ( runner . getLast Snapshot For Test ()). isEqualTo ( snapshot 2 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġhost Cancelled On Cle ared () Ġ{ ĊĠĠĠ Ġvar Ġcancelled Ġ= Ġfalse ĊĠĠĠ Ġval Ġhost Ġ= Ġobject Ġ: ĠWorkflow Host < Unit , ĠUnit > Ġ{ ĊĠĠĠĠĠ Ġoverride Ġval Ġrender ings And Snapshots : ĠFlow < Rendering And Snapshot < Unit >> Ġ= Ġempty Flow () ĊĠĠĠĠĠ Ġoverride Ġval Ġoutputs : ĠFlow < Nothing > Ġ= Ġempty Flow () ĊĊĠĠĠĠĠ Ġprivate Ġval Ġjob Ġ= ĠJob (). apply Ġ{ Ġinvoke On Completion Ġ{ Ġcancelled Ġ= Ġtrue Ġ} Ġ} ĊĊĠĠĠĠĠ Ġoverride Ġfun Ġstart (): ĠJob Ġ= Ġjob ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġrunner Ġ= ĠWorkflow Runner ViewModel ( view Registry , Ġhost , ĠUn conf ined ) ĊĊĠĠĠ ĠassertThat ( cancelled ). isFalse () ĊĠĠĠ Ġrunner . output . test () ĊĠĠĠ ĠassertThat ( cancelled ). isFalse () ĊĊĠĠĠ Ġrunner . clear For Test () ĊĠĠĠ ĠassertThat ( cancelled ). isTrue () ĊĠ Ġ} Ċ } Ċ