1port module FuzzMain exposing (Model, Msg(..), PossibleAttributes, Stage(..), Testable, TestableElement(..), allIndividualTestables, allPossibilities, analyze, attr, availableAttributes, content, createContainer, createElement, generateTest, generateTests, heightFill, heightPx, heights, init, layout, main, possibleToList, runTest, styles, subscriptions, testableLayout, tests, update, view, viewResult, widthFill, widthPx, widths)
7import Dict exposing (Dict)
9import Element.Background as Background
10import Element.Border as Border
11import Element.Font as Font
14import Html exposing (Html)
19import Test.Runner.Failure
21import Tests exposing (Testable)
22import Time exposing (Time)
25init : ( Model Msg, Cmd Msg )
32 -- generateTests (Random.initialSeed 227852860) 1
34 , stage = BeginRendering
40main : Program Never (Model Msg) Msg
46 , subscriptions = subscriptions
51 { current : Maybe (Testable msg)
52 , upcoming : List (Testable msg)
53 , finished : List (Testable msg)
64 , bbox : Testable.BoundingBox
65 , style : Testable.Style
77runTest : Dict String Testable.Found -> Testable msg -> Testable msg
81 Testable.toTest test.label boxes test.element
84 Random.initialSeed 227852860
87 Testable.runTests seed (Debug.log "created Tests" tests)
88 |> Debug.log "run tests"
90 { test | results = Just results }
93generateTests : Random.Seed -> Int -> List (Testable msg)
94generateTests seed num =
100 ( testable, newSeed ) =
103 testable :: generateTests newSeed (num - 1)
106generateTest : Random.Seed -> ( Testable msg, Random.Seed )
110 |> flip Random.step seed
111 |> (\( ( val, shrinker ), newSeed ) -> ( val, seed ))
114update : Msg -> Model Msg -> ( Model Msg, Cmd Msg )
120 RefreshBoundingBox boxes ->
121 case model.current of
123 ( { model | stage = Finished }
130 ( box.id, { style = box.style, bbox = box.bbox } )
138 runTest foundData current
140 case model.upcoming of
145 , finished = currentResults :: model.finished
150 newCurrent :: remaining ->
152 | finished = currentResults :: model.finished
153 , stage = BeginRendering
161 case model.upcoming of
163 ( { model | stage = Rendered }
167 current :: remaining ->
170 , upcoming = remaining
171 , current = Just current
177 case model.current of
179 ( { model | stage = Finished }
184 ( { model | stage = GatherData }
185 , analyze (Testable.getIds test.element)
189 ( { model | stage = Rendered }
194subscriptions : { a | stage : Stage } -> Sub Msg
197 [ styles RefreshBoundingBox
198 , case model.stage of
200 AnimationFrame.times Tick
203 AnimationFrame.times Tick
210port analyze : List String -> Cmd msg
213port styles : (List { id : String, bbox : Testable.BoundingBox, style : Testable.Style } -> msg) -> Sub msg
216view : Model Msg -> Html Msg
218 case model.current of
220 if model.stage == Finished then
225 , Element.width (Element.px 800)
227 -- , Background.color Color.grey
229 (List.map viewResult model.finished)
235 Testable.render current.element
238viewResult : Testable Msg -> Element.Element Msg
243 ( label, Nothing ) ->
245 [ Background.color Color.green
246 , Font.color Color.white
247 , Element.paddingXY 20 10
252 Element.text (label ++ " - " ++ "Success!")
254 ( label, Just { given, description, reason } ) ->
256 [ Background.color Color.red
257 , Font.color Color.white
258 , Element.paddingXY 20 10
263 [ Element.el [ Element.width Element.fill ] <| Element.text label
265 -- , Element.el [ Element.width Element.fill ] <| Element.text description
266 , Element.el [ Element.width Element.fill ] <| Element.text (toString reason)
271 , Border.color Color.lightGrey
273 , Element.height Element.shrink
276 [ Element.el [ Font.bold ] (Element.text testable.label)
277 , Element.column [ Element.alignLeft, Element.spacing 20 ]
278 (case testable.results of
280 [ Element.text "no results" ]
283 List.map viewSingle results
289type alias Testable msg =
290 { element : Testable.Element msg
297 { given : Maybe String
298 , description : String
299 , reason : Test.Runner.Failure.Reason
306attr tag label attr test =
311 Test.test (tag ++ ": " ++ label) <|
320 (Element.width Element.fill)
324 context.parent.bbox.width / toFloat (List.length context.siblings + 1)
326 Expect.equal spacePerPortion context.self.bbox.width
333 (Element.height Element.fill)
337 context.parent.bbox.height / toFloat (List.length context.siblings + 1)
339 Expect.equal spacePerPortion context.self.bbox.height
345 ("height at " ++ toString px ++ "px")
346 (Element.height (Element.px (round px)))
348 Expect.equal found.self.bbox.height px
354 ("width at " ++ toString px ++ "px")
355 (Element.width (Element.px (round px)))
357 Expect.equal found.self.bbox.width px
361type alias PossibleAttributes msg =
362 { width : String -> Testable.Attr msg
363 , height : String -> Testable.Attr msg
367possibleToList str { width, height } =
368 width str :: height str :: []
371availableAttributes : { width : Float, height : Float } -> Fuzz.Fuzzer (PossibleAttributes msg)
372availableAttributes bounds =
373 Fuzz.map2 PossibleAttributes
375 (List.map Fuzz.constant (widths bounds.width))
378 (List.map Fuzz.constant (heights bounds.height))
382widths : Float -> List (String -> Testable.Attr msg)
386 (" with width at " ++ toString width ++ "px")
387 (Element.width (Element.px (round width)))
389 Expect.equal found.self.bbox.width width
394 (Element.width Element.fill)
399 -- totalparentwidth - (paddingLeft ++ paddingRight)
400 -- minus widths of all the other children
403 -- Debug.log "width" <|
405 -- Debug.log "widths" <|
406 List.map (\child -> child.bbox.width) context.siblings
409 context.parent.bbox.width - otherWidth
411 Expect.equal spacePerPortion context.self.bbox.width
416heights : Float -> List (String -> Testable.Attr msg)
420 (" with height at " ++ toString height ++ "px")
421 (Element.height (Element.px (round height)))
423 Expect.equal found.self.bbox.height height
428 (Element.height Element.fill)
433 -- totalparentwidth - (paddingLeft ++ paddingRight)
434 -- minus widths of all the other children
438 List.map (\child -> child.bbox.height) context.siblings
441 context.parent.bbox.height - otherHeight
443 Expect.equal spacePerPortion context.self.bbox.height
448content : Testable.Element msg
451 [ Testable.Attr <| Element.width (Element.px 20)
452 , Testable.Attr <| Element.height (Element.px 20)
457tests : List (Testable msg)
459 [ { label = "Width/Height 200"
463 [ widthPx 200 "single element"
464 , heightPx 200 "single element"
468 , { label = "Width Fill/Height Fill - 1"
472 [ widthFill "single element"
473 , heightFill "single element"
478 , { label = "Width Fill/Height Fill - 2"
482 [ widthFill "top element"
483 , heightFill "top element"
487 [ widthFill "embedded element"
488 , heightFill "embedded element"
493 , { label = "Row Width Fill/Height Fill"
498 , heightFill "on row"
501 [ widthFill "row - 1"
502 , heightFill "row - 1"
506 [ widthFill "row - 2"
507 , heightFill "row - 2"
511 [ widthFill "row - 3"
512 , heightFill "row - 3"
521{- Generating A Complete Test Suite
532allIndividualTestables : List (Fuzz.Fuzzer TestableElement)
533allIndividualTestables =
536 , Fuzz.constant Column
540testableLayout : Fuzz.Fuzzer (Testable msg)
545 , label = "A Sweet Test"
549 Fuzz.map asTestable layout
552layout : Fuzz.Fuzzer (Testable.Element msg)
554 Fuzz.map4 createContainer
556 ( availableAttributes { width = 20, height = 20 }
557 , availableAttributes { width = 20, height = 20 }
558 , availableAttributes { width = 20, height = 20 }
561 (availableAttributes { width = 200, height = 200 })
562 (Fuzz.oneOf allIndividualTestables)
563 (Fuzz.oneOf allIndividualTestables)
566createElement : String -> TestableElement -> PossibleAttributes msg -> Testable.Element msg
567createElement tag layout possibleAttrs =
570 possibleToList tag possibleAttrs
574 Testable.El attrs content
584 Testable.Column attrs
591createContainer : ( PossibleAttributes msg, PossibleAttributes msg, PossibleAttributes msg ) -> PossibleAttributes msg -> TestableElement -> TestableElement -> Testable.Element msg
592createContainer ( a1, a2, a3 ) possibleAttrs parent child =
595 possibleToList "0" possibleAttrs
599 Testable.El attrs (createElement "0-0" child a1)
603 [ createElement "0-0" child a1
604 , createElement "0-1" child a2
605 , createElement "0-2" child a3
609 Testable.Column attrs
610 [ createElement "0-0" child a1
611 , createElement "0-1" child a2
612 , createElement "0-2" child a3
616{-| Given a list of a list of possibilities,
618choose once from each list.
620 [ [width (px 100), width fill]
621 , [height (px 100), height fill]
625 [ [width (px 100), height (px 100)]
626 , [width (px 100), height fill]
630allPossibilities : List (List a) -> List (List a)
632 List.Extra.cartesianProduct
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