package Ġworkflow . tutorial Ċ Ċ import Ġcom . squareup . workflow 1 . Experimental Workflow Api Ċ import Ġcom . squareup . workflow 1 . apply To Ċ import Ġorg . junit . Test Ċ import Ġworkflow . tutorial . Todo Edit Workflow . Edit Props Ċ import Ġworkflow . tutorial . Todo Edit Workflow . Output . Save Ċ import Ġworkflow . tutorial . Todo Edit Workflow . State Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertNull Ċ Ċ @ Opt In ( Experimental Workflow Api :: class ) Ċ class ĠTodo Edit Workflow Test Ġ{ ĊĊĠ Ġ// ĠStart Ġwith Ġa Ġtodo Ġof Ġ" Title " Ġ" Note " ĊĠ Ġprivate Ġval Ġstart State Ġ= ĠState ( todo Ġ= ĠTodo Model ( title Ġ= Ġ" Title ", Ġnote Ġ= Ġ" Note ")) ĊĊĠ Ġ@ Test Ġfun Ġ` title Ġis Ġupdated `() Ġ{ ĊĠĠĠ Ġ// ĠThese Ġwill Ġbe Ġignored Ġby Ġthe Ġaction . ĊĠĠĠ Ġval Ġprops Ġ= ĠEdit Props ( Todo Model ( title Ġ= Ġ"", Ġnote Ġ= Ġ"")) ĊĊĠĠĠ Ġ// ĠUpdate Ġthe Ġtitle Ġto Ġ" Updated ĠTitle " ĊĠĠĠ Ġval Ġ( newState , Ġoutput ) Ġ= ĠTodo Edit Workflow . on Title Changed (" Updated ĠTitle ") ĊĠĠĠĠĠĠĠ Ġ. apply To ( props , Ġstart State ) ĊĊĠĠĠ ĠassertNull ( output ) ĊĠĠĠ ĠassertEquals ( Todo Model ( title Ġ= Ġ" Updated ĠTitle ", Ġnote Ġ= Ġ" Note "), ĠnewState . todo ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` note Ġis Ġupdated `() Ġ{ ĊĠĠĠ Ġ// ĠThese Ġwill Ġbe Ġignored Ġby Ġthe Ġaction . ĊĠĠĠ Ġval Ġprops Ġ= ĠEdit Props ( Todo Model ( title Ġ= Ġ"", Ġnote Ġ= Ġ"")) ĊĊĠĠĠ Ġ// ĠUpdate Ġthe Ġnote Ġto Ġ" Updated ĠNote " ĊĠĠĠ Ġval Ġ( newState , Ġoutput ) Ġ= ĠTodo Edit Workflow . on Note Changed (" Updated ĠNote ") ĊĠĠĠĠĠĠĠ Ġ. apply To ( props , Ġstart State ) ĊĊĠĠĠ ĠassertNull ( output ) ĊĠĠĠ ĠassertEquals ( Todo Model ( title Ġ= Ġ" Title ", Ġnote Ġ= Ġ" Updated ĠNote "), ĠnewState . todo ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` save Ġemits Ġmodel `() Ġ{ ĊĠĠĠ Ġval Ġprops Ġ= ĠEdit Props ( Todo Model ( title Ġ= Ġ" Title ", Ġnote Ġ= Ġ" Note ")) ĊĊĠĠĠ Ġval Ġ(_, Ġoutput ) Ġ= ĠTodo Edit Workflow . on Save () ĊĠĠĠĠĠĠĠ Ġ. apply To ( props , Ġstart State ) ĊĊĠĠĠ ĠassertEquals ( Save ( Todo Model ( title Ġ= Ġ" Title ", Ġnote Ġ= Ġ" Note ")), Ġoutput ?. value ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġ` changed Ġprops Ġupdated Ġlocal Ġstate `() Ġ{ ĊĠĠĠ Ġval Ġinitial Props Ġ= ĠEdit Props ( initial Todo Ġ= ĠTodo Model ( title Ġ= Ġ" Title ", Ġnote Ġ= Ġ" Note ")) ĊĠĠĠ Ġvar Ġstate Ġ= ĠTodo Edit Workflow . initialState ( initial Props , Ġnull ) ĊĊĠĠĠ Ġ// ĠThe Ġinitial Ġstate Ġis Ġa Ġcopy Ġof Ġthe Ġprovided Ġtodo : ĊĠĠĠ ĠassertEquals (" Title ", Ġstate . todo . title ) ĊĠĠĠ ĠassertEquals (" Note ", Ġstate . todo . note ) ĊĊĠĠĠ Ġ// ĠCreate Ġa Ġnew Ġinternal Ġstate , Ġsim ulating Ġthe Ġchange Ġfrom Ġactions : ĊĠĠĠ Ġstate Ġ= ĠState ( Todo Model ( title Ġ= Ġ" Updated ĠTitle ", Ġnote Ġ= Ġ" Note ")) ĊĊĠĠĠ Ġ// ĠUpdate Ġthe Ġworkflow Ġproperties Ġwith Ġthe Ġsame Ġvalue . ĠThe Ġstate Ġshould Ġnot Ġbe Ġupdated : ĊĠĠĠ Ġstate Ġ= ĠTodo Edit Workflow . on Props Changed ( initial Props , Ġinitial Props , Ġstate ) ĊĠĠĠ ĠassertEquals (" Updated ĠTitle ", Ġstate . todo . title ) ĊĠĠĠ ĠassertEquals (" Note ", Ġstate . todo . note ) ĊĊĠĠĠ Ġ// ĠThe Ġparent Ġprovided Ġdifferent Ġproperties . ĠThe Ġinternal Ġstate Ġshould Ġbe Ġupdated Ġwith Ġthe ĊĠĠĠ Ġ// Ġnewly - provided Ġproperties . ĊĠĠĠ Ġval Ġupdated Props Ġ= ĠEdit Props ( initial Todo Ġ= ĠTodo Model ( title Ġ= Ġ" New ĠTitle ", Ġnote Ġ= Ġ" New ĠNote ")) ĊĠĠĠ Ġstate Ġ= ĠTodo Edit Workflow . on Props Changed ( initial Props , Ġupdated Props , Ġstate ) ĊĠĠĠ ĠassertEquals (" New ĠTitle ", Ġstate . todo . title ) ĊĠĠĠ ĠassertEquals (" New ĠNote ", Ġstate . todo . note ) ĊĠ Ġ} Ċ } Ċ