package Ġcom . th om ask io ko . st arg azer . browse . ui . view model Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġapp . cash . tur bine . test Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġcom . th om ask io ko . st arg azer . browse . domain . View Mock Data . make Paging Repo View DataModel List Ċ import Ġcom . th om ask io ko . st arg azer . browse . domain . inter actor . Search Repositories Interactor Ċ import Ġcom . th om ask io ko . st arg azer . browse . ui . Search Action Ċ import Ġcom . th om ask io ko . st arg azer . browse . ui . Search Action . Search Repository Ċ import Ġcom . th om ask io ko . st arg azer . browse . ui . Search ViewState Ċ import Ġcom . th om ask io ko . st arg azer . core . ViewState Result Ċ import Ġcom . th om ask io ko . st arg azer . core . ViewState Result . Success Ċ import Ġkotlinx . coroutines . flow . flow Of Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġkotlinx . coroutines . test . Test Coroutine Dispatcher Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . rules . Test Rule Ċ Ċ internal Ġclass ĠSearch Repos ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġinstant Task Executor Rule : ĠTest Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġprivate Ġval Ġinter actor : ĠSearch Repositories Interactor Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġtest Coroutine Dispatcher Ġ= ĠTest Coroutine Dispatcher () ĊĊĠĠĠ Ġprivate Ġval ĠviewModel Ġ= ĊĠĠĠĠĠĠĠ ĠSearch Repos ViewModel ( inter actor , Ġtest Coroutine Dispatcher ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Successful Response Ġverify Ġsuccess State Is Returned `() Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpaging View DataList Ġ= Ġmake Paging Repo View DataModel List () ĊĠĠĠĠĠĠĠ Ġwhenever ( inter actor (" Sq ")). thenReturn ( flow Of ( Success ( paging View DataList ))) ĊĊĠĠĠĠĠĠĠ ĠviewModel . state Flow . test Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . dispatch Action ( Search Repository (" Sq ")) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( expect Item (), ĠSearch ViewState . Init ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( expect Item (), ĠSearch ViewState . Success ( paging View DataList )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` given Failure Response Ġverify Ġerror State Is Returned `() Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠerrorMessage Ġ= Ġ" Something Ġwent Ġwrong " ĊĊĠĠĠĠĠĠĠ Ġwhenever ( inter actor (" Sq ")). thenReturn ( flow Of ( ViewState Result . Error ( errorMessage ))) ĊĊĠĠĠĠĠĠĠ ĠviewModel . state Flow . test Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . dispatch Action ( Search Repository (" Sq ")) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( expect Item (), ĠSearch ViewState . Init ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( expect Item (), ĠSearch ViewState . Error ( errorMessage )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġback Is Pressed Ġverify Ġnavigator Is Inv oked `() Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . dispatch Action ( Search Action . Back Pressed ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠTODO :: ĠUser Ġscreen Navigator Ġto Ġgo Ġback Ġverify ( screen Navigator ). go Back () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġrepo Is Clicked Ġverify Ġnavigate To Detail Is Inv oked `() Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . dispatch Action ( Search Action . Navigate To Repo Detail Screen ( 1 L )) Ċ Ċ // ĠĠĠĠĠĠĠ Ġverify ( screen Navigator ). navigate ( Screen Directions . Details ) ĊĠĠĠ Ġ} Ċ } Ċ