123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181open!Coreopen!ImportincludeHelpers_intfletsexp_to_string=Expect_test_helpers_core.sexp_to_stringletmake_generic(typeinputextraactionresults)~(driver:(input,s)Driver.t)~(string_of_result:result->string)~(get_result:s->result)~(get_extra:s->extra)~(schedule_action:s->action->unit):(moduleSwithtypeinput=inputandtypeaction=actionandtypeextra=extra)=(modulestructtypenonrecinput=inputtypenonrecaction=actiontypenonrecextra=extraletshow()=driver|>Driver.result|>get_result|>string_of_result|>print_endline;;letshow_model()=(* Cleans up a sexp by
- removing empty lists (unit models are common in bonsai)
- flattening lists that contain a single element *)letrecclean_up_model_sexpa=matchawith|Sexp.Listl->(matchList.filter_mapl~f:clean_up_model_sexpwith|[]->None|[l]->Somel|l->Some(Sexp.Listl))|Sexp.Atom_asa->Someaindriver|>Driver.sexp_of_model|>clean_up_model_sexp|>Option.value~default:(Sexp.List[])|>sexp_to_string|>print_endline;;letget_extra()=driver|>Driver.result|>get_extraletset_inputinput=Driver.set_inputdriverinput;Driver.flushdriver;show();;letdo_actionsactions=List.iteractions~f:(schedule_action(Driver.resultdriver));Driver.flushdriver;show();;end);;letmake_vdom_generic(typeinputactionextras)~(driver:(input,s)Driver.t)~(vdom_of_result:s->Vdom.Node.t)~(get_extra:s->extra)~(inject_of_result:s->action->unitVdom.Effect.t)?(vdom_to_string=funnode->node|>Virtual_dom_test_helpers.Node_helpers.unsafe_convert_exn|>Virtual_dom_test_helpers.Node_helpers.to_string_html)():(moduleS_vdomwithtypeinput=inputandtypeaction=actionandtypeextra=extra)=letopenVirtual_dom_test_helpersinlet(moduleH)=make_generic~driver~string_of_result:vdom_to_string~get_result:vdom_of_result~get_extra~schedule_action:(funsaction->Driver.schedule_eventdriver((inject_of_results)action))in(modulestructincludeHletget_element~selector=letnode=driver|>Driver.result|>vdom_of_result|>Node_helpers.unsafe_convert_exninNode_helpers.select_first_exnnode~selector;;letclick_on~selector=letelement=get_element~selectorinNode_helpers.User_actions.click_onelement;Driver.flushdriver;;letinput_text~selector~text=letelement=get_element~selectorinNode_helpers.User_actions.input_textelement~text;Driver.flushdriver;;end);;let[@warning"-16"]make_vdom_with_inject?vdom_to_string~driver=make_vdom_generic?vdom_to_string~driver~get_extra:(Fn.const())~vdom_of_result:Tuple2.get1~inject_of_result:Tuple2.get2();;let[@warning"-16"]make_vdom_with_extra?vdom_to_string~driver=make_vdom_generic?vdom_to_string~driver~vdom_of_result:Tuple2.get1~get_extra:Tuple2.get2~inject_of_result:(Fn.constNothing.unreachable_code)();;let[@warning"-16"]make_vdom?vdom_to_string~driver=make_vdom_generic?vdom_to_string~driver~get_extra:(Fn.const())~vdom_of_result:Fn.id~inject_of_result:(Fn.constNothing.unreachable_code)();;letmake_string~driver=make_generic~driver~string_of_result:Fn.id~get_result:Fn.id~get_extra:(Fn.const())~schedule_action:(Fn.constNothing.unreachable_code);;letmake~driver~sexp_of_result=make_generic~driver~string_of_result:(funr->r|>sexp_of_result|>sexp_to_string)~get_result:Fn.id~get_extra:(Fn.const())~schedule_action:(Fn.constNothing.unreachable_code);;letmake_string_with_inject~driver=make_generic~driver~string_of_result:Fn.id~get_result:fst~get_extra:(Fn.const())~schedule_action:(fun(_,inject)action->Driver.schedule_eventdriver(injectaction));;letmake_with_inject~driver~sexp_of_result=make_generic~driver~string_of_result:(funr->r|>sexp_of_result|>sexp_to_string)~get_result:fst~get_extra:(Fn.const())~schedule_action:(fun(_,inject)action->Driver.schedule_eventdriver(injectaction));;