git.iko.soy/typeable/elm-ui
on master help sign in
adjust tests to be mor sensitive to text wrapping
commitd5c8a943eacb8a47790445637e10df8517bce0b5 authorElm UI Automation <automation@elm-ui.com> dateSat 16 May 2020, 10:44 (6 years ago) parent1ed9f79
7 files changed+300−178
tests-rendering/src/Testable.elm+6−3 tests-rendering/src/Testable/Element.elm+114−83 tests-rendering/src/Testable/Generator.elm+109−30 tests-rendering/src/Testable/Runner.elm+43−25 tests-rendering/src/Tests/All.elm+3−1 tests-rendering/src/Tests/Run.elm+5−23 tests-rendering/src/Tests/TextWrapping.elm+20−13
tests-rendering/src/Testable.elm+6−3
@@ -162,6 +162,9 @@ type LayoutContext
162162 | InRow
163163 | InEl
164164 | InColumn
165+ | InParagraph
166+ | InTextCol
167+ | AtRoot
165168
166169
167170type alias Surroundings msg =
@@ -491,7 +494,7 @@ runTests harvested el =
491494 , parentSpacing = 0
492495 , level = [ 0, 0 ]
493496 , element = el
494− , location = InEl
497+ , location = AtRoot
495498 }
496499
497500
@@ -590,10 +593,10 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
590593 InColumn
591594
592595 TextColumn _ _ ->
593− InColumn
596+ InTextCol
594597
595598 Paragraph _ _ ->
596− InRow
599+ InParagraph
597600
598601 Text _ ->
599602 InEl
tests-rendering/src/Testable/Element.elm+114−83
@@ -307,6 +307,11 @@ paddingXY x y =
307307 }
308308
309309
310+listIf ls =
311+ List.filter Tuple.first ls
312+ |> List.map Tuple.second
313+
314+
310315widthHelper maybeMin maybeMax len =
311316 let
312317 addMin l =
@@ -465,12 +470,31 @@ widthHelper maybeMin maybeMax len =
465470 totalChildren + horizontalPadding
466471
467472 expectedLines =
468− ceiling (totalCalculatedWidth / context.self.bbox.width)
473+ if boxChildrenHeight > 20 then
474+ ceiling (boxChildrenHeight / 20)
475+
476+ else
477+ ceiling (totalCalculatedWidth / context.self.bbox.width)
478+
479+ boxChildrenHeight =
480+ context.children
481+ |> List.map
482+ (\c ->
483+ c.bbox.height
484+ )
485+ |> List.sum
469486 in
470− [ Testable.rounded "text wrapping, checking height"
471− { expected = toFloat (expectedLines * 22)
472− , found = context.self.bbox.height
473− }
487+ [ Testable.true "text wrapping, checking height"
488+ -- all we're doing here is testing if wrapping is occurring
489+ -- not the exact height, which is a little tricky to calculate perfectly without more information.
490+ (if expectedLines > 1 then
491+ context.self.bbox.height >= (20 * 2)
492+
493+ else
494+ -- then it's less than 2 ~ line heights
495+ -- there's some weird variance here which makes it hard to be exact.
496+ context.self.bbox.height < (20 * 2)
497+ )
474498 ]
475499
476500 _ ->
@@ -504,23 +528,21 @@ widthHelper maybeMin maybeMax len =
504528
505529 horizontalPadding =
506530 context.self.bbox.padding.left + context.self.bbox.padding.right
507−
508− _ =
509− Debug.log "widths"
510− { children =
511− context.children
512− |> List.map childWidth
513− , text = List.map .width context.self.textMetrics
514− }
515531 in
516− [ Testable.rounded "equals children"
517− { expected = totalChildren + horizontalPadding
518− , found = context.self.bbox.width
519− }
520− , Testable.lessThanOrEqual "not larger than parent"
521− context.self.bbox.width
522− context.parent.bbox.width
523− ]
532+ listIf
533+ [ ( (context.parentLayout /= Testable.InParagraph)
534+ && (context.parentLayout /= Testable.InTextCol)
535+ , Testable.rounded "equals children"
536+ { expected = totalChildren + horizontalPadding
537+ , found = context.self.bbox.width
538+ }
539+ )
540+ , ( context.parentLayout /= Testable.AtRoot
541+ , Testable.lessThanOrEqual "not larger than parent"
542+ context.self.bbox.width
543+ context.parent.bbox.width
544+ )
545+ ]
524546
525547 Testable.Row rowAttrs _ ->
526548 -- width of row is the sum of all children widths
@@ -544,14 +566,19 @@ widthHelper maybeMin maybeMax len =
544566 totalSpacing =
545567 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
546568 in
547− [ expectRoundedEquality
548− { expected = totalChildren + horizontalPadding + totalSpacing
549− , found = context.self.bbox.width
550− }
551− , Testable.lessThanOrEqual "not larger than parent"
552− context.self.bbox.width
553− context.parent.bbox.width
554− ]
569+ listIf
570+ [ ( True
571+ , expectRoundedEquality
572+ { expected = totalChildren + horizontalPadding + totalSpacing
573+ , found = context.self.bbox.width
574+ }
575+ )
576+ , ( context.parentLayout /= Testable.AtRoot
577+ , Testable.lessThanOrEqual "not larger than parent"
578+ context.self.bbox.width
579+ context.parent.bbox.width
580+ )
581+ ]
555582
556583 Testable.Column _ _ ->
557584 -- The width of the column is the width of the widest child.
@@ -575,14 +602,19 @@ widthHelper maybeMin maybeMax len =
575602 |> List.map childWidth
576603 |> List.append textChildren
577604 in
578− [ expectRoundedEquality
579− { expected = Maybe.withDefault 0 (List.maximum allChildren)
580− , found = context.self.bbox.width
581− }
582− , Testable.lessThanOrEqual "not larger than parent"
583− context.self.bbox.width
584− context.parent.bbox.width
585− ]
605+ listIf
606+ [ ( True
607+ , expectRoundedEquality
608+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
609+ , found = context.self.bbox.width
610+ }
611+ )
612+ , ( context.parentLayout /= Testable.AtRoot
613+ , Testable.lessThanOrEqual "not larger than parent"
614+ context.self.bbox.width
615+ context.parent.bbox.width
616+ )
617+ ]
586618
587619 Testable.TextColumn _ _ ->
588620 -- The width of the column is the width of the widest child.
@@ -606,14 +638,19 @@ widthHelper maybeMin maybeMax len =
606638 |> List.map childWidth
607639 |> List.append textChildren
608640 in
609− [ expectRoundedEquality
610− { expected = Maybe.withDefault 0 (List.maximum allChildren)
611− , found = context.self.bbox.width
612− }
613− , Testable.lessThanOrEqual "not larger than parent"
614− context.self.bbox.width
615− context.parent.bbox.width
616− ]
641+ listIf
642+ [ ( True
643+ , expectRoundedEquality
644+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
645+ , found = context.self.bbox.width
646+ }
647+ )
648+ , ( context.parentLayout /= Testable.AtRoot
649+ , Testable.lessThanOrEqual "not larger than parent"
650+ context.self.bbox.width
651+ context.parent.bbox.width
652+ )
653+ ]
617654
618655 Testable.Paragraph _ _ ->
619656 -- This should be the size it's text,
@@ -631,14 +668,19 @@ widthHelper maybeMin maybeMax len =
631668 horizontalPadding =
632669 context.self.bbox.padding.left + context.self.bbox.padding.right
633670 in
634− [ expectRoundedEquality
635− { expected = totalChildren + horizontalPadding
636− , found = context.self.bbox.width
637− }
638− , Testable.lessThanOrEqual "not larger than parent"
639− context.self.bbox.width
640− context.parent.bbox.width
641− ]
671+ listIf
672+ [ ( True
673+ , expectRoundedEquality
674+ { expected = totalChildren + horizontalPadding
675+ , found = context.self.bbox.width
676+ }
677+ )
678+ , ( context.parentLayout /= Testable.AtRoot
679+ , Testable.lessThanOrEqual "not larger than parent"
680+ context.self.bbox.width
681+ context.parent.bbox.width
682+ )
683+ ]
642684
643685 Testable.Text _ ->
644686 []
@@ -792,20 +834,17 @@ heightHelper maybeMin maybeMax len =
792834 childHeight child =
793835 child.bbox.height
794836 in
795− [ if List.isEmpty context.children then
837+ if List.isEmpty context.children then
796838 -- context.self.textMetrics
797839 -- |> List.map Testable.textHeight
798840 -- |> List.sum
799841 -- TODO: apparently the font metrics we have are for the literal characters rendered
800842 -- not for the font itself.
801− -- so for now, we are stubbing this in as 20, which is the default font size + line height.
802− Testable.rounded "expected multiple of 20"
803− { expected = context.self.bbox.height
804− , found = toFloat (List.length context.self.textMetrics * 20)
805− }
843+ [ Testable.todo "calculate height from actual text metrics"
844+ ]
806845
807− else
808− expectRoundedEquality
846+ else
847+ [ expectRoundedEquality
809848 { expected =
810849 context.children
811850 |> List.map childHeight
@@ -813,28 +852,26 @@ heightHelper maybeMin maybeMax len =
813852 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
814853 , found = context.self.bbox.height
815854 }
816− , Testable.lessThanOrEqual "not larger than parent"
817− context.self.bbox.height
818− context.parent.bbox.height
819− ]
855+ , Testable.lessThanOrEqual "not larger than parent"
856+ context.self.bbox.height
857+ context.parent.bbox.height
858+ ]
820859
821860 Testable.Row _ _ ->
822861 let
823862 childHeight child =
824863 child.bbox.height
825864 in
826− [ if List.isEmpty context.children then
865+ if List.isEmpty context.children then
827866 -- context.self.textMetrics
828867 -- |> List.map Testable.textHeight
829868 -- |> List.sum
830869 -- TODO: apparently the font metrics we have are for the literal characters rendered
831870 -- not for the font itself.
832− -- so for now, we are stubbing this in as 20, which is the default font size.
833− Testable.true "expected multiple of 20"
834− ((round context.self.bbox.height |> modBy 20) == 0)
871+ [ Testable.todo "calculate height from actual text metrics" ]
835872
836− else
837− expectRoundedEquality
873+ else
874+ [ expectRoundedEquality
838875 { expected =
839876 context.children
840877 |> List.map childHeight
@@ -843,10 +880,10 @@ heightHelper maybeMin maybeMax len =
843880 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
844881 , found = context.self.bbox.height
845882 }
846− , Testable.lessThanOrEqual "not larger than parent"
847− context.self.bbox.height
848− context.parent.bbox.height
849− ]
883+ , Testable.lessThanOrEqual "not larger than parent"
884+ context.self.bbox.height
885+ context.parent.bbox.height
886+ ]
850887
851888 Testable.Column colAttrs _ ->
852889 let
@@ -878,16 +915,10 @@ heightHelper maybeMin maybeMax len =
878915 ]
879916
880917 Testable.TextColumn _ _ ->
881− [ Testable.lessThanOrEqual "not larger than parent"
882− context.self.bbox.height
883− context.parent.bbox.height
884− ]
918+ []
885919
886920 Testable.Paragraph _ _ ->
887− [ Testable.lessThanOrEqual "not larger than parent"
888− context.self.bbox.height
889− context.parent.bbox.height
890− ]
921+ []
891922
892923 Testable.Text _ ->
893924 []
tests-rendering/src/Testable/Generator.elm+109−30
@@ -20,37 +20,38 @@ element : String -> List (Testable.Attr msg) -> List ( String, Testable.Element
2020element label attrs =
2121 -- [ ( label, paragraph attrs [ short ] )
2222 -- ]
23− mapEveryCombo
24− (\makeLayout child ->
25− ( label, makeLayout attrs child )
23+ mapEveryCombo3
24+ (\( layoutLabel, makeLayout ) ( selfLabel, makeSelf ) ( childLabel, child ) ->
25+ ( label ++ " - " ++ layoutLabel ++ " > " ++ selfLabel ++ " > " ++ childLabel
26+ , makeLayout [] (makeSelf attrs child)
27+ )
2628 )
2729 layouts
30+ layouts
2831 contents
2932
3033
31−mapEveryCombo fn listOne listTwo =
32− List.concatMap
33− (\one ->
34− List.map
35− (\two ->
36− fn one two
37− )
38− listTwo
39− )
40− listOne
41−
42−
4334layouts =
44− [ \attrs child ->
45− el attrs child
46− , \attrs child ->
47− row attrs [ child ]
48− , \attrs child ->
49− column attrs [ child ]
50− , \attrs child ->
51− paragraph attrs [ child ]
52− , \attrs child ->
53− textColumn attrs [ child ]
35+ [ ( "el"
36+ , \attrs child ->
37+ el attrs child
38+ )
39+ , ( "row"
40+ , \attrs child ->
41+ row attrs [ child ]
42+ )
43+ , ( "col"
44+ , \attrs child ->
45+ column attrs [ child ]
46+ )
47+ , ( "para"
48+ , \attrs child ->
49+ paragraph attrs [ child ]
50+ )
51+ , ( "txtCol"
52+ , \attrs child ->
53+ textColumn attrs [ child ]
54+ )
5455 ]
5556
5657
@@ -65,17 +66,23 @@ nearbys =
6566
6667
6768contents =
68− [ none
69− , text short
70− , text lorem
71− , el
69+ [ ( "none", none )
70+ , ( "short text", text short )
71+ , ( "long text", text lorem )
72+ , ( "box"
73+ , box
74+ )
75+ ]
76+
77+
78+box =
79+ el
7280 [ width (px 50)
7381 , height (px 50)
7482 , Background.color (rgb (240 / 255) 0 (245 / 255))
7583 , Font.color (rgb 1 1 1)
7684 ]
7785 none
78− ]
7986
8087
8188short =
@@ -84,3 +91,75 @@ short =
8491
8592lorem =
8693 "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc."
94+
95+
96+mapEveryCombo fn listOne listTwo =
97+ List.concatMap
98+ (\one ->
99+ List.map
100+ (\two ->
101+ fn one two
102+ )
103+ listTwo
104+ )
105+ listOne
106+
107+
108+mapEveryCombo3 fn listOne listTwo listThree =
109+ List.concatMap
110+ (\one ->
111+ List.concatMap
112+ (\two ->
113+ List.map
114+ (\three ->
115+ fn one two three
116+ )
117+ listThree
118+ )
119+ listTwo
120+ )
121+ listOne
122+
123+
124+sizes render =
125+ List.concatMap
126+ (\( widthLen, heightLen ) ->
127+ [ text (Debug.toString ( widthLen, heightLen ))
128+ , render
129+ (\attrs children ->
130+ el
131+ (width widthLen
132+ :: height heightLen
133+ :: attrs
134+ )
135+ children
136+ )
137+ ]
138+ )
139+ allLengthPairs
140+
141+
142+allLengthPairs : List ( Length, Length )
143+allLengthPairs =
144+ let
145+ crossProduct len =
146+ List.map (Tuple.pair len) lengths
147+ in
148+ List.concatMap crossProduct lengths
149+
150+
151+lengths =
152+ [ px 50
153+ , fill
154+ , shrink
155+ , fill
156+ |> maximum 100
157+ , fill
158+ |> maximum 100
159+ |> minimum 50
160+ , shrink
161+ |> maximum 100
162+ , shrink
163+ |> maximum 100
164+ |> minimum 50
165+ ]
tests-rendering/src/Testable/Runner.elm+43−25
@@ -3,9 +3,9 @@ port module Testable.Runner exposing
33 , Testable
44 , TestableProgram
55 , program
6+ , rename
67 , show
78 , testable
8− , rename
99 )
1010
1111{-| -}
@@ -108,7 +108,8 @@ type alias Model msg =
108108
109109
110110type alias WithResults thing =
111− { element : thing
111+ { index : Int
112+ , element : thing
112113 , label : String
113114 , results :
114115 List Testable.LayoutTest
@@ -170,13 +171,14 @@ type Msg
170171 )
171172
172173
173−runTest : Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
174−runTest boxes label element =
174+runTest : Int -> Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
175+runTest index boxes label element =
175176 let
176177 results =
177178 Testable.runTests boxes element
178179 in
179− { element = element
180+ { index = index
181+ , element = element
180182 , label = label
181183 , results = results
182184 }
@@ -222,7 +224,7 @@ update msg model =
222224 |> Dict.fromList
223225
224226 currentResults =
225− runTest foundData label current
227+ runTest (List.length model.finished) foundData label current
226228 in
227229 case model.upcoming of
228230 [] ->
@@ -267,8 +269,6 @@ view model =
267269 let
268270 selected =
269271 getByIndex model.selected model.finished
270−
271− -- |> Debug.log "selected"
272272 in
273273 Element.layout
274274 [ Font.size 16
@@ -316,7 +316,10 @@ view model =
316316 , Element.height Element.fill
317317 , Element.scrollbarY
318318 ]
319− (List.indexedMap (viewResult model.selected) model.finished)
319+ (model.finished
320+ |> List.sortBy hasFailure
321+ |> List.map (viewResult model.selected)
322+ )
320323 ]
321324
322325 else
@@ -370,9 +373,35 @@ viewElementHighlight model =
370373 ]
371374
372375
373−viewResult : Int -> Int -> WithResults (Testable.Element Msg) -> Element.Element Msg
374−viewResult selectedIndex index myTest =
375− if index == selectedIndex then
376+hasFailure : WithResults (Testable.Element Msg) -> Int
377+hasFailure myTest =
378+ if
379+ List.any
380+ (not << isPassing)
381+ myTest.results
382+ then
383+ 0
384+
385+ else
386+ 1
387+
388+
389+isExpectationPassing result =
390+ case result of
391+ Testable.Todo label ->
392+ True
393+
394+ Testable.Expect details ->
395+ details.result
396+
397+
398+isPassing layoutTest =
399+ List.all isExpectationPassing layoutTest.expectations
400+
401+
402+viewResult : Int -> WithResults (Testable.Element Msg) -> Element.Element Msg
403+viewResult selectedIndex myTest =
404+ if myTest.index == selectedIndex then
376405 Element.column
377406 [ Element.alignLeft
378407 , Element.spacing 16
@@ -388,17 +417,6 @@ viewResult selectedIndex index myTest =
388417
389418 else
390419 let
391− isExpectationPassing result =
392− case result of
393− Testable.Todo label ->
394− True
395−
396− Testable.Expect details ->
397− details.result
398−
399− isPassing layoutTest =
400− List.all isExpectationPassing layoutTest.expectations
401−
402420 ( passing, failing ) =
403421 List.partition isPassing myTest.results
404422 in
@@ -406,10 +424,10 @@ viewResult selectedIndex index myTest =
406424 [ Element.alignLeft
407425 , Element.spacing 16
408426 , Element.pointer
409− , Events.onClick (Select index)
427+ , Events.onClick (Select myTest.index)
410428 ]
411429 [ Element.row [ Element.spacing 16 ]
412− [ Element.el [ Font.size 24 ] (Element.text myTest.label)
430+ [ Element.el [ Font.size 16 ] (Element.text myTest.label)
413431 , Element.text (String.fromInt (List.length passing) ++ " passing")
414432 , let
415433 failingCount =
tests-rendering/src/Tests/All.elm+3−1
@@ -18,7 +18,9 @@ import Tests.Transparency
1818main : Testable.Runner.TestableProgram
1919main =
2020 (Testable.Runner.program << List.concat)
21− [ -- Testable.Generator.element "Basics" []
21+ [ --Testable.Generator.element "Basics"
22+ --[]
23+ -- , Testable.Generator.element "Align " []
2224 -- Tuple.pair "Basic Element" Tests.Basic.view
2325 -- , Tuple.pair "Nearby" Tests.Nearby.view
2426 -- , Tuple.pair "Element Alignment" Tests.ElementAlignment.view
tests-rendering/src/Tests/Run.elm+5−23
@@ -1,32 +1,14 @@
11module Tests.Run exposing (main)
22
3−{-| -}
3+{-| _NOTE_ this is auto-generated! Notouchy!
4+-}
45
5−import Testable.Generator
6+import ElInFixedHeightColumn
67import Testable.Runner
7−import Tests.Basic
8−import Tests.ColumnAlignment
9−import Tests.ColumnSpacing
10−import Tests.ElementAlignment
11−import Tests.Nearby
12−import Tests.RowAlignment
13−import Tests.RowSpacing
14−import Tests.TextWrapping
15−import Tests.Transparency
168
179
1810main : Testable.Runner.TestableProgram
1911main =
20− (Testable.Runner.program << List.concat)
21− [ -- Testable.Generator.element "Basics" []
22− -- Tuple.pair "Basic Element" Tests.Basic.view
23− -- , Tuple.pair "Nearby" Tests.Nearby.view
24− -- , Tuple.pair "Element Alignment" Tests.ElementAlignment.view
25− -- , Tuple.pair "Transparency" Tests.Transparency.view
26− -- , Tuple.pair "Column Alignment" Tests.ColumnAlignment.view
27− -- -- This has 12k cases, so it runs slow and sometimes crashes IE
28− -- , Tuple.pair "Row Alignment" Tests.RowAlignment.view
29− -- , Tuple.pair "Column Spacing" Tests.ColumnSpacing.view
30− -- , Tuple.pair "Row Spacing" Tests.RowSpacing.view
31− [ Tuple.pair "Paragraph wrapping" Tests.TextWrapping.view ]
12+ Testable.Runner.program
13+ [ Testable.Runner.rename " El In Fixed Height Column" ElInFixedHeightColumn.view
3214 ]
tests-rendering/src/Tests/TextWrapping.elm+20−13
@@ -28,17 +28,24 @@ main =
2828
2929
3030view =
31− column [ paddingXY 0 100, spacing 16 ]
32− [ paragraph []
33− [ text Testable.Generator.lorem
31+ el [] <|
32+ paragraph []
33+ [ Testable.Generator.box
3434 ]
35− , paragraph []
36− [ text Testable.Generator.lorem
37− , text Testable.Generator.lorem
38− ]
39− , paragraph []
40− [ text Testable.Generator.lorem
41− , paragraph []
42− [ text Testable.Generator.lorem ]
43− ]
44− ]
35+
36+
37+
38+-- column [ spacing 16 ]
39+-- [ paragraph []
40+-- [ el [] (text Testable.Generator.short)
41+-- ]
42+-- -- , paragraph []
43+-- -- [ text Testable.Generator.lorem
44+-- -- , text Testable.Generator.lorem
45+-- -- ]
46+-- -- , paragraph []
47+-- -- [ text Testable.Generator.lorem
48+-- -- , paragraph []
49+-- -- [ text Testable.Generator.lorem ]
50+-- -- ]
51+-- ]