@@ -1,632 +0,0 @@
1−port 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)
7−import Dict exposing (Dict)
9−import Element.Background as Background
10−import Element.Border as Border
11−import Element.Font as Font
14−import Html exposing (Html)
19−import Test.Runner.Failure
21−import Tests exposing (Testable)
22−import Time exposing (Time)
25−init : ( Model Msg, Cmd Msg )
27− ( { current = Nothing
32− -- generateTests (Random.initialSeed 227852860) 1
34− , stage = BeginRendering
40−main : Program Never (Model Msg) Msg
46− , subscriptions = subscriptions
50−type alias Model msg =
51− { current : Maybe (Testable msg)
52− , upcoming : List (Testable msg)
53− , finished : List (Testable msg)
64− , bbox : Testable.BoundingBox
65− , style : Testable.Style
77−runTest : 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 }
93−generateTests : Random.Seed -> Int -> List (Testable msg)
94−generateTests seed num =
100− ( testable, newSeed ) =
103− testable :: generateTests newSeed (num - 1)
106−generateTest : Random.Seed -> ( Testable msg, Random.Seed )
110− |> flip Random.step seed
111− |> (\( ( val, shrinker ), newSeed ) -> ( val, seed ))
114−update : 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 }
194−subscriptions : { a | stage : Stage } -> Sub Msg
195−subscriptions model =
197− [ styles RefreshBoundingBox
198− , case model.stage of
200− AnimationFrame.times Tick
203− AnimationFrame.times Tick
210−port analyze : List String -> Cmd msg
213−port styles : (List { id : String, bbox : Testable.BoundingBox, style : Testable.Style } -> msg) -> Sub msg
216−view : Model Msg -> Html Msg
218− case model.current of
220− if model.stage == Finished then
221− Element.layout [] <|
223− [ Element.spacing 20
224− , Element.padding 20
225− , Element.width (Element.px 800)
227− -- , Background.color Color.grey
229− (List.map viewResult model.finished)
232− Html.text "running?"
235− Testable.render current.element
238−viewResult : Testable Msg -> Element.Element Msg
239−viewResult testable =
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
260− , Element.spacing 25
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
272− , Element.padding 20
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
289−type alias Testable msg =
290− { element : Testable.Element msg
297− { given : Maybe String
298− , description : String
299− , reason : Test.Runner.Failure.Reason
306−attr tag label attr test =
308− [ Testable.Attr attr
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
361−type alias PossibleAttributes msg =
362− { width : String -> Testable.Attr msg
363− , height : String -> Testable.Attr msg
367−possibleToList str { width, height } =
368− width str :: height str :: []
371−availableAttributes : { width : Float, height : Float } -> Fuzz.Fuzzer (PossibleAttributes msg)
372−availableAttributes bounds =
373− Fuzz.map2 PossibleAttributes
375− (List.map Fuzz.constant (widths bounds.width))
378− (List.map Fuzz.constant (heights bounds.height))
382−widths : 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
416−heights : 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
448−content : Testable.Element msg
451− [ Testable.Attr <| Element.width (Element.px 20)
452− , Testable.Attr <| Element.height (Element.px 20)
457−tests : 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"
497− [ widthFill "on row"
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
532−allIndividualTestables : List (Fuzz.Fuzzer TestableElement)
533−allIndividualTestables =
536− , Fuzz.constant Column
540−testableLayout : Fuzz.Fuzzer (Testable msg)
545− , label = "A Sweet Test"
549− Fuzz.map asTestable layout
552−layout : 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)
566−createElement : String -> TestableElement -> PossibleAttributes msg -> Testable.Element msg
567−createElement tag layout possibleAttrs =
570− possibleToList tag possibleAttrs
574− Testable.El attrs content
584− Testable.Column attrs
591−createContainer : ( PossibleAttributes msg, PossibleAttributes msg, PossibleAttributes msg ) -> PossibleAttributes msg -> TestableElement -> TestableElement -> Testable.Element msg
592−createContainer ( 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,
618−choose 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]
630−allPossibilities : List (List a) -> List (List a)
632− List.Extra.cartesianProduct