diff --git a/docs/Test/FlareCheck.md b/docs/Test/FlareCheck.md index 69707bd..78df388 100644 --- a/docs/Test/FlareCheck.md +++ b/docs/Test/FlareCheck.md @@ -106,6 +106,25 @@ gCreateUI :: forall a e. (Generic a) => UI e a -> UI e Renderable A `createUI` implementation for types with a `Generic` instance. +#### `flareDoc'` + +``` purescript +flareDoc' :: forall t e. (Interactive t) => ElementId -> Label -> Maybe String -> t -> Eff (chan :: Chan, dom :: DOM | e) Unit +``` + +Run an interactive test. The ID specifies the parent element to which +the test will be appended and the label provides a title for the test. +The String argument is an optional documentation string. + +#### `flareDoc` + +``` purescript +flareDoc :: forall t e. (Interactive t) => Label -> Maybe String -> t -> Eff (chan :: Chan, dom :: DOM | e) Unit +``` + +Run an interactive test. The label provides a title for the test. The +String argument is an optional documentation string. + #### `flareCheck'` ``` purescript diff --git a/src/Test/FlareCheck.js b/src/Test/FlareCheck.js index 08d5e7a..c63dea1 100644 --- a/src/Test/FlareCheck.js +++ b/src/Test/FlareCheck.js @@ -6,26 +6,34 @@ exports.appendTest = function(parentId) { return function(title) { - return function(elements) { - return function() { - var parent = document.getElementById(parentId); - var fieldset = document.createElement("fieldset"); - fieldset.className = "flarecheck-test"; - var legend = document.createElement("legend"); - legend.textContent = title; - fieldset.appendChild(legend); + return function(doc) { + return function(elements) { + return function() { + var parent = document.getElementById(parentId); + var fieldset = document.createElement("fieldset"); + fieldset.className = "flarecheck-test"; + var legend = document.createElement("legend"); + legend.textContent = title; + fieldset.appendChild(legend); - for (var i = 0; i < elements.length; i++) { - fieldset.appendChild(elements[i]); - } + if (doc !== "") { + var docEl = document.createElement("p"); + docEl.innerHTML = doc; + fieldset.appendChild(docEl); + } - var output = document.createElement("div"); - output.className = "flarecheck-output"; - fieldset.appendChild(output); + for (var i = 0; i < elements.length; i++) { + fieldset.appendChild(elements[i]); + } - parent.appendChild(fieldset); + var output = document.createElement("div"); + output.className = "flarecheck-output"; + fieldset.appendChild(output); - return output; + parent.appendChild(fieldset); + + return output; + }; }; }; }; diff --git a/src/Test/FlareCheck.purs b/src/Test/FlareCheck.purs index 36139ea..ed8e063 100644 --- a/src/Test/FlareCheck.purs +++ b/src/Test/FlareCheck.purs @@ -11,6 +11,8 @@ module Test.FlareCheck , foldableCreateUI , gCreateUI , Renderable() + , flareDoc' + , flareDoc , flareCheck' , flareCheck , module Flare @@ -263,9 +265,10 @@ instance interactiveFunction :: (Flammable a, Interactive b) => Interactive (a - createUI f = createUI (f <*> spark) -- | Append a new interactive test. The arguments are the ID of the parent --- | element, the title for the test and the list of Flare components. Returns --- | the element for the output of the test. +-- | element, the title for the test, a documentation string and the list of +-- | Flare components. Returns the element for the output of the test. foreign import appendTest :: forall e. ElementId + -> String -> String -> Array Element -> Eff (dom :: DOM | e) Element @@ -295,17 +298,38 @@ render output (SetHTML markup) = setHTML output (H.render markup) -- | Run an interactive test. The ID specifies the parent element to which -- | the test will be appended and the label provides a title for the test. -flareCheck' :: forall t e. (Interactive t) +-- | The String argument is an optional documentation string. +flareDoc' :: forall t e. (Interactive t) => ElementId -> Label + -> Maybe String -> t -> Eff (chan :: Chan, dom :: DOM | e) Unit -flareCheck' parentId title x = do +flareDoc' parentId title doc x = do let flare = createUI (pure x) { components, signal } <- setupFlare flare - output <- appendTest parentId title components + let docString = fromMaybe "" doc + output <- appendTest parentId title docString components runSignal (render output <$> signal) +-- | Run an interactive test. The label provides a title for the test. The +-- | String argument is an optional documentation string. +flareDoc :: forall t e. (Interactive t) + => Label + -> Maybe String + -> t + -> Eff (chan :: Chan, dom :: DOM | e) Unit +flareDoc = flareDoc' "tests" + +-- | Run an interactive test. The ID specifies the parent element to which +-- | the test will be appended and the label provides a title for the test. +flareCheck' :: forall t e. (Interactive t) + => ElementId + -> Label + -> t + -> Eff (chan :: Chan, dom :: DOM | e) Unit +flareCheck' id label = flareDoc' id label Nothing + -- | Run an interactive test. The label provides a title for the test. flareCheck :: forall t e. (Interactive t) => Label