1port module Testable.Runner exposing (Msg, TestableProgram, program, show)
6import Dict exposing (Dict)
8import Element.Background as Background
9import Element.Border as Border
10import Element.Events as Events
11import Element.Font as Font
12import Html exposing (Html)
20show : Testable.Element msg -> Html msg
25type alias TestableProgram =
26 Program () (Model Msg) Msg
30 { white = Element.rgb 1 1 1
31 , red = Element.rgb 1 0 0
32 , green = Element.rgb 0 1 0
33 , black = Element.rgb 0 0 0
34 , lightGrey = Element.rgb 0.7 0.7 0.7
38program : List ( String, Testable.Element Msg ) -> TestableProgram
41 ( current, upcoming ) =
47 ( Just cur, remaining )
55 , highlightDomId = Nothing
57 , Task.perform (always Analyze)
65 , subscriptions = subscriptions
69subscriptions : Model Msg -> Sub Msg
72 [ styles RefreshBoundingBox
77 { current : Maybe ( String, Testable.Element msg )
78 , upcoming : List ( String, Testable.Element msg )
79 , finished : List (WithResults (Testable.Element msg))
80 , highlightDomId : Maybe String
84type alias WithResults thing =
88 List Testable.LayoutTest
93 List (WithResults (Testable.Element msg))
99 { description : String
104encodeForReport withResults =
106 prepareExpectation layoutTest exp =
108 Testable.Todo description ->
109 { description = description
114 Testable.Expect details ->
115 { description = details.description
116 , passing = details.result
120 prepareNode layoutTest =
121 List.map (prepareExpectation layoutTest) layoutTest.expectations
123 prepare { label, results } =
125 , results = List.concatMap prepareNode results
128 List.map prepare withResults
134 | HighlightDomID (Maybe String)
138 , bbox : Testable.BoundingBox
139 , style : List ( String, String )
141 , textMetrics : List Testable.TextMetrics
146runTest : Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
147runTest boxes label element =
150 Testable.runTests boxes element
158update : Msg -> Model Msg -> ( Model Msg, Cmd Msg )
164 HighlightDomID newId ->
165 ( { model | highlightDomId = newId }
169 RefreshBoundingBox boxes ->
170 case model.current of
176 Just ( label, current ) ->
180 , { style = Dict.fromList box.style
182 , isVisible = box.isVisible
183 , textMetrics = box.textMetrics
193 runTest foundData label current
195 case model.upcoming of
199 , finished = model.finished ++ [ currentResults ]
201 , report (encodeForReport (currentResults :: model.finished))
204 newCurrent :: remaining ->
206 | finished = model.finished ++ [ currentResults ]
207 , current = Just newCurrent
208 , upcoming = remaining
210 , Task.perform (always Analyze)
218 case model.current of
224 Just ( label, current ) ->
226 , analyze (Testable.getIds current)
230view : Model Msg -> Html.Html Msg
232 case model.current of
234 if List.isEmpty model.upcoming then
235 case model.finished of
241 , Element.width (Element.px 800)
245 finished :: remaining ->
248 , Element.inFront (Element.html (viewElementHighlight model))
249 , Element.height Element.fill
252 Element.row [ Element.width Element.fill, Element.height Element.fill ]
256 |> Element.maximum 900)
258 , Element.height Element.fill
263 , Element.padding 100
266 , Border.color palette.lightGrey
271 , Font.color palette.lightGrey
273 (Element.text "test case")
276 (Testable.toElement finished.element)
281 , Element.width Element.fill
282 , Element.height Element.fill
285 (List.map viewResult (finished :: remaining))
291 Just ( label, current ) ->
292 Testable.toHtml current
295viewElementHighlight model =
296 case model.highlightDomId of
300 Just highlightDomId ->
303 highlightDomId ++ " { outline: solid black; }"
308 |> String.append "#tests-"
311 testId ++ " { outline: dashed black; }"
321 [ Html.text styleSheet
325viewResult : WithResults (Testable.Element Msg) -> Element.Element Msg
328 isExpectationPassing result =
330 Testable.Todo label ->
333 Testable.Expect details ->
336 isPassing layoutTest =
337 List.any isExpectationPassing layoutTest.expectations
339 ( passing, failing ) =
340 List.partition isPassing testable.results
346 [ Element.el [ Font.size 24 ] (Element.text testable.label)
348 [ Element.alignLeft, Element.spacing 16 ]
350 |> groupBy .elementDomId
351 |> List.map (expandDetails >> viewLayoutTestGroup)
357 case group.members of
360 , elementType = Testable.EmptyType
361 , members = group.members
366 , elementType = top.elementType
367 , members = group.members
372 groupWhile (\one two -> fn one == fn two) list
374 (\( fst, remaining ) ->
376 , members = fst :: remaining
381groupWhile : (a -> a -> Bool) -> List a -> List ( a, List a )
382groupWhile isSameGroup items =
389 ( y, restOfGroup ) :: groups ->
390 if isSameGroup x y then
391 ( x, y :: restOfGroup ) :: groups
400viewLayoutTestGroup group =
405 |> String.append "tests-"
409 , Element.htmlAttribute (Html.Attributes.id testId)
410 , Events.onMouseEnter (HighlightDomID (Just group.id))
411 , Events.onMouseLeave (HighlightDomID Nothing)
412 , Element.htmlAttribute (Html.Attributes.style "user-select" "none")
414 [ Element.row [ Element.spacing 16 ]
415 [ Element.el [] (Element.text (Testable.elementTypeToString group.elementType))
416 , Element.el [ Font.color palette.lightGrey ] (Element.text group.id)
420 , Element.paddingXY 32 0
422 (List.map viewLayoutTest group.members)
426type alias Grouped thing =
428 , members : List thing
432viewLayoutTest layoutTest =
436 [ Element.row [ Element.spacing 8 ]
437 [ Element.el [ Font.bold ] (Element.text layoutTest.label)
439 -- , Element.el [ Font.color palette.lightGrey ] (Element.text layoutTest.elementDomId)
441 , Element.column [ Element.spacing 8 ]
442 (List.map viewLayoutExpectation layoutTest.expectations)
446viewLayoutExpectation expectation =
448 Testable.Todo label ->
449 Element.row [ Element.spacing 4 ]
450 [ todo, Element.text label ]
452 Testable.Expect details ->
453 if details.result then
454 Element.row [ Element.spacing 4 ]
455 [ pass, Element.text details.description ]
458 Element.row [ Element.spacing 4 ]
459 [ fail, Element.text details.description ]
464 [ Background.color color
465 , Font.color palette.black
466 , Element.paddingXY 4 8
473 badge palette.lightGrey "todo"
477 badge palette.green "pass"
481 badge palette.red "fail"
484formatKeyValue : String -> String -> String
485formatKeyValue key val =
494 { description : String
502port test : String -> Cmd msg
505port analyze : List String -> Cmd msg
511 , bbox : Testable.BoundingBox
512 , style : List ( String, String )
514 , textMetrics : List Testable.TextMetrics
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list