fulcro

timeyyy 2024-11-30T01:25:18.907499Z

After reading the statecharts documentaion and looking at the section for https://fulcrologic.github.io/statecharts/#_starting_in_a_specific_configuration, i'm unsure what is really meant by looking at the example. The example mentions something about an internal call and doesn't show how the previously mentioned testing/configuration-for-states is used.

(defn config [] {:statechart some-statechart})

(specification "Starting in Some State"
  (let [env (testing/new-testing-env (config) {})]

    ;; assume a top-level parallel node, with two sub-regions. An internal call to `configuration-for-states`
    ;; will populate all of the necessary ancestor states from these leaves.
    (testing/goto-configuration! env [] #{:state.region1/leaf :state.region2/leaf})
    (testing/run-events! env :event/expired)

    ;; assertions
    ))

tony.kay 2024-12-01T12:42:12.348229Z

The testing tools auto-mock ALL of the code in your chart (predicates, script tags, etc). So, that test says “Start in this configuration, and then send :event/expired”. Then you could check that you get to the target state expected. This is ok as a regression test (for edits of the chart itself), but normally you would also do things like set certain ones of the mocked functions to something you control to demonstrate how you intend the logic to operate as a way to ensure you’ve constructed the chart in the way you thought.

tony.kay 2024-12-01T12:44:46.720739Z

you can either unmock things (by setting them to their originals) or sub in particular values for predicates. This makes it so you don’t have to have real side effects, etc. The one down-side is that any external events you send from within the chart (via send) are also not processed because the default event queue drops events. This is so you can control the test completely and deliver that external event as part of the logic of your test. If you want a real event queue, you can put it in the env.

tony.kay 2024-12-01T12:52:15.001349Z

This line is setting up the mocking so the real functions are not used: https://github.com/fulcrologic/statecharts/blob/main/src/test/com/fulcrologic/statecharts/algorithms/v20150901/executable_content_spec.cljc#L45

tony.kay 2024-12-01T12:52:52.206419Z

but you can also just populate that map with something like {a a} where you’re saying “use the original for a

tony.kay 2024-12-01T12:53:34.070069Z

but in that case you might instead use the “simple” statechart implementation, like here: https://github.com/fulcrologic/statecharts/blob/main/src/test/com/fulcrologic/statecharts/algorithms/v20150901/executable_content_spec.cljc#L180

tony.kay 2024-12-01T12:54:03.370639Z

where you can control the processing of the external event queue when you want, like on this line https://github.com/fulcrologic/statecharts/blob/main/src/test/com/fulcrologic/statecharts/algorithms/v20150901/executable_content_spec.cljc#L197