git.iko.soy/typeable/elm-ui
on master help sign in
expand width and height testing to be informed by what the element is that's being tested
5f880a7Elm UI Automation
tests-rendering/cases/open/WeirdCentering.elm+13−3
@@ -7,13 +7,23 @@ import Testable.Element.Background as Background
7
7
8main =
8main =
9 layout [] <|
9 layout [] <|
10+ -- row [] [ el [] (text "Example with centerX:") ]
10 column []
11 column []
11 [ text "Example with centerX:"
12 [ text "Example with centerX:"
12 , row
13 , row
13 [ width fill ]
14 [ width fill ]
15+ [ row
16+ [ centerX
14− [ row [ centerX, Background.color <| rgb 0 1 0 ]
17+ , Background.color <| rgb 0 1 0
18+ ]
19+ [ paragraph
20+ [ width shrink
21+ ]
15− [ paragraph [ width shrink ] [ text "Hello world" ]
22+ [ text "Hello world" ]
23+ , paragraph
24+ [ width shrink
25+ ]
16− , paragraph [ width shrink ] [ text "Hello world" ]
26+ [ text "Hello world" ]
17 ]
27 ]
18 ]
28 ]
19 , text "Example without centerX:"
29 , text "Example without centerX:"
tests-rendering/src/Testable.elm+94−46
@@ -3,6 +3,7 @@ module Testable exposing
3 , AttributeId(..)
3 , AttributeId(..)
4 , BoundingBox
4 , BoundingBox
5 , Element(..)
5 , Element(..)
6+ , ElementType(..)
6 , Found
7 , Found
7 , LayoutContext(..)
8 , LayoutContext(..)
8 , LayoutExpectation(..)
9 , LayoutExpectation(..)
@@ -10,13 +11,16 @@ module Testable exposing
10 , Location(..)
11 , Location(..)
11 , Style
12 , Style
12 , Surroundings
13 , Surroundings
14+ , TextMetrics
13 , compareFormattedColor
15 , compareFormattedColor
16+ , elementTypeToString
14 , equal
17 , equal
15 , formatColor
18 , formatColor
16 , formatColorWithAlpha
19 , formatColorWithAlpha
17 , getIds
20 , getIds
18 , getSpacing
21 , getSpacing
19 , runTests
22 , runTests
23+ , textHeight
20 , toElement
24 , toElement
21 , toHtml
25 , toHtml
22 , todo
26 , todo
@@ -43,6 +47,66 @@ type Element msg
43 | Empty
47 | Empty
44
48
45
49
50+type ElementType
51+ = ElType
52+ | RowType
53+ | ColumnType
54+ | TextColumnType
55+ | ParagraphType
56+ | TextType
57+ | EmptyType
58+
59+
60+elementTypeToString : ElementType -> String
61+elementTypeToString elem =
62+ case elem of
63+ ElType ->
64+ "El"
65+
66+ RowType ->
67+ "Row"
68+
69+ ColumnType ->
70+ "Column"
71+
72+ TextColumnType ->
73+ "TextColumn"
74+
75+ ParagraphType ->
76+ "Paragraph"
77+
78+ TextType ->
79+ "Text"
80+
81+ EmptyType ->
82+ "Empty"
83+
84+
85+toElementType : Element msg -> ElementType
86+toElementType elem =
87+ case elem of
88+ El _ _ ->
89+ ElType
90+
91+ Row _ _ ->
92+ RowType
93+
94+ Column _ _ ->
95+ ColumnType
96+
97+ TextColumn _ _ ->
98+ TextColumnType
99+
100+ Paragraph _ _ ->
101+ ParagraphType
102+
103+ Text _ ->
104+ TextType
105+
106+ Empty ->
107+ EmptyType
108+
109+
46{-| We have an attribute id in order to remove tests when an overriding attribtue is assigned.
110{-| We have an attribute id in order to remove tests when an overriding attribtue is assigned.
47
111
48Basically, we want to implictly test for height/width shrink.
112Basically, we want to implictly test for height/width shrink.
@@ -61,7 +125,7 @@ type AttributeId
61type Attr msg
125type Attr msg
62 = Attr (Element.Attribute msg)
126 = Attr (Element.Attribute msg)
63 | AttrTest
127 | AttrTest
64− { test : Surroundings -> List LayoutExpectation
128+ { test : Surroundings msg -> List LayoutExpectation
65 , label : String
129 , label : String
66 , id : AttributeId
130 , id : AttributeId
67 }
131 }
@@ -70,11 +134,11 @@ type Attr msg
70 | Nearby
134 | Nearby
71 { location : Location
135 { location : Location
72 , element : Element msg
136 , element : Element msg
73− , test : Surroundings -> List LayoutExpectation
137+ , test : Surroundings msg -> List LayoutExpectation
74 , label : String
138 , label : String
75 }
139 }
76 | LabeledTest
140 | LabeledTest
77− { test : Surroundings -> List LayoutExpectation
141+ { test : Surroundings msg -> List LayoutExpectation
78 , label : String
142 , label : String
79 , attr : Element.Attribute msg
143 , attr : Element.Attribute msg
80 , id : AttributeId
144 , id : AttributeId
@@ -97,14 +161,15 @@ type LayoutContext
97 | InColumn
161 | InColumn
98
162
99
163
100−type alias Surroundings =
164+type alias Surroundings msg =
101 { siblings : List Found
165 { siblings : List Found
102 , parent : Found
166 , parent : Found
103 , children : List Found
167 , children : List Found
104 , self : Found
168 , self : Found
169+ , selfElement : Element msg
105
170
106 -- These values are needed to perform some types of tests.
171 -- These values are needed to perform some types of tests.
107− , location : LayoutContext
172+ , parentLayout : LayoutContext
108 , parentSpacing : Int
173 , parentSpacing : Int
109 }
174 }
110
175
@@ -113,9 +178,24 @@ type alias Found =
113 { bbox : BoundingBox
178 { bbox : BoundingBox
114 , style : Style
179 , style : Style
115 , isVisible : Bool
180 , isVisible : Bool
181+ , textMetrics : List TextMetrics
182+ }
183+
184+
185+type alias TextMetrics =
186+ { actualBoundingBoxAscent : Float
187+ , actualBoundingBoxDescent : Float
188+ , actualBoundingBoxLeft : Float
189+ , actualBoundingBoxRight : Float
190+ , width : Float
116 }
191 }
117
192
118
193
194+textHeight metrics =
195+ metrics.actualBoundingBoxAscent
196+ + metrics.actualBoundingBoxDescent
197+
198+
119{-| -}
199{-| -}
120type alias Style =
200type alias Style =
121 Dict String String
201 Dict String String
@@ -147,6 +227,7 @@ type LayoutExpectation
147
227
148type alias LayoutTest =
228type alias LayoutTest =
149 { elementDomId : String
229 { elementDomId : String
230+ , elementType : ElementType
150 , label : String
231 , label : String
151 , expectations : List LayoutExpectation
232 , expectations : List LayoutExpectation
152 }
233 }
@@ -351,6 +432,7 @@ runTests harvested el =
351 case maybeFound of
432 case maybeFound of
352 Nothing ->
433 Nothing ->
353 [ { elementDomId = "se-0"
434 [ { elementDomId = "se-0"
435+ , elementType = EmptyType
354 , label = "Finding root element"
436 , label = "Finding root element"
355 , expectations =
437 , expectations =
356 [ Expect
438 [ Expect
@@ -548,8 +630,9 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
548 { siblings = siblings
630 { siblings = siblings
549 , parent = parent
631 , parent = parent
550 , self = self
632 , self = self
633+ , selfElement = element
551 , children = childrenFoundData
634 , children = childrenFoundData
552− , location = location
635+ , parentLayout = location
553 , parentSpacing = parentSpacing
636 , parentSpacing = parentSpacing
554 }
637 }
555 attr
638 attr
@@ -570,6 +653,7 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
570
653
571 _ ->
654 _ ->
572 [ { elementDomId = id
655 [ { elementDomId = id
656+ , elementType = EmptyType
573 , label = "Finding element in DOM"
657 , label = "Finding element in DOM"
574 , expectations =
658 , expectations =
575 [ Expect
659 [ Expect
@@ -609,7 +693,7 @@ createAttributeTest :
609 -> Dict String Found
693 -> Dict String Found
610 -> List Int
694 -> List Int
611 -> Int
695 -> Int
612− -> Surroundings
696+ -> Surroundings msg
613 -> Attr msg
697 -> Attr msg
614 -> List LayoutTest
698 -> List LayoutTest
615createAttributeTest parent cache level attrIndex surroundings attr =
699createAttributeTest parent cache level attrIndex surroundings attr =
@@ -626,6 +710,8 @@ createAttributeTest parent cache level attrIndex surroundings attr =
626
710
627 AttrTest details ->
711 AttrTest details ->
628 [ { elementDomId = domId
712 [ { elementDomId = domId
713+ , elementType =
714+ toElementType surroundings.selfElement
629 , label = details.label
715 , label = details.label
630 , expectations = details.test surroundings
716 , expectations = details.test surroundings
631 }
717 }
@@ -658,6 +744,7 @@ createAttributeTest parent cache level attrIndex surroundings attr =
658
744
659 LabeledTest { label, test } ->
745 LabeledTest { label, test } ->
660 [ { elementDomId = domId
746 [ { elementDomId = domId
747+ , elementType = toElementType surroundings.selfElement
661 , label = label
748 , label = label
662 , expectations = test surroundings
749 , expectations = test surroundings
663 }
750 }
@@ -689,45 +776,6 @@ addAttribute attr el =
689 Text str
776 Text str
690
777
691
778
692−
693−-- runTests :
694−-- Random.Seed
695−-- -> Test
696−-- ->
697−-- List
698−-- ( String
699−-- , Maybe
700−-- { given : Maybe String
701−-- , description : String
702−-- , reason : Test.Runner.Failure.Reason
703−-- }
704−-- )
705−-- runTests seed tests =
706−-- let
707−-- run runner =
708−-- let
709−-- ran =
710−-- List.map Test.Runner.getFailureReason (runner.run ())
711−-- in
712−-- List.map2 Tuple.pair runner.labels ran
713−-- results =
714−-- case Test.Runner.fromTest 100 seed tests of
715−-- Test.Runner.Plain rnrs ->
716−-- List.map run rnrs
717−-- Test.Runner.Only rnrs ->
718−-- List.map run rnrs
719−-- Test.Runner.Skipping rnrs ->
720−-- List.map run rnrs
721−-- Test.Runner.Invalid invalid ->
722−-- let
723−-- _ =
724−-- Debug.log "Invalid tests" invalid
725−-- in
726−-- []
727−-- in
728−-- List.concat results
729−
730−
731compareFormattedColor : Color -> String -> Bool
779compareFormattedColor : Color -> String -> Bool
732compareFormattedColor color expected =
780compareFormattedColor color expected =
733 formatColor color == expected || formatColorWithAlpha color == expected
781 formatColor color == expected || formatColorWithAlpha color == expected
tests-rendering/src/Testable/Element.elm+204−80
@@ -96,8 +96,8 @@ none =
96
96
97
97
98paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
98paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99−paragraph =
99+paragraph attrs =
100− Testable.Paragraph
100+ Testable.Paragraph (implicitWidthHeightShrink attrs)
101
101
102
102
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
@@ -366,7 +366,7 @@ widthHelper maybeMin maybeMax len =
366 )
366 )
367 , test =
367 , test =
368 \context ->
368 \context ->
369− if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
369+ if List.member context.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
370 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
370 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
371
371
372 else
372 else
@@ -374,7 +374,7 @@ widthHelper maybeMin maybeMax len =
374 parentAvailableWidth =
374 parentAvailableWidth =
375 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
375 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
376 in
376 in
377− [ case context.location of
377+ [ case context.parentLayout of
378 Testable.IsNearby _ ->
378 Testable.IsNearby _ ->
379 Testable.true "Nearby Element has fill width"
379 Testable.true "Nearby Element has fill width"
380 ((floor context.parent.bbox.width == floor context.self.bbox.width)
380 ((floor context.parent.bbox.width == floor context.self.bbox.width)
@@ -415,36 +415,110 @@ widthHelper maybeMin maybeMax len =
415 , id = Testable.IsWidth
415 , id = Testable.IsWidth
416 , test =
416 , test =
417 \context ->
417 \context ->
418− let
418+ case context.selfElement of
419+ Testable.El _ _ ->
420+ let
419− childWidth child =
421+ childWidth child =
420− -- TODO: add margin values to widths
422+ child.bbox.width
423+
424+ totalChildren =
425+ context.children
426+ |> List.map childWidth
427+ |> List.append (List.map .width context.self.textMetrics)
428+ |> List.sum
429+
430+ horizontalPadding =
431+ context.self.bbox.padding.left + context.self.bbox.padding.right
432+ in
433+ [ expectRoundedEquality
434+ { expected = totalChildren + horizontalPadding
435+ , found = context.self.bbox.width
436+ }
437+ ]
438+
439+ Testable.Row _ _ ->
440+ -- width of row is the sum of all children widths
441+ -- both text elements and others.
442+ let
443+ childWidth child =
421− child.bbox.width
444+ child.bbox.width
422−
445+
423− totalChildren =
446+ totalChildren =
424− context.children
447+ context.children
425− |> List.map childWidth
448+ |> List.map childWidth
449+ |> List.append (List.map .width context.self.textMetrics)
426− |> List.sum
450+ |> List.sum
427−
451+
428− horizontalPadding =
452+ horizontalPadding =
429− context.self.bbox.padding.left + context.self.bbox.padding.right
453+ context.self.bbox.padding.left + context.self.bbox.padding.right
430−
454+
431− spacingValue =
455+ spacingValue =
432− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
456+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
433− in
457+ in
434− if totalChildren == 0 then
458+ [ expectRoundedEquality
435− -- TODO: The issue is that we have a hard time measuring `text` elements
459+ { expected = totalChildren + horizontalPadding + spacingValue
436− -- So if a element has a text child, then it's width isn't going to show up in the system.
460+ , found = context.self.bbox.width
437− [ Testable.Todo "Calculate text size for width-shrink calculation"
461+ }
462+ ]
463+
464+ Testable.Column _ _ ->
465+ -- The width of the column is the width of the widest child.
466+ let
467+ childWidth child =
468+ child.bbox.width
469+ + context.self.bbox.padding.left
470+ + context.self.bbox.padding.right
471+
472+ textChildren =
473+ List.map
474+ (\txt ->
475+ txt.width
476+ + context.self.bbox.padding.left
477+ + context.self.bbox.padding.right
478+ )
479+ context.self.textMetrics
480+
481+ allChildren =
482+ context.children
483+ |> List.map childWidth
484+ |> List.append textChildren
485+ in
486+ [ expectRoundedEquality
487+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
488+ , found = context.self.bbox.width
489+ }
490+ ]
491+
492+ Testable.TextColumn _ _ ->
438− ]
493+ []
439
494
440− else
495+ Testable.Paragraph _ _ ->
441− -- This fails if this element is actually a column
496+ -- This should be the size it's text,
442− -- So we need to capture what this element is in order to do this calculation.
497+ -- unless it takes up all available space, in which case it should wrap.
498+ let
499+ childWidth child =
500+ child.bbox.width
501+
502+ totalChildren =
503+ context.children
504+ |> List.map childWidth
505+ |> List.append (List.map .width context.self.textMetrics)
506+ |> List.sum
507+
508+ horizontalPadding =
509+ context.self.bbox.padding.left + context.self.bbox.padding.right
510+ in
443− [ expectRoundedEquality
511+ [ expectRoundedEquality
444− { expected = totalChildren + horizontalPadding + spacingValue
512+ { expected = totalChildren + horizontalPadding
445− , found = context.self.bbox.width
513+ , found = context.self.bbox.width
446− }
514+ }
515+ ]
516+
517+ Testable.Text _ ->
518+ []
519+
520+ Testable.Empty ->
447− ]
521+ []
448 }
522 }
449
523
450
524
@@ -535,7 +609,7 @@ heightHelper maybeMin maybeMax len =
535 , id = Testable.IsHeight
609 , id = Testable.IsHeight
536 , test =
610 , test =
537 \context ->
611 \context ->
538− [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
612+ [ if List.member context.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
539 Testable.true "height fill doesn't apply to above/below elements" True
613 Testable.true "height fill doesn't apply to above/below elements" True
540
614
541 else
615 else
@@ -543,7 +617,7 @@ heightHelper maybeMin maybeMax len =
543 parentAvailableHeight =
617 parentAvailableHeight =
544 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
618 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
545 in
619 in
546− case context.location of
620+ case context.parentLayout of
547 Testable.IsNearby _ ->
621 Testable.IsNearby _ ->
548 Testable.true "Nearby Element has fill height"
622 Testable.true "Nearby Element has fill height"
549 ((floor context.parent.bbox.height == floor context.self.bbox.height)
623 ((floor context.parent.bbox.height == floor context.self.bbox.height)
@@ -584,36 +658,86 @@ heightHelper maybeMin maybeMax len =
584 , id = Testable.IsHeight
658 , id = Testable.IsHeight
585 , test =
659 , test =
586 \context ->
660 \context ->
661+ case context.selfElement of
662+ Testable.El _ _ ->
587− let
663+ let
588− childHeight child =
664+ childHeight child =
589− -- TODO: add margin values to heights
665+ -- TODO: add margin values to heights
590− child.bbox.height
666+ child.bbox.height
591−
667+
592− totalChildren =
668+ totalChildren =
593− context.children
669+ context.children
594− |> List.map childHeight
670+ |> List.map childHeight
671+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
595− |> List.sum
672+ |> List.sum
596−
673+
597− verticalPadding =
674+ verticalPadding =
598− context.self.bbox.padding.top + context.self.bbox.padding.bottom
675+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
599−
676+
600− spacingValue =
677+ spacingValue =
601− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
678+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
602− in
679+ in
603− if totalChildren == 0 then
680+ [ expectRoundedEquality
604− -- TODO: The issue is that we have a hard time measuring `text` elements
681+ { expected = totalChildren + verticalPadding + spacingValue
605− -- So if a element has a text child, then it's height isn't going to show up in the system.
682+ , found = context.self.bbox.height
606− [ Testable.Todo "Calculate expected height shrink"
683+ }
684+ ]
685+
686+ Testable.Row _ _ ->
687+ let
688+ childHeight child =
689+ child.bbox.height
690+
691+ totalChildren =
692+ context.children
693+ |> List.map childHeight
694+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
695+ |> List.maximum
696+ |> Maybe.withDefault 0
697+
698+ verticalPadding =
699+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
700+ in
701+ [ expectRoundedEquality
702+ { expected = totalChildren + verticalPadding
703+ , found = context.self.bbox.height
704+ }
705+ ]
706+
707+ Testable.Column _ _ ->
708+ let
709+ childHeight child =
710+ child.bbox.height
711+
712+ totalChildren =
713+ context.children
714+ |> List.map childHeight
715+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
716+ |> List.sum
717+
718+ verticalPadding =
719+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
720+
721+ spacingValue =
722+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
723+ in
724+ [ expectRoundedEquality
725+ { expected = totalChildren + verticalPadding + spacingValue
726+ , found = context.self.bbox.height
727+ }
728+ ]
729+
730+ Testable.TextColumn _ _ ->
607− ]
731+ []
608
732
609− else
733+ Testable.Paragraph _ _ ->
610− -- This fails if this element is actually a column
734+ []
611− -- So we need to capture what this element is in order to do this calculation.
735+
612− [ expectRoundedEquality
736+ Testable.Text _ ->
613− { expected = totalChildren + verticalPadding + spacingValue
737+ []
614− , found = context.self.bbox.height
738+
615− }
739+ Testable.Empty ->
616− ]
740+ []
617 }
741 }
618
742
619
743
@@ -716,11 +840,11 @@ alignLeft =
716 , id = Testable.NoId
840 , id = Testable.NoId
717 , test =
841 , test =
718 \found ->
842 \found ->
719− [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
843+ [ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
720 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
844 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
721
845
722 else if
846 else if
723− List.member found.location
847+ List.member found.parentLayout
724 [ Testable.IsNearby Testable.InFront
848 [ Testable.IsNearby Testable.InFront
725 , Testable.IsNearby Testable.Behind
849 , Testable.IsNearby Testable.Behind
726 , Testable.IsNearby Testable.Above
850 , Testable.IsNearby Testable.Above
@@ -739,7 +863,7 @@ alignLeft =
739 }
863 }
740
864
741 else
865 else
742− case found.location of
866+ case found.parentLayout of
743 Testable.InRow ->
867 Testable.InRow ->
744 let
868 let
745 siblingsOnLeft =
869 siblingsOnLeft =
@@ -785,7 +909,7 @@ centerX =
785 parentCenter =
909 parentCenter =
786 found.parent.bbox.left + (found.parent.bbox.width / 2)
910 found.parent.bbox.left + (found.parent.bbox.width / 2)
787 in
911 in
788− if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
912+ if List.member found.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
789 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
913 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
790
914
791 else if List.length found.siblings == 0 then
915 else if List.length found.siblings == 0 then
@@ -796,7 +920,7 @@ centerX =
796 ]
920 ]
797
921
798 else
922 else
799− case found.location of
923+ case found.parentLayout of
800 Testable.InRow ->
924 Testable.InRow ->
801 let
925 let
802 siblingsOnLeft =
926 siblingsOnLeft =
@@ -850,11 +974,11 @@ alignRight =
850 , id = Testable.NoId
974 , id = Testable.NoId
851 , test =
975 , test =
852 \found ->
976 \found ->
853− if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
977+ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
854 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
978 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
855
979
856 else if
980 else if
857− List.member found.location
981+ List.member found.parentLayout
858 [ Testable.IsNearby Testable.InFront
982 [ Testable.IsNearby Testable.InFront
859 , Testable.IsNearby Testable.Behind
983 , Testable.IsNearby Testable.Behind
860 , Testable.IsNearby Testable.Above
984 , Testable.IsNearby Testable.Above
@@ -875,7 +999,7 @@ alignRight =
875 ]
999 ]
876
1000
877 else
1001 else
878− case found.location of
1002+ case found.parentLayout of
879 Testable.InRow ->
1003 Testable.InRow ->
880 let
1004 let
881 siblingsOnRight =
1005 siblingsOnRight =
@@ -913,11 +1037,11 @@ alignTop =
913 , id = Testable.NoId
1037 , id = Testable.NoId
914 , test =
1038 , test =
915 \found ->
1039 \found ->
916− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1040+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
917 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
1041 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
918
1042
919 else if
1043 else if
920− List.member found.location
1044+ List.member found.parentLayout
921 [ Testable.IsNearby Testable.InFront
1045 [ Testable.IsNearby Testable.InFront
922 , Testable.IsNearby Testable.Behind
1046 , Testable.IsNearby Testable.Behind
923 , Testable.IsNearby Testable.OnRight
1047 , Testable.IsNearby Testable.OnRight
@@ -938,7 +1062,7 @@ alignTop =
938 ]
1062 ]
939
1063
940 else
1064 else
941− case found.location of
1065+ case found.parentLayout of
942 Testable.InColumn ->
1066 Testable.InColumn ->
943 let
1067 let
944 siblingsAbove =
1068 siblingsAbove =
@@ -976,11 +1100,11 @@ alignBottom =
976 , id = Testable.NoId
1100 , id = Testable.NoId
977 , test =
1101 , test =
978 \found ->
1102 \found ->
979− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1103+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
980 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
1104 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
981
1105
982 else if
1106 else if
983− List.member found.location
1107+ List.member found.parentLayout
984 [ Testable.IsNearby Testable.InFront
1108 [ Testable.IsNearby Testable.InFront
985 , Testable.IsNearby Testable.Behind
1109 , Testable.IsNearby Testable.Behind
986 , Testable.IsNearby Testable.OnRight
1110 , Testable.IsNearby Testable.OnRight
@@ -1001,7 +1125,7 @@ alignBottom =
1001 ]
1125 ]
1002
1126
1003 else
1127 else
1004− case found.location of
1128+ case found.parentLayout of
1005 Testable.InColumn ->
1129 Testable.InColumn ->
1006 let
1130 let
1007 siblingsBelow =
1131 siblingsBelow =
@@ -1058,7 +1182,7 @@ centerY =
1058 parentCenter =
1182 parentCenter =
1059 found.parent.bbox.top + (found.parent.bbox.height / 2)
1183 found.parent.bbox.top + (found.parent.bbox.height / 2)
1060 in
1184 in
1061− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1185+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1062 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
1186 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
1063
1187
1064 else if List.length found.siblings == 0 then
1188 else if List.length found.siblings == 0 then
@@ -1069,7 +1193,7 @@ centerY =
1069 ]
1193 ]
1070
1194
1071 else
1195 else
1072− case found.location of
1196+ case found.parentLayout of
1073 Testable.InColumn ->
1197 Testable.InColumn ->
1074 let
1198 let
1075 siblingsOnTop =
1199 siblingsOnTop =
tests-rendering/src/Testable/Runner.elm+23−13
@@ -138,7 +138,7 @@ type Msg
138 , bbox : Testable.BoundingBox
138 , bbox : Testable.BoundingBox
139 , style : List ( String, String )
139 , style : List ( String, String )
140 , isVisible : Bool
140 , isVisible : Bool
141− , textMetrics : List TextMetrics
141+ , textMetrics : List Testable.TextMetrics
142 }
142 }
143 )
143 )
144
144
@@ -180,6 +180,7 @@ update msg model =
180 , { style = Dict.fromList box.style
180 , { style = Dict.fromList box.style
181 , bbox = box.bbox
181 , bbox = box.bbox
182 , isVisible = box.isVisible
182 , isVisible = box.isVisible
183+ , textMetrics = box.textMetrics
183 }
184 }
184 )
185 )
185
186
@@ -339,11 +340,26 @@ viewResult testable =
339 [ Element.alignLeft, Element.spacing 16 ]
340 [ Element.alignLeft, Element.spacing 16 ]
340 (testable.results
341 (testable.results
341 |> groupBy .elementDomId
342 |> groupBy .elementDomId
342− |> List.map viewLayoutTestGroup
343+ |> List.map (expandDetails >> viewLayoutTestGroup)
343 )
344 )
344 ]
345 ]
345
346
346
347
348+expandDetails group =
349+ case group.members of
350+ [] ->
351+ { id = group.id
352+ , elementType = Testable.EmptyType
353+ , members = group.members
354+ }
355+
356+ top :: _ ->
357+ { id = group.id
358+ , elementType = top.elementType
359+ , members = group.members
360+ }
361+
362+
347groupBy fn list =
363groupBy fn list =
348 groupWhile (\one two -> fn one == fn two) list
364 groupWhile (\one two -> fn one == fn two) list
349 |> List.map
365 |> List.map
@@ -387,7 +403,10 @@ viewLayoutTestGroup group =
387 , Events.onMouseLeave (HighlightDomID Nothing)
403 , Events.onMouseLeave (HighlightDomID Nothing)
388 , Element.htmlAttribute (Html.Attributes.style "user-select" "none")
404 , Element.htmlAttribute (Html.Attributes.style "user-select" "none")
389 ]
405 ]
406+ [ Element.row [ Element.spacing 16 ]
407+ [ Element.el [] (Element.text (Testable.elementTypeToString group.elementType))
390− [ Element.el [ Font.color palette.lightGrey ] (Element.text group.id)
408+ , Element.el [ Font.color palette.lightGrey ] (Element.text group.id)
409+ ]
391 , Element.column
410 , Element.column
392 [ Element.spacing 8
411 [ Element.spacing 8
393 , Element.paddingXY 32 0
412 , Element.paddingXY 32 0
@@ -484,17 +503,8 @@ port styles :
484 , bbox : Testable.BoundingBox
503 , bbox : Testable.BoundingBox
485 , style : List ( String, String )
504 , style : List ( String, String )
486 , isVisible : Bool
505 , isVisible : Bool
487− , textMetrics : List TextMetrics
506+ , textMetrics : List Testable.TextMetrics
488 }
507 }
489 -> msg
508 -> msg
490 )
509 )
491 -> Sub msg
510 -> Sub msg
492−
493−
494−type alias TextMetrics =
495− { actualBoundingBoxAscent : Float
496− , actualBoundingBoxDescent : Float
497− , actualBoundingBoxLeft : Float
498− , actualBoundingBoxRight : Float
499− , width : Float
500− }