webbhuset/elm-actor-model/1.0.0

NOTE: the latest version is 4.0.0

Webbhuset.Component.Sandbox

Sandbox

The sandbox module is helpful when developing components. It lets you run the component using elm reactor outside the system and define several test cases.

type alias SandboxProgram model msgIn =
Program () (Model model msgIn) (Msg msgIn)

The Program type of your main function.

type alias TestCase msgIn =
{ title : String
, desc : String
, init : List msgIn
}

A test case for the Component

Each test case contains a list of in-messages that will be sent to the component when the sandbox is started.

Sandbox UI Components

ui :
{ title : String
, component : UI model msgIn msgOut
, cases : List (TestCase msgIn)
, stringifyMsgIn : msgIn -> String
, stringifyMsgOut : msgOut -> String
}
-> SandboxProgram model msgIn

Wrap a component in a sandbox application.

This will render each test case and log all messages. Create a test file with a main function where you declare all test cases.

import Component.Form as Form
import Webbhuset.Component.Sandbox as Sandbox exposing (SandboxProgram)


main : SandboxProgram Form.Model Form.MsgIn
main =
    Sandbox.ui
        Form.component
        "Form Component"
        [ Sandbox.TestCase
            "Empty form"
            "Submit-button should be disabled"
            [
            ]
        , Sandbox.TestCase
            "Form with Errors"
            "You should see an error message"
            [ Form.ErrorMsg "Error message"
            ]
        ]

You can also use the ui sandbox on a Service component. Just add a view function.

{ init = service.init
, update = service.update
, kill = service.kill
, subs = service.subs
, view = view
}


view : Model -> Html MsgIn
view model =
    Html.text "Service Component"