package Ġorg . simple . clin ic . medical history . new entry Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ import Ġcom . n ha ar man . mockito _ kotlin . in Order Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . times Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġio . reactivex . Comp letable Ċ import Ġio . reactivex . Single Ċ import Ġio . reactivex . subjects . Publish Subject Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . simple . clin ic . medical history . Medical History Question Ċ import Ġorg . simple . clin ic . medical history . Medical History Question . HAS _ DI AB ET ES Ċ import Ġorg . simple . clin ic . medical history . Medical History Question . HAS _ H AD _ A _ HE ART _ ATT ACK Ċ import Ġorg . simple . clin ic . medical history . Medical History Question . HAS _ H AD _ A _ K ID NE Y _ DI SE ASE Ċ import Ġorg . simple . clin ic . medical history . Medical History Question . HAS _ H AD _ A _ ST RO KE Ċ import Ġorg . simple . clin ic . medical history . Medical History Question . IS _ ON _ TRE AT MENT _ FOR _ HY PER T ENSION Ċ import Ġorg . simple . clin ic . medical history . Medical History Question . NONE Ċ import Ġorg . simple . clin ic . medical history . Medical History Repository Ċ import Ġorg . simple . clin ic . medical history . O ngo ing Medical History Entry Ċ import Ġorg . simple . clin ic . patient . Patient M ocker Ċ import Ġorg . simple . clin ic . patient . Patient Repository Ċ import Ġorg . simple . clin ic . widgets . Screen Created Ċ import Ġorg . simple . clin ic . widgets . Ui Event Ċ import Ġjava . util . UUID Ċ Ċ class ĠNew Medical History Screen Controller Test Ġ{ ĊĊĠ Ġprivate Ġval Ġscreen : ĠNew Medical History Screen Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġmedical History Repository : ĠMedical History Repository Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġpatient Repository : ĠPatient Repository Ġ= Ġmock () ĊĊĠ Ġprivate Ġlateinit Ġvar Ġcontroller : ĠNew Medical History Screen Controller ĊĠ Ġprivate Ġval Ġui Events Ġ= ĠPublish Subject . create < Ui Event >() ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġcontroller Ġ= ĠNew Medical History Screen Controller ( medical History Repository , Ġpatient Repository ) ĊĊĠĠĠ Ġwhenever ( medical History Repository . save ( any (), Ġany ())). thenReturn ( Comp letable . complete ()) ĊĊĠĠĠ Ġui Events . compose ( controller ). subscribe Ġ{ Ġui Change Ġ-> Ġui Change ( screen ) Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġany Ġanswer Ġis Ġselected Ġexcept Ġfor Ġnone Ġthen Ġnone Ġshould Ġbe Ġselected `() Ġ{ ĊĠĠĠ Ġval Ġanswers Minus None Ġ= ĠMedical History Question . values (). filter Ġ{ Ġit Ġ!= ĠNONE Ġ} ĊĊĠĠĠ Ġanswers Minus None . forEach Ġ{ ĊĠĠĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= Ġit , Ġselected Ġ= Ġfalse )) ĊĠĠĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= Ġit , Ġselected Ġ= Ġtrue )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġverify ( screen , Ġtimes ( answers Minus None . size )). un Select None Answer () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġnone Ġis Ġselected Ġthen Ġall Ġanswers Ġshould Ġget Ġun selected `() Ġ{ ĊĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= ĠNONE , Ġselected Ġ= Ġtrue )) ĊĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= ĠNONE , Ġselected Ġ= Ġfalse )) ĊĠĠĠ Ġverify ( screen ). un Select All Answers Except None () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġsave Ġis Ġclicked Ġwith Ġselected Ġanswers Ġthen Ġpatient Ġwith Ġthe Ġanswers Ġshould Ġbe Ġsaved Ġand Ġsummary Ġscreen Ġshould Ġbe Ġopened `() Ġ{ ĊĠĠĠ Ġval Ġsaved Patient Ġ= ĠPatient M ocker . patient ( uuid Ġ= ĠUUID . randomUUID ()) ĊĠĠĠ Ġwhenever ( patient Repository . save O ngo ing Entry As Patient ()). thenReturn ( Single . just ( saved Patient )) ĊĊĠĠĠ Ġval Ġanswers Minus None Ġ= ĠMedical History Question . values (). filter Ġ{ Ġit Ġ!= ĠNONE Ġ} ĊĠĠĠ Ġval Ġselected Answers Ġ= Ġanswers Minus None . sh uffled (). sub List ( 0 , Ġanswers Minus None . size Ġ/ Ġ 2 ) ĊĠĠĠ Ġval Ġun selected Answers Ġ= Ġanswers Minus None . minus ( selected Answers ) ĊĊĠĠĠ Ġui Events . onNext ( Screen Created ()) ĊĠĠĠ Ġselected Answers . forEach Ġ{ ĊĠĠĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( it , Ġselected Ġ= Ġtrue )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġun selected Answers . forEach Ġ{ ĊĠĠĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( it , Ġselected Ġ= Ġfalse )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġui Events . onNext ( Save Medical History Clicked ()) ĊĊĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( medical History Repository , Ġpatient Repository , Ġscreen ) ĊĠĠĠ Ġin Order . verify ( patient Repository ). save O ngo ing Entry As Patient () ĊĠĠĠ Ġin Order . verify ( medical History Repository ). save ( ĊĠĠĠĠĠĠĠ Ġpatient Uuid Ġ= Ġsaved Patient . uuid , ĊĠĠĠĠĠĠĠ Ġhistory Entry Ġ= ĠO ngo ing Medical History Entry ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas H ad Heart Attack Ġ= Ġselected Answers . contains ( HAS _ H AD _ A _ HE ART _ ATT ACK ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas H ad Stroke Ġ= Ġselected Answers . contains ( HAS _ H AD _ A _ ST RO KE ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas H ad K id ney D isease Ġ= Ġselected Answers . contains ( HAS _ H AD _ A _ K ID NE Y _ DI SE ASE ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis On T reatment For Hy pert ension Ġ= Ġselected Answers . contains ( IS _ ON _ TRE AT MENT _ FOR _ HY PER T ENSION ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas Di abet es Ġ= Ġselected Answers . contains ( HAS _ DI AB ET ES ))) ĊĠĠĠ Ġin Order . verify ( screen ). open Patient Summary Screen ( saved Patient . uuid ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġsave Ġis Ġclicked Ġwith Ġno Ġanswers Ġthen Ġpatient Ġwith Ġan Ġempty Ġmedical Ġhistory Ġshould Ġbe Ġsaved Ġand Ġsummary Ġscreen Ġshould Ġbe Ġopened `() Ġ{ ĊĠĠĠ Ġval Ġsaved Patient Ġ= ĠPatient M ocker . patient ( uuid Ġ= ĠUUID . randomUUID ()) ĊĠĠĠ Ġwhenever ( patient Repository . save O ngo ing Entry As Patient ()). thenReturn ( Single . just ( saved Patient )) ĊĊĠĠĠ Ġui Events . onNext ( Screen Created ()) ĊĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= ĠNONE , Ġselected Ġ= Ġtrue )) ĊĠĠĠ Ġui Events . onNext ( Save Medical History Clicked ()) ĊĊĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( medical History Repository , Ġpatient Repository , Ġscreen ) ĊĠĠĠ Ġin Order . verify ( patient Repository ). save O ngo ing Entry As Patient () ĊĠĠĠ Ġin Order . verify ( medical History Repository ). save ( ĊĠĠĠĠĠĠĠ Ġpatient Uuid Ġ= Ġsaved Patient . uuid , ĊĠĠĠĠĠĠĠ Ġhistory Entry Ġ= ĠO ngo ing Medical History Entry ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas H ad Heart Attack Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas H ad Stroke Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas H ad K id ney D isease Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis On T reatment For Hy pert ension Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas Di abet es Ġ= Ġfalse )) ĊĠĠĠ Ġin Order . verify ( screen ). open Patient Summary Screen ( saved Patient . uuid ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` save Ġbutton Ġshould Ġremain Ġenabled Ġonly Ġwhen Ġat least Ġone Ġanswer Ġis Ġselected `() Ġ{ ĊĠĠĠ Ġval Ġanswers Ġ= ĠMedical History Question . values () ĊĠĠĠ Ġanswers . forEach Ġ{ ĊĠĠĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= Ġit , Ġselected Ġ= Ġfalse )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġanswers . forEach Ġ{ ĊĠĠĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= Ġit , Ġselected Ġ= Ġtrue )) ĊĠĠĠĠĠ Ġui Events . onNext ( New Medical History Answer Toggle d ( question Ġ= Ġit , Ġselected Ġ= Ġfalse )) ĊĠĠĠ Ġ} ĊĠĠĠ Ġverify ( screen , Ġtimes ( answers . size )). set Save Button Enabled ( true ) ĊĠĠĠ Ġverify ( screen , Ġtimes ( answers . size Ġ+ Ġ 1 )). set Save Button Enabled ( false ) ĊĠ Ġ} Ċ } Ċ