package Ġorg . simple . clin ic . new entry Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . do Return Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify No More Interactions Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Zero Interactions Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġio . reactivex . Observable Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Test Ċ import Ġorg . simple . clin ic . R Ċ import Ġorg . simple . clin ic . TestData Ċ import Ġorg . simple . clin ic . facility . Facility Repository Ċ import Ġorg . simple . clin ic . mob ius . Effect Handler TestCase Ċ import Ġorg . simple . clin ic . new entry . Field . PhoneNumber Ċ import Ġorg . simple . clin ic . new entry . country . Input Fields Ċ import Ġorg . simple . clin ic . new entry . country . Input Fields Factory Ċ import Ġorg . simple . clin ic . new entry . form . Age Field Ċ import Ġorg . simple . clin ic . new entry . form . Alternative Id Input Field Ċ import Ġorg . simple . clin ic . new entry . form . Date OfBirth Field Ċ import Ġorg . simple . clin ic . new entry . form . District Field Ċ import Ġorg . simple . clin ic . new entry . form . Gender Field Ċ import Ġorg . simple . clin ic . new entry . form . Land line Or Mobile Field Ċ import Ġorg . simple . clin ic . new entry . form . Patient Name Field Ċ import Ġorg . simple . clin ic . new entry . form . State Field Ċ import Ġorg . simple . clin ic . new entry . form . Street Address Field Ċ import Ġorg . simple . clin ic . new entry . form . V illage Or Col ony Field Ċ import Ġorg . simple . clin ic . new entry . form . Zone Field Ċ import Ġorg . simple . clin ic . patient . Gender Ċ import Ġorg . simple . clin ic . patient . O ngo ing New Patient Entry Ċ import Ġorg . simple . clin ic . patient . Patient Repository Ċ import Ġorg . simple . clin ic . user . User Session Ċ import Ġorg . simple . clin ic . util . Test User Clock Ċ import Ġorg . simple . clin ic . util . scheduler . Tr amp oline Schedulers Provider Ċ import Ġjava . time . LocalDate Ċ import Ġjava . time . format . DateTime Formatter Ċ import Ġjava . util . Locale Ċ import Ġjava . util . UUID Ċ Ċ class ĠPatient Entry Effect Handler Test Ġ{ ĊĊĠ Ġprivate Ġval Ġuser Session Ġ= Ġmock < User Session >() ĊĠ Ġprivate Ġval Ġfacility Repository Ġ= Ġmock < Facility Repository >() ĊĠ Ġprivate Ġval Ġpatient Repository Ġ= Ġmock < Patient Repository >() ĊĊĠ Ġprivate Ġval Ġfacility Ġ= ĠTest Data . facility ( uuid Ġ= ĠUUID . fromString (" e 1 3 5 0 8 5 f - b 5 a 1 - 4 9 d 4 - bd 7 7 - 7 3 ad 9 8 5 0 0 b 9 2 ")) ĊĠ Ġprivate Ġval Ġentry Ġ= ĠTest Data . ongo ing Patient Entry () ĊĊĠ Ġprivate Ġval ĠdateTime Formatter Ġ= ĠDateTime Formatter . of Pattern (" dd / MM / yyyy ", ĠLocale . EN GL ISH ) ĊĠ Ġprivate Ġval Ġclock Ġ= ĠTest User Clock ( LocalDate . parse (" 2 0 1 8 - 0 1 - 0 1 ")) ĊĊĠ Ġprivate Ġval Ġinput Fields Ġ= ĠInput Fields ( listOf ( ĊĠĠĠĠĠ ĠPatient Name Field ( R . string . patient entry _ full _ name ), ĊĠĠĠĠĠ ĠAge Field ( R . string . patient entry _ age ), ĊĠĠĠĠĠ ĠDate OfBirth Field ({ Ġvalue Ġ-> ĠLocalDate . parse ( value , ĠdateTime Formatter ) Ġ}, ĠLocalDate . now ( clock ), ĠR . string . patient entry _ date _ of _ birth _ un focused ), ĊĠĠĠĠĠ ĠLand line Or Mobile Field ( R . string . patient entry _ phone _ number ), ĊĠĠĠĠĠ ĠGender Field (_ label Res Id Ġ= Ġ 0 , Ġallowed G enders Ġ= Ġset Of ( Gender . Male , ĠGender . Female , ĠGender . Trans gender )), ĊĠĠĠĠĠ ĠAltern ative Id Input Field ( R . string . patient entry _ bang l ade sh _ national _ id ), ĊĠĠĠĠĠ ĠStreet Address Field ( R . string . patient entry _ street _ house _ road _ number ), ĊĠĠĠĠĠ ĠV illage Or Col ony Field ( R . string . patient entry _ v illage _ ward ), ĊĠĠĠĠĠ ĠZone Field ( R . string . patient entry _ zone ), ĊĠĠĠĠĠ ĠDistrict Field ( R . string . patient entry _ up az ila ), ĊĠĠĠĠĠ ĠState Field ( R . string . patient entry _ district ) ĊĠ Ġ)) ĊĠ Ġprivate Ġval Ġinput Fields Factory Ġ= Ġmock < Input Fields Factory >() ĊĊĠ Ġprivate Ġval Ġui Actions Ġ= Ġmock < Patient Entry Ui Actions >() ĊĠ Ġprivate Ġval Ġview Effect Handler Ġ= ĠPatient Entry View Effect Handler ( ui Actions ) ĊĠ Ġprivate Ġval Ġeffect Handler Ġ= ĠPatient Entry Effect Handler ( ĊĠĠĠĠĠ Ġfacility Repository Ġ= Ġfacility Repository , ĊĠĠĠĠĠ Ġpatient Repository Ġ= Ġpatient Repository , ĊĠĠĠĠĠ Ġs chedulers Provider Ġ= ĠTr amp oline Schedulers Provider (), ĊĠĠĠĠĠ Ġinput Fields Factory Ġ= Ġinput Fields Factory , ĊĠĠĠĠĠ Ġpatient Registered Count Ġ= Ġmock (), ĊĠĠĠĠĠ Ġview Effects Consumer Ġ= Ġview Effect Handler :: handle ĊĠ Ġ) ĊĊĠ Ġprivate Ġlateinit Ġvar ĠtestCase : ĠEffect Handler TestCase < Patient Entry Effect , ĠPatient Entry Event > ĊĊĠ Ġ@ After ĊĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠ ĠtestCase . dispose () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` it Ġhide s Ġphone Ġlength Ġerrors Ġwhen Ġhide Ġphone Ġvalidation Ġerrors Ġis Ġdis patched `() Ġ{ ĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ Ġsetup TestCase () ĊĠĠĠ ĠtestCase . dispatch ( Hide ValidationError ( PhoneNumber )) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ ĠtestCase . assert No Outgoing Events () ĊĠĠĠ Ġverify ( ui Actions ). show Length Too Short PhoneNumber Error ( false , Ġ 0 ) ĊĠĠĠ Ġverify No More Interactions ( ui Actions ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġthe Ġload Ġinput Ġfields Ġeffect Ġis Ġreceived , Ġthe Ġinput Ġfields Ġmust Ġbe Ġloaded `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġwhenever ( input Fields Factory . provide Fields ()) Ġdo Return Ġinput Fields . fields ĊĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ Ġsetup TestCase () ĊĠĠĠ ĠtestCase . dispatch ( Load Input Fields ) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ ĠtestCase . assert Outgoing Events ( Input Fields Loaded ( input Fields )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġthe Ġsetup ĠUI Ġeffect Ġis Ġreceived , Ġthe ĠUI Ġmust Ġbe Ġsetup Ġwith Ġthe Ġinput Ġfields `() Ġ{ ĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ Ġsetup TestCase () ĊĠĠĠ ĠtestCase . dispatch ( Setup Ui ( input Fields )) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ ĠtestCase . assert No Outgoing Events () ĊĠĠĠ Ġverify ( ui Actions ). setup Ui ( input Fields ) ĊĠĠĠ Ġverify No More Interactions ( ui Actions ) ĊĠĠĠ Ġverify Zero Interactions ( ui Actions ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġfetch Ġcol ony Ġor Ġv illage Ġnames Ġeffect Ġis Ġreceived , Ġthen Ġload Ġcol ony Ġor Ġv illage Ġnames `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġval Ġcol ony Or V ill ages Ġ= ĠlistOf (" col ony 1 ", Ġ" col ony 2 ", Ġ" col ony 3 ", Ġ" col ony 4 ") ĊĠĠĠ Ġwhenever ( patient Repository . all Colon ies Or V ill ages In Patient Address ()). thenReturn ( col ony Or V ill ages ) ĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ Ġsetup TestCase () ĊĠĠĠ ĠtestCase . dispatch ( Fetch Col ony Or V ill ages Effect ) ĊĊĠĠĠ Ġ// then ĊĠĠĠ ĠtestCase . assert Outgoing Events ( Col ony Or V ill ages F etched ( col ony Or V ill ages )) ĊĠĠĠ Ġverify Zero Interactions ( ui Actions ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġfetch Ġpatient Ġentry Ġeffect Ġis Ġreceived Ġand Ġaddress Ġis Ġnot Ġempty Ġbut Ġthere Ġis Ġno Ġdistrict Ġand Ġstate Ġin Ġpatient Ġentry , Ġthen Ġfetch Ġongoing Ġpatient Ġentry Ġfrom Ġthe Ġrepo Ġand Ġadd Ġthe Ġdistrict Ġand Ġstate Ġfields `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġval Ġongoing New Patient Entry Ġ= ĠO ngo ing New Patient Entry ( ĊĠĠĠĠĠĠĠ Ġpersonal Details Ġ= ĠO ngo ing New Patient Entry . Personal Details ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfullName Ġ= Ġ" Ri ya ĠO ber oi ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdate OfBirth Ġ= Ġ" 2 2 / 0 3 / 2 0 0 9 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgender Ġ= ĠGender . Female , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġage Ġ= Ġnull ), ĊĠĠĠĠĠĠĠ Ġaddress Ġ= ĠO ngo ing New Patient Entry . Address . BLANK . with Col ony Or V illage (" 3 4 B , ĠR aj pur ĠRoad "), ĊĠĠĠĠĠĠĠ Ġidentifier Ġ= Ġnull ) ĊĠĠĠ Ġval Ġfacility Ġ= ĠTest Data . facility ( state Ġ= Ġ" P un jab ", Ġdistrict Ġ= Ġ" B ath inda ") ĊĠĠĠ Ġwhenever ( patient Repository . ongo ing Entry ()). thenReturn ( ongo ing New Patient Entry ) ĊĠĠĠ Ġwhenever ( facility Repository . current Facility ()). thenReturn ( Observable . just ( facility )) ĊĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ ĠtestCase Ġ= ĠEffect Handler TestCase ( effect Handler . build ()) ĊĠĠĠ ĠtestCase . dispatch ( Fetch Patient Entry ) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ ĠtestCase . assert Outgoing Events ( O ngo ing Entry F etched ( ongo ing New Patient Entry . with District ( facility . district ). with State ( facility . state ))) ĊĠĠĠ Ġverify Zero Interactions ( ui Actions ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġfetch Ġpatient Ġentry Ġeffect Ġis Ġreceived Ġwith Ġfilled Ġaddress Ġfields , Ġthen Ġfetch Ġongoing Ġpatient Ġentry Ġand Ġdon 't Ġadd Ġdistrict Ġand Ġstate Ġfields `() Ġ{ ĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ Ġsetup TestCase () ĊĠĠĠ ĠtestCase . dispatch ( Fetch Patient Entry ) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ ĠtestCase . assert Outgoing Events ( O ngo ing Entry F etched ( entry )) ĊĠĠĠ Ġverify Zero Interactions ( ui Actions ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġfetch Ġpatient Ġentry Ġeffect Ġis Ġreceived Ġand Ġaddress Ġis Ġnot Ġempty Ġbut Ġthere Ġis Ġdistrict Ġand Ġstate Ġin Ġpatient Ġentry , Ġthen Ġfetch Ġongoing Ġpatient Ġentry Ġfrom Ġthe Ġrepo Ġand Ġdon 't Ġadd Ġthe Ġdistrict Ġand Ġstate Ġfields `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġval Ġongoing New Patient Entry Ġ= ĠO ngo ing New Patient Entry ( ĊĠĠĠĠĠĠĠ Ġpersonal Details Ġ= ĠO ngo ing New Patient Entry . Personal Details ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfullName Ġ= Ġ" Ri ya ĠO ber oi ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdate OfBirth Ġ= Ġ" 2 2 / 0 3 / 2 0 0 9 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgender Ġ= ĠGender . Female , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġage Ġ= Ġnull ), ĊĠĠĠĠĠĠĠ Ġaddress Ġ= Ġnull , ĊĠĠĠĠĠĠĠ Ġidentifier Ġ= Ġnull ) ĊĠĠĠ Ġval Ġfacility Ġ= ĠTest Data . facility ( state Ġ= Ġ" P un jab ", Ġdistrict Ġ= Ġ" B ath inda ") ĊĠĠĠ Ġwhenever ( patient Repository . ongo ing Entry ()). thenReturn ( ongo ing New Patient Entry ) ĊĠĠĠ Ġwhenever ( facility Repository . current Facility ()). thenReturn ( Observable . just ( facility )) ĊĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ ĠtestCase Ġ= ĠEffect Handler TestCase ( effect Handler . build ()) ĊĠĠĠ ĠtestCase . dispatch ( Fetch Patient Entry ) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ ĠtestCase . assert Outgoing Events ( O ngo ing Entry F etched ( ongo ing New Patient Entry . with District ( facility . district ). with State ( facility . state ))) ĊĠĠĠ Ġverify Zero Interactions ( ui Actions ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup TestCase () Ġ{ ĊĠĠĠ Ġwhenever ( facility Repository . current Facility ()). thenReturn ( Observable . just ( facility )) ĊĠĠĠ Ġwhenever ( patient Repository . ongo ing Entry ()). thenReturn ( entry ) ĊĊĠĠĠ ĠtestCase Ġ= ĠEffect Handler TestCase ( effect Handler . build ()) ĊĠ Ġ} Ċ } Ċ