@@ -58,7 +58,6 @@ In order to run the test:
59import Dict
59import Dict
60import Element
60import Element
62import Html.Attributes
61import Html.Attributes
63import Testable
62import Testable
64import Testable.Runner
63import Testable.Runner
@@ -67,7 +66,7 @@ import Testable.Runner
67layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
66layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
68layout attrs elem =
67layout attrs elem =
69 Testable.Runner.program
68 Testable.Runner.program
70− [ ( "Open Case", elem )
69+ [ ( "Tests Run", elem )
@@ -77,18 +76,18 @@ text =
79el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
78el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
81− Testable.El
80+ Testable.El (implicitWidthHeightShrink attrs)
84row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
83row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
86− Testable.Row
85+ Testable.Row (implicitWidthHeightShrink attrs)
89column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
88column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
90−column =
89+column attrs =
91− Testable.Column
90+ Testable.Column (implicitWidthHeightShrink attrs)
94none : Testable.Element msg
93none : Testable.Element msg
@@ -102,8 +101,8 @@ paragraph =
104textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
105−textColumn =
104+textColumn attrs =
106− Testable.TextColumn
105+ Testable.TextColumn (implicitWidthHeightShrink attrs)
109{-| Old labeling mechanism that i removed to hastily
108{-| Old labeling mechanism that i removed to hastily
@@ -182,6 +181,7 @@ transparent on =
184 , attr = Element.transparent on
183 , attr = Element.transparent on
184+ , id = Testable.NoId
186 \context ->
186 \context ->
@@ -204,9 +204,9 @@ transparent on =
205isVisible : Testable.Attr msg
205isVisible : Testable.Attr msg
206isVisible =
206isVisible =
207− Testable.LabeledTest
207+ Testable.AttrTest
208 { label = "is-visible"
208 { label = "is-visible"
209− , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
209+ , id = Testable.NoId
211 \context ->
211 \context ->
212 [ Testable.equal context.self.isVisible True ]
212 [ Testable.equal context.self.isVisible True ]
@@ -219,6 +219,7 @@ alpha a =
219 Testable.LabeledTest
219 Testable.LabeledTest
220 { label = "alpha-" ++ String.fromFloat a
220 { label = "alpha-" ++ String.fromFloat a
221 , attr = Element.alpha a
221 , attr = Element.alpha a
222+ , id = Testable.NoId
223 \context ->
224 \context ->
@@ -237,6 +238,7 @@ padding pad =
237 Testable.LabeledTest
238 Testable.LabeledTest
238 { label = "padding " ++ String.fromInt pad
239 { label = "padding " ++ String.fromInt pad
239 , attr = Element.padding pad
240 , attr = Element.padding pad
241+ , id = Testable.NoId
241 \found ->
243 \found ->
242 [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
244 [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
@@ -257,6 +259,7 @@ paddingXY x y =
257 Testable.LabeledTest
259 Testable.LabeledTest
258 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
260 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
259 , attr = Element.paddingXY x y
261 , attr = Element.paddingXY x y
262+ , id = Testable.NoId
261 \found ->
264 \found ->
262 [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
265 [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
@@ -332,6 +335,7 @@ widthHelper maybeMin maybeMax len =
332 -- Pixel values should ignore min and max?
335 -- Pixel values should ignore min and max?
333 Testable.LabeledTest
336 Testable.LabeledTest
334 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
337 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
338+ , id = Testable.IsWidth
336 Element.width
340 Element.width
337 (Element.px val
341 (Element.px val
@@ -353,6 +357,7 @@ widthHelper maybeMin maybeMax len =
355 "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
359 "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
360+ , id = Testable.IsWidth
357 Element.width
362 Element.width
358 (Element.fillPortion portion
363 (Element.fillPortion portion
@@ -407,6 +412,7 @@ widthHelper maybeMin maybeMax len =
407 |> addMin
412 |> addMin
408 |> addMax
413 |> addMax
415+ , id = Testable.IsWidth
411 \context ->
417 \context ->
@@ -428,12 +434,17 @@ widthHelper maybeMin maybeMax len =
428 if totalChildren == 0 then
434 if totalChildren == 0 then
429 -- TODO: The issue is that we have a hard time measuring `text` elements
435 -- TODO: The issue is that we have a hard time measuring `text` elements
430 -- So if a element has a text child, then it's width isn't going to show up in the system.
436 -- So if a element has a text child, then it's width isn't going to show up in the system.
431− [ expectRoundedEquality context.self.bbox.width context.self.bbox.width ]
437+ [ Testable.Todo "Calculate text size for width-shrink calculation"
434 -- This fails if this element is actually a column
441 -- This fails if this element is actually a column
435 -- So we need to capture what this element is in order to do this calculation.
442 -- So we need to capture what this element is in order to do this calculation.
443+ [ expectRoundedEquality
436− [ expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width ]
444+ { expected = totalChildren + horizontalPadding + spacingValue
445+ , found = context.self.bbox.width
@@ -502,6 +513,7 @@ heightHelper maybeMin maybeMax len =
502 |> addMin
513 |> addMin
503 |> addMax
514 |> addMax
516+ , id = Testable.IsHeight
506 \found ->
518 \found ->
507 [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
519 [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
@@ -520,6 +532,7 @@ heightHelper maybeMin maybeMax len =
520 |> addMin
532 |> addMin
521 |> addMax
533 |> addMax
535+ , id = Testable.IsHeight
524 \context ->
537 \context ->
525 [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
538 [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
@@ -568,16 +581,17 @@ heightHelper maybeMin maybeMax len =
568 |> addMin
581 |> addMin
569 |> addMax
582 |> addMax
584+ , id = Testable.IsHeight
572 \context ->
586 \context ->
574− childWidth child =
588+ childHeight child =
575 -- TODO: add margin values to heights
589 -- TODO: add margin values to heights
576 child.bbox.height
590 child.bbox.height
578 totalChildren =
592 totalChildren =
579 context.children
593 context.children
580− |> List.map childWidth
594+ |> List.map childHeight
581 |> List.sum
595 |> List.sum
583 verticalPadding =
597 verticalPadding =
@@ -589,12 +603,17 @@ heightHelper maybeMin maybeMax len =
589 if totalChildren == 0 then
603 if totalChildren == 0 then
590 -- TODO: The issue is that we have a hard time measuring `text` elements
604 -- TODO: The issue is that we have a hard time measuring `text` elements
591 -- So if a element has a text child, then it's height isn't going to show up in the system.
605 -- So if a element has a text child, then it's height isn't going to show up in the system.
592− [ expectRoundedEquality context.self.bbox.height context.self.bbox.height ]
606+ [ Testable.Todo "Calculate expected height shrink"
595 -- This fails if this element is actually a column
610 -- This fails if this element is actually a column
596 -- So we need to capture what this element is in order to do this calculation.
611 -- So we need to capture what this element is in order to do this calculation.
612+ [ expectRoundedEquality
597− [ expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height ]
613+ { expected = totalChildren + verticalPadding + spacingValue
614+ , found = context.self.bbox.height
@@ -615,6 +634,7 @@ spacing space =
615 , Testable.LabeledTest
634 , Testable.LabeledTest
616 { label = "spacing: " ++ String.fromInt space
635 { label = "spacing: " ++ String.fromInt space
617 , attr = Element.spacing space
636 , attr = Element.spacing space
637+ , id = Testable.NoId
619 \found ->
639 \found ->
@@ -693,6 +713,7 @@ alignLeft =
693 Testable.LabeledTest
713 Testable.LabeledTest
694 { label = "alignLeft"
714 { label = "alignLeft"
695 , attr = Element.alignLeft
715 , attr = Element.alignLeft
716+ , id = Testable.NoId
697 \found ->
718 \found ->
698 [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
719 [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
@@ -707,13 +728,15 @@ alignLeft =
709 expectRoundedEquality
730 expectRoundedEquality
710− found.self.bbox.left
731+ { found = found.self.bbox.left
711− found.parent.bbox.left
732+ , expected = found.parent.bbox.left
713 else if List.length found.siblings == 0 then
735 else if List.length found.siblings == 0 then
714 expectRoundedEquality
736 expectRoundedEquality
715− found.self.bbox.left
737+ { found = found.self.bbox.left
716− (found.parent.bbox.left + found.parent.bbox.padding.left)
738+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
719 case found.location of
742 case found.location of
@@ -731,13 +754,15 @@ alignLeft =
731 |> List.sum
754 |> List.sum
733 expectRoundedEquality
756 expectRoundedEquality
734− found.self.bbox.left
757+ { found = found.self.bbox.left
735− (found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings))
758+ , expected = found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings)
738 expectRoundedEquality
762 expectRoundedEquality
739− found.self.bbox.left
763+ { found = found.self.bbox.left
740− (found.parent.bbox.left + found.parent.bbox.padding.left)
764+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
@@ -748,6 +773,7 @@ centerX =
748 Testable.LabeledTest
773 Testable.LabeledTest
749 { label = "centerX"
774 { label = "centerX"
750 , attr = Element.centerX
775 , attr = Element.centerX
776+ , id = Testable.NoId
752 \found ->
778 \found ->
@@ -764,8 +790,9 @@ centerX =
765 else if List.length found.siblings == 0 then
791 else if List.length found.siblings == 0 then
766 [ expectRoundedEquality
792 [ expectRoundedEquality
767− selfCenter
793+ { found = selfCenter
768− parentCenter
794+ , expected = parentCenter
@@ -800,12 +827,17 @@ centerX =
802 [ expectRoundedEquality
829 [ expectRoundedEquality
803− selfCenter
830+ { found = selfCenter
804− expectedCenter
831+ , expected = expectedCenter
808− [ expectRoundedEquality selfCenter parentCenter ]
836+ [ expectRoundedEquality
837+ { found = selfCenter
838+ , expected = parentCenter
@@ -815,6 +847,7 @@ alignRight =
815 Testable.LabeledTest
847 Testable.LabeledTest
816 { label = "alignRight"
848 { label = "alignRight"
817 , attr = Element.alignRight
849 , attr = Element.alignRight
850+ , id = Testable.NoId
819 \found ->
852 \found ->
820 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
853 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
@@ -829,14 +862,16 @@ alignRight =
831 [ expectRoundedEquality
864 [ expectRoundedEquality
832− found.self.bbox.right
865+ { found = found.self.bbox.right
833− found.parent.bbox.right
866+ , expected = found.parent.bbox.right
836 else if List.length found.siblings == 0 then
870 else if List.length found.siblings == 0 then
837 [ expectRoundedEquality
871 [ expectRoundedEquality
838− found.self.bbox.right
872+ { found = found.self.bbox.right
839− (found.parent.bbox.right + found.parent.bbox.padding.right)
873+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
@@ -855,14 +890,16 @@ alignRight =
855 |> List.sum
890 |> List.sum
857 [ expectRoundedEquality
892 [ expectRoundedEquality
858− found.self.bbox.right
893+ { found = found.self.bbox.right
859− (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
894+ , expected = found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings)
863 [ expectRoundedEquality
899 [ expectRoundedEquality
864− found.self.bbox.right
900+ { found = found.self.bbox.right
865− (found.parent.bbox.right + found.parent.bbox.padding.right)
901+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
@@ -873,6 +910,7 @@ alignTop =
873 Testable.LabeledTest
910 Testable.LabeledTest
874 { label = "alignTop"
911 { label = "alignTop"
875 , attr = Element.alignTop
912 , attr = Element.alignTop
913+ , id = Testable.NoId
877 \found ->
915 \found ->
878 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
916 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
@@ -887,14 +925,16 @@ alignTop =
889 [ expectRoundedEquality
927 [ expectRoundedEquality
890− found.self.bbox.top
928+ { found = found.self.bbox.top
891− found.parent.bbox.top
929+ , expected = found.parent.bbox.top
894 else if List.length found.siblings == 0 then
933 else if List.length found.siblings == 0 then
895 [ expectRoundedEquality
934 [ expectRoundedEquality
896− found.self.bbox.top
935+ { found = found.self.bbox.top
897− (found.parent.bbox.top + found.parent.bbox.padding.top)
936+ , expected = found.parent.bbox.top + found.parent.bbox.padding.top
@@ -913,14 +953,16 @@ alignTop =
913 |> List.sum
953 |> List.sum
915 [ expectRoundedEquality
955 [ expectRoundedEquality
916− found.self.bbox.top
956+ { found = found.self.bbox.top
917− (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
957+ , expected = found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings)
921 [ expectRoundedEquality
962 [ expectRoundedEquality
922− found.self.bbox.top
963+ { found = found.self.bbox.top
923− found.parent.bbox.top
964+ , expected = found.parent.bbox.top
@@ -931,6 +973,7 @@ alignBottom =
931 Testable.LabeledTest
973 Testable.LabeledTest
932 { label = "alignBottom"
974 { label = "alignBottom"
933 , attr = Element.alignBottom
975 , attr = Element.alignBottom
976+ , id = Testable.NoId
935 \found ->
978 \found ->
936 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
979 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
@@ -945,14 +988,16 @@ alignBottom =
947 [ expectRoundedEquality
990 [ expectRoundedEquality
948− found.self.bbox.bottom
991+ { found = found.self.bbox.bottom
949− found.parent.bbox.bottom
992+ , expected = found.parent.bbox.bottom
952 else if List.length found.siblings == 0 then
996 else if List.length found.siblings == 0 then
953 [ expectRoundedEquality
997 [ expectRoundedEquality
954− found.self.bbox.bottom
998+ { found = found.self.bbox.bottom
955− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
999+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
@@ -971,22 +1016,25 @@ alignBottom =
971 |> List.sum
1016 |> List.sum
973 [ expectRoundedEquality
1018 [ expectRoundedEquality
974− found.self.bbox.bottom
1019+ { found = found.self.bbox.bottom
975− (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
1020+ , expected = found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings)
979 [ expectRoundedEquality
1025 [ expectRoundedEquality
980− found.self.bbox.bottom
1026+ { found = found.self.bbox.bottom
981− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1027+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
986−expectRoundedEquality x y =
1033+expectRoundedEquality : { expected : Float, found : Float } -> Testable.LayoutExpectation
1034+expectRoundedEquality { expected, found } =
987 Testable.true
1035 Testable.true
988− ("within 1 of each other " ++ floatToString x ++ ", " ++ floatToString y)
1036+ ("expected " ++ floatToString expected ++ ", found " ++ floatToString found)
989− (abs (x - y) < 1)
1037+ (abs (expected - found) < 1)
992floatToString : Float -> String
1040floatToString : Float -> String
@@ -1000,6 +1048,7 @@ centerY =
1000 Testable.LabeledTest
1048 Testable.LabeledTest
1001 { label = "centerY"
1049 { label = "centerY"
1002 , attr = Element.centerY
1050 , attr = Element.centerY
1051+ , id = Testable.NoId
1003 , test =
1052 , test =
1004 \found ->
1053 \found ->
@@ -1014,8 +1063,9 @@ centerY =
1015 else if List.length found.siblings == 0 then
1064 else if List.length found.siblings == 0 then
1016 [ expectRoundedEquality
1065 [ expectRoundedEquality
1017− selfCenter
1066+ { found = selfCenter
1018− parentCenter
1067+ , expected = parentCenter
@@ -1050,12 +1100,17 @@ centerY =
1052 [ expectRoundedEquality
1102 [ expectRoundedEquality
1053− selfCenter
1103+ { found = selfCenter
1054− expectedCenter
1104+ , expected = expectedCenter
1058− [ expectRoundedEquality selfCenter parentCenter ]
1109+ [ expectRoundedEquality
1110+ { found = selfCenter
1111+ , expected = parentCenter
@@ -1068,7 +1123,11 @@ above element =
1068 , label = "above"
1123 , label = "above"
1069 , test =
1124 , test =
1070 \found ->
1125 \found ->
1071− [ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top ]
1126+ [ expectRoundedEquality
1127+ { found = found.self.bbox.bottom
1128+ , expected = found.parent.bbox.top
@@ -1081,7 +1140,11 @@ below element =
1081 , label = "below"
1140 , label = "below"
1082 , test =
1141 , test =
1083 \found ->
1142 \found ->
1084− [ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom ]
1143+ [ expectRoundedEquality
1144+ { found = found.self.bbox.top
1145+ , expected = found.parent.bbox.bottom
@@ -1094,7 +1157,11 @@ onRight element =
1094 , label = "onRight"
1157 , label = "onRight"
1095 , test =
1158 , test =
1096 \found ->
1159 \found ->
1097− [ expectRoundedEquality found.self.bbox.left found.parent.bbox.right ]
1160+ [ expectRoundedEquality
1161+ { found = found.self.bbox.left
1162+ , expected = found.parent.bbox.right
@@ -1107,7 +1174,11 @@ onLeft element =
1107 , label = "onLeft"
1174 , label = "onLeft"
1108 , test =
1175 , test =
1109 \found ->
1176 \found ->
1110− [ expectRoundedEquality found.self.bbox.right found.parent.bbox.left ]
1177+ [ expectRoundedEquality
1178+ { found = found.self.bbox.right
1179+ , expected = found.parent.bbox.left
@@ -1173,3 +1244,85 @@ behindContent element =
1173 \found ->
1244 \found ->
1174 [ withinHelper found ]
1245 [ withinHelper found ]
1250+{- Implicit width/height calcualtions -}
1253+implicitWidthHeightShrink attrs =
1256+ implicitTest (widthHelper Nothing Nothing Shrink)
1257+ :: implicitTest (heightHelper Nothing Nothing Shrink)
1260+ skipOverridden withImplicits
1265+ Testable.LabeledTest details ->
1268+ Testable.AttrTest details ->
1277+ (\attr ( found, caught ) ->
1280+ case attrId attr of
1284+ Testable.IsWidth ->
1286+ , { hasWidth = True
1287+ , hasHeight = found.hasHeight
1291+ Testable.IsHeight ->
1293+ , { hasWidth = found.hasWidth
1306+ ( { hasWidth = False
1307+ , hasHeight = False
1316+{-| This is taking a normal test and rmoving its ability to attach a real `Element` attribute.
1320+ Testable.LabeledTest details ->
1322+ { test = details.test
1323+ , label = "Implicit -> " ++ details.label