1port module Testable.Runner exposing
14import Dict exposing (Dict)
16import Element.Background as Background
17import Element.Border as Border
18import Element.Events as Events
19import Element.Font as Font
20import Html exposing (Html)
28show : Testable.Element msg -> Html msg
33type alias TestableProgram =
34 Program () (Model Msg) Msg
37{-| This should be a real type, but I'm too busy atm.
40 ( String, Testable.Element Msg )
43rename : String -> Testable -> Testable
44rename newName ( _, el ) =
48testable : String -> Testable.Element Msg -> Testable
54 { white = Element.rgb 1 1 1
55 , red = Element.rgb 1 0 0
56 , green = Element.rgb 0 1 0
57 , black = Element.rgb 0 0 0
58 , lightGrey = Element.rgb 0.7 0.7 0.7
62program : List Testable -> TestableProgram
65 ( current, upcoming ) =
71 ( Just cur, remaining )
80 , highlightDomId = Nothing
82 , Task.perform (always Analyze)
90 , subscriptions = subscriptions
94subscriptions : Model Msg -> Sub Msg
97 [ styles RefreshBoundingBox
101type alias Model msg =
102 { current : Maybe ( String, Testable.Element msg )
103 , upcoming : List ( String, Testable.Element msg )
104 , finished : List (WithResults (Testable.Element msg))
106 , highlightDomId : Maybe String
110type alias WithResults thing =
115 List Testable.LayoutTest
120 List (WithResults (Testable.Element msg))
126 { description : String
131encodeForReport withResults =
133 prepareExpectation layoutTest exp =
135 Testable.Todo description ->
136 { description = description
141 Testable.Expect details ->
142 { description = details.description
143 , passing = details.result
147 prepareNode layoutTest =
148 List.map (prepareExpectation layoutTest) layoutTest.expectations
150 prepare { label, results } =
152 , results = List.concatMap prepareNode results
155 List.map prepare withResults
162 | HighlightDomID (Maybe String)
166 , bbox : Testable.BoundingBox
167 , style : List ( String, String )
169 , textMetrics : List Testable.TextMetrics
174runTest : Int -> Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
175runTest index boxes label element =
178 Testable.runTests boxes element
187update : Msg -> Model Msg -> ( Model Msg, Cmd Msg )
193 HighlightDomID newId ->
194 ( { model | highlightDomId = newId }
199 ( { model | selected = index }
203 RefreshBoundingBox boxes ->
204 case model.current of
210 Just ( label, current ) ->
214 , { style = Dict.fromList box.style
216 , isVisible = box.isVisible
217 , textMetrics = box.textMetrics
227 runTest (List.length model.finished) foundData label current
229 case model.upcoming of
233 , finished = model.finished ++ [ currentResults ]
235 , report (encodeForReport (currentResults :: model.finished))
238 newCurrent :: remaining ->
240 | finished = model.finished ++ [ currentResults ]
241 , current = Just newCurrent
242 , upcoming = remaining
244 , Task.perform (always Analyze)
252 case model.current of
258 Just ( label, current ) ->
260 , analyze (Testable.getIds current)
264view : Model Msg -> Html.Html Msg
266 case model.current of
268 if List.isEmpty model.upcoming then
271 getByIndex model.selected model.finished
275 , Element.inFront (Element.html (viewElementHighlight model))
276 , Element.height Element.fill
279 Element.row [ Element.width Element.fill, Element.height Element.fill ]
283 |> Element.maximum 900
286 , Element.height Element.fill
291 , Element.padding 100
294 , Border.color palette.lightGrey
299 , Font.color palette.lightGrey
301 (Element.text "test case")
306 Element.text "nothing selected"
309 Testable.toElement sel.element
315 , Element.width Element.fill
316 , Element.height Element.fill
320 |> List.sortBy hasFailure
321 |> List.map (viewResult model.selected)
328 Just ( label, current ) ->
329 Testable.toHtml current
334 (\elem ( index, found ) ->
336 ( index + 1, Just elem )
346viewElementHighlight model =
347 case model.highlightDomId of
351 Just highlightDomId ->
354 highlightDomId ++ " { outline: solid black; }"
359 |> String.append "#tests-"
362 testId ++ " { outline: dashed black; }"
372 [ Html.text styleSheet
376hasFailure : WithResults (Testable.Element Msg) -> Int
389isExpectationPassing result =
391 Testable.Todo label ->
394 Testable.Expect details ->
398isPassing layoutTest =
399 List.all isExpectationPassing layoutTest.expectations
402viewResult : Int -> WithResults (Testable.Element Msg) -> Element.Element Msg
403viewResult selectedIndex myTest =
404 if myTest.index == selectedIndex then
409 [ Element.el [ Font.size 24 ] (Element.text myTest.label)
411 [ Element.alignLeft, Element.spacing 16 ]
413 |> groupBy .elementDomId
414 |> List.map (expandDetails >> viewLayoutTestGroup)
420 ( passing, failing ) =
421 List.partition isPassing myTest.results
427 , Events.onClick (Select myTest.index)
429 [ Element.row [ Element.spacing 16 ]
430 [ Element.el [ Font.size 16 ] (Element.text myTest.label)
431 , Element.text (String.fromInt (List.length passing) ++ " passing")
436 if failingCount == 0 then
440 Element.text (String.fromInt (List.length failing) ++ " failing")
446 case group.members of
449 , elementType = Testable.EmptyType
450 , members = group.members
455 , elementType = top.elementType
456 , members = group.members
461 groupWhile (\one two -> fn one == fn two) list
463 (\( fst, remaining ) ->
465 , members = fst :: remaining
470groupWhile : (a -> a -> Bool) -> List a -> List ( a, List a )
471groupWhile isSameGroup items =
478 ( y, restOfGroup ) :: groups ->
479 if isSameGroup x y then
480 ( x, y :: restOfGroup ) :: groups
489viewLayoutTestGroup group =
494 |> String.append "tests-"
498 , Element.htmlAttribute (Html.Attributes.id testId)
499 , Events.onMouseEnter (HighlightDomID (Just group.id))
500 , Events.onMouseLeave (HighlightDomID Nothing)
501 , Element.htmlAttribute (Html.Attributes.style "user-select" "none")
503 [ Element.row [ Element.spacing 16 ]
504 [ Element.el [] (Element.text (Testable.elementTypeToString group.elementType))
505 , Element.el [ Font.color palette.lightGrey ] (Element.text group.id)
509 , Element.paddingXY 32 0
511 (List.map viewLayoutTest group.members)
515type alias Grouped thing =
517 , members : List thing
521viewLayoutTest layoutTest =
525 [ Element.row [ Element.spacing 8 ]
526 [ Element.el [ Font.bold ] (Element.text layoutTest.label)
528 -- , Element.el [ Font.color palette.lightGrey ] (Element.text layoutTest.elementDomId)
530 , Element.column [ Element.spacing 8 ]
531 (List.map viewLayoutExpectation layoutTest.expectations)
535viewLayoutExpectation expectation =
537 Testable.Todo label ->
538 Element.row [ Element.spacing 4 ]
539 [ todo, Element.text label ]
541 Testable.Expect details ->
542 if details.result then
543 Element.row [ Element.spacing 4 ]
544 [ pass, Element.text details.description ]
547 Element.row [ Element.spacing 4 ]
548 [ fail, Element.text details.description ]
553 [ Background.color color
554 , Font.color palette.black
555 , Element.paddingXY 4 8
562 badge palette.lightGrey "todo"
566 badge palette.green "pass"
570 badge palette.red "fail"
573formatKeyValue : String -> String -> String
574formatKeyValue key val =
583 { description : String
591port test : String -> Cmd msg
594port analyze : List String -> Cmd msg
600 , bbox : Testable.BoundingBox
601 , style : List ( String, String )
603 , 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