@@ -10,6 +10,7 @@ module Testable.Element exposing
15 , expectRoundedEquality
16 , expectRoundedEquality
@@ -20,6 +21,7 @@ module Testable.Element exposing
20 , isVisible
21 , isVisible
25 , moveDown
27 , moveDown
@@ -36,10 +38,14 @@ module Testable.Element exposing
42 , textColumn
47 , textColumn
43 , transparent
49 , transparent
@@ -58,17 +64,21 @@ In order to run the test:
59import Dict
65import Dict
60import Element
66import Element
62import Html.Attributes
67import Html.Attributes
63import Testable
68import Testable
64import Testable.Runner
69import Testable.Runner
72+{-| This is used when we want to run all tests in a test suite instead of one at a time.
74+toProgram : Testable.Runner.Testable -> Testable.Runner.TestableProgram
76+ Testable.Runner.program [ testable ]
67−layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
79+layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.Testable
68layout attrs elem =
80layout attrs elem =
69− Testable.Runner.program
81+ Testable.Runner.testable "Test" elem
70− [ ( "Open Case", elem )
74text : String -> Testable.Element msg
84text : String -> Testable.Element msg
@@ -77,18 +87,18 @@ text =
79el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
89el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
81− Testable.El
91+ Testable.El (implicitWidthHeightShrink attrs)
84row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
94row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
86− Testable.Row
96+ Testable.Row (implicitWidthHeightShrink attrs)
89column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
90−column =
100+column attrs =
91− Testable.Column
101+ Testable.Column (implicitWidthHeightShrink attrs)
94none : Testable.Element msg
104none : Testable.Element msg
@@ -97,13 +107,60 @@ none =
99paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
109paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
100−paragraph =
110+paragraph attrs =
113+ implicitTest (widthHelper Nothing Nothing (Fill 1))
114+ :: implicitTest (heightHelper Nothing Nothing Shrink)
101− Testable.Paragraph
117+ Testable.Paragraph (skipOverridden withImplicits)
104textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
120textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
105−textColumn =
121+textColumn attrs =
124+ implicitTest (widthHelper (Just 500) (Just 750) (Fill 1))
125+ :: implicitTest (heightHelper Nothing Nothing Shrink)
106− Testable.TextColumn
128+ Testable.TextColumn (skipOverridden withImplicits)
132+ List (Testable.Attr msg)
135+ , label : Testable.Element msg
137+ -> Testable.Element msg
139+ Testable.Link details.url
140+ (implicitWidthHeightShrink attrs)
145+ Testable.Attr Element.clip
149+scrollbars : Testable.Attr msg
151+ Testable.Attr Element.scrollbars
155+scrollbarY : Testable.Attr msg
157+ Testable.Attr Element.scrollbarY
161+scrollbarX : Testable.Attr msg
163+ Testable.Attr Element.scrollbarX
109{-| Old labeling mechanism that i removed to hastily
166{-| Old labeling mechanism that i removed to hastily
@@ -182,6 +239,7 @@ transparent on =
184 , attr = Element.transparent on
241 , attr = Element.transparent on
242+ , id = Testable.NoId
186 \context ->
244 \context ->
@@ -204,9 +262,9 @@ transparent on =
205isVisible : Testable.Attr msg
263isVisible : Testable.Attr msg
206isVisible =
264isVisible =
207− Testable.LabeledTest
265+ Testable.AttrTest
208 { label = "is-visible"
266 { label = "is-visible"
209− , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
267+ , id = Testable.NoId
211 \context ->
269 \context ->
212 [ Testable.equal context.self.isVisible True ]
270 [ Testable.equal context.self.isVisible True ]
@@ -219,6 +277,7 @@ alpha a =
219 Testable.LabeledTest
277 Testable.LabeledTest
220 { label = "alpha-" ++ String.fromFloat a
278 { label = "alpha-" ++ String.fromFloat a
221 , attr = Element.alpha a
279 , attr = Element.alpha a
280+ , id = Testable.NoId
223 \context ->
282 \context ->
@@ -237,6 +296,7 @@ padding pad =
237 Testable.LabeledTest
296 Testable.LabeledTest
238 { label = "padding " ++ String.fromInt pad
297 { label = "padding " ++ String.fromInt pad
239 , attr = Element.padding pad
298 , attr = Element.padding pad
299+ , id = Testable.NoId
241 \found ->
301 \found ->
242 [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
302 [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
@@ -257,6 +317,7 @@ paddingXY x y =
257 Testable.LabeledTest
317 Testable.LabeledTest
258 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
318 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
259 , attr = Element.paddingXY x y
319 , attr = Element.paddingXY x y
320+ , id = Testable.NoId
261 \found ->
322 \found ->
262 [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
323 [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
@@ -273,6 +334,11 @@ paddingXY x y =
338+ List.filter Tuple.first ls
339+ |> List.map Tuple.second
276widthHelper maybeMin maybeMax len =
342widthHelper maybeMin maybeMax len =
278 addMin l =
344 addMin l =
@@ -332,6 +398,7 @@ widthHelper maybeMin maybeMax len =
332 -- Pixel values should ignore min and max?
398 -- Pixel values should ignore min and max?
333 Testable.LabeledTest
399 Testable.LabeledTest
334 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
400 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
401+ , id = Testable.IsWidth
336 Element.width
403 Element.width
337 (Element.px val
404 (Element.px val
@@ -340,7 +407,10 @@ widthHelper maybeMin maybeMax len =
342 \found ->
409 \found ->
410+ [ expectRoundedEquality
411+ { expected = toFloat val
343− [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
412+ , found = found.self.bbox.width
344 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
414 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
@@ -353,6 +423,7 @@ widthHelper maybeMin maybeMax len =
355 "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
425 "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
426+ , id = Testable.IsWidth
357 Element.width
428 Element.width
358 (Element.fillPortion portion
429 (Element.fillPortion portion
@@ -361,7 +432,7 @@ widthHelper maybeMin maybeMax len =
363 \context ->
434 \context ->
364− if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
435+ if List.member context.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
365 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
436 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
@@ -369,33 +440,93 @@ widthHelper maybeMin maybeMax len =
369 parentAvailableWidth =
440 parentAvailableWidth =
370 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
441 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
372− [ case context.location of
444+ [ case context.parentLayout of
373− Testable.IsNearby _ ->
445+ Testable.IsNearby _ ->
374− Testable.true "Nearby Element has fill width"
446+ [ Testable.true "Nearby Element has fill width"
375− ((floor context.parent.bbox.width == floor context.self.bbox.width)
447+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
376− || minMaxTest (floor context.self.bbox.width)
448+ || minMaxTest (floor context.self.bbox.width)
379− Testable.InColumn ->
452+ Testable.InColumn ->
380− Testable.true "Element within column has fill width"
453+ [ Testable.true "Element within column has fill width"
381− ((floor parentAvailableWidth == floor context.self.bbox.width)
454+ ((floor parentAvailableWidth == floor context.self.bbox.width)
382− || minMaxTest (floor context.self.bbox.width)
455+ || minMaxTest (floor context.self.bbox.width)
385− Testable.InEl ->
459+ Testable.InEl ->
386− Testable.true "Element within element has fill width" <|
460+ [ Testable.true "Element within element has fill width" <|
387− (floor parentAvailableWidth == floor context.self.bbox.width)
461+ (floor parentAvailableWidth == floor context.self.bbox.width)
388− || minMaxTest (floor context.self.bbox.width)
462+ || minMaxTest (floor context.self.bbox.width)
392− spacePerPortion =
467+ spacePerPortion =
393− parentAvailableWidth / toFloat (List.length context.siblings + 1)
468+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
395− Testable.true "element has fill width" <|
470+ [ Testable.true "element has fill width" <|
396− (floor spacePerPortion == floor context.self.bbox.width)
471+ (floor spacePerPortion == floor context.self.bbox.width)
397− || minMaxTest (floor context.self.bbox.width)
472+ || minMaxTest (floor context.self.bbox.width)
474+ , [ Testable.lessThanOrEqual "not larger than parent"
475+ context.self.bbox.width
476+ context.parent.bbox.width
478+ , case context.selfElement of
479+ Testable.Paragraph _ _ ->
480+ -- A paragraph with width fill
481+ -- we want to test for correct text wrapping here.
489+ |> List.map childWidth
490+ |> List.append (List.map .width context.self.textMetrics)
494+ context.self.bbox.padding.left + context.self.bbox.padding.right
496+ totalCalculatedWidth =
497+ totalChildren + horizontalPadding
500+ if boxChildrenHeight > 20 then
501+ ceiling (boxChildrenHeight / 20)
504+ ceiling (totalCalculatedWidth / context.self.bbox.width)
514+ [ Testable.true "text wrapping, checking height"
515+ -- all we're doing here is testing if wrapping is occurring
516+ -- not the exact height, which is a little tricky to calculate perfectly without more information.
517+ (if expectedLines > 1 then
518+ context.self.bbox.height >= (20 * 2)
521+ -- then it's less than 2 ~ line heights
522+ -- there's some weird variance here which makes it hard to be exact.
523+ context.self.bbox.height < (20 * 2)
401 Shrink ->
532 Shrink ->
@@ -407,33 +538,211 @@ widthHelper maybeMin maybeMax len =
407 |> addMin
538 |> addMin
408 |> addMax
539 |> addMax
541+ , id = Testable.IsWidth
411 \context ->
543 \context ->
544+ case context.selfElement of
413− childWidth child =
547+ childWidth child =
414− -- TODO: add margin values to widths
415− child.bbox.width
548+ child.bbox.width
417− totalChildren =
550+ totalChildren =
418− context.children
551+ context.children
419− |> List.map childWidth
552+ |> List.map childWidth
553+ |> List.append (List.map .width context.self.textMetrics)
420− |> List.sum
554+ |> List.sum
422− horizontalPadding =
556+ horizontalPadding =
423− context.self.bbox.padding.left + context.self.bbox.padding.right
557+ context.self.bbox.padding.left + context.self.bbox.padding.right
426− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
428− if totalChildren == 0 then
559+ listIf
429− -- TODO: The issue is that we have a hard time measuring `text` elements
560+ [ ( (context.parentLayout /= Testable.InParagraph)
430− -- So if a element has a text child, then it's width isn't going to show up in the system.
561+ && (context.parentLayout /= Testable.InTextCol)
562+ , Testable.rounded "equals children"
563+ { expected = totalChildren + horizontalPadding
564+ , found = context.self.bbox.width
567+ , ( context.parentLayout /= Testable.AtRoot
568+ , Testable.lessThanOrEqual "not larger than parent"
431− [ expectRoundedEquality context.self.bbox.width context.self.bbox.width ]
569+ context.self.bbox.width
570+ context.parent.bbox.width
433− else
574+ Testable.Link _ _ _ ->
434− -- This fails if this element is actually a column
575+ let
435− -- So we need to capture what this element is in order to do this calculation.
576+ childWidth child =
581+ |> List.map childWidth
582+ |> List.append (List.map .width context.self.textMetrics)
586+ context.self.bbox.padding.left + context.self.bbox.padding.right
589+ [ ( (context.parentLayout /= Testable.InParagraph)
590+ && (context.parentLayout /= Testable.InTextCol)
591+ , Testable.rounded "equals children"
592+ { expected = totalChildren + horizontalPadding
593+ , found = context.self.bbox.width
596+ , ( context.parentLayout /= Testable.AtRoot
597+ , Testable.lessThanOrEqual "not larger than parent"
598+ context.self.bbox.width
599+ context.parent.bbox.width
603+ Testable.Row rowAttrs _ ->
604+ -- width of row is the sum of all children widths
605+ -- both text elements and others.
612+ |> List.map childWidth
613+ |> List.append (List.map .width context.self.textMetrics)
617+ context.self.bbox.padding.left + context.self.bbox.padding.right
620+ Testable.getSpacingFromAttributes rowAttrs
623+ toFloat spacingAmount * (toFloat (List.length context.children) - 1)
627+ , expectRoundedEquality
628+ { expected = totalChildren + horizontalPadding + totalSpacing
629+ , found = context.self.bbox.width
632+ , ( context.parentLayout /= Testable.AtRoot
633+ , Testable.lessThanOrEqual "not larger than parent"
634+ context.self.bbox.width
635+ context.parent.bbox.width
639+ Testable.Column _ _ ->
640+ -- The width of the column is the width of the widest child.
644+ + context.self.bbox.padding.left
645+ + context.self.bbox.padding.right
651+ + context.self.bbox.padding.left
652+ + context.self.bbox.padding.right
654+ context.self.textMetrics
658+ |> List.map childWidth
659+ |> List.append textChildren
663+ , expectRoundedEquality
664+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
665+ , found = context.self.bbox.width
668+ , ( context.parentLayout /= Testable.AtRoot
669+ , Testable.lessThanOrEqual "not larger than parent"
670+ context.self.bbox.width
671+ context.parent.bbox.width
675+ Testable.TextColumn _ _ ->
676+ -- The width of the column is the width of the widest child.
680+ + context.self.bbox.padding.left
681+ + context.self.bbox.padding.right
687+ + context.self.bbox.padding.left
688+ + context.self.bbox.padding.right
690+ context.self.textMetrics
694+ |> List.map childWidth
695+ |> List.append textChildren
699+ , expectRoundedEquality
700+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
701+ , found = context.self.bbox.width
704+ , ( context.parentLayout /= Testable.AtRoot
705+ , Testable.lessThanOrEqual "not larger than parent"
706+ context.self.bbox.width
707+ context.parent.bbox.width
711+ Testable.Paragraph _ _ ->
712+ -- This should be the size it's text,
713+ -- unless it takes up all available space, in which case it should wrap.
720+ |> List.map childWidth
721+ |> List.append (List.map .width context.self.textMetrics)
725+ context.self.bbox.padding.left + context.self.bbox.padding.right
729+ , expectRoundedEquality
436− [ expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width ]
730+ { expected = totalChildren + horizontalPadding
731+ , found = context.self.bbox.width
734+ , ( context.parentLayout /= Testable.AtRoot
735+ , Testable.lessThanOrEqual "not larger than parent"
736+ context.self.bbox.width
737+ context.parent.bbox.width
@@ -502,10 +811,13 @@ heightHelper maybeMin maybeMax len =
502 |> addMin
811 |> addMin
503 |> addMax
812 |> addMax
814+ , id = Testable.IsHeight
506 \found ->
816 \found ->
507− [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
817+ [ expectRoundedEquality
818+ { expected = toFloat val
508− (floor found.self.bbox.height == val)
819+ , found = found.self.bbox.height
509 , Testable.true "min/max holds true"
821 , Testable.true "min/max holds true"
510 (minMaxTest (floor found.self.bbox.height))
822 (minMaxTest (floor found.self.bbox.height))
@@ -520,9 +832,10 @@ heightHelper maybeMin maybeMax len =
520 |> addMin
832 |> addMin
521 |> addMax
833 |> addMax
835+ , id = Testable.IsHeight
524 \context ->
837 \context ->
525− [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
838+ [ if List.member context.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
526 Testable.true "height fill doesn't apply to above/below elements" True
839 Testable.true "height fill doesn't apply to above/below elements" True
@@ -530,7 +843,7 @@ heightHelper maybeMin maybeMax len =
530 parentAvailableHeight =
843 parentAvailableHeight =
531 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
844 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
533− case context.location of
846+ case context.parentLayout of
534 Testable.IsNearby _ ->
847 Testable.IsNearby _ ->
535 Testable.true "Nearby Element has fill height"
848 Testable.true "Nearby Element has fill height"
536 ((floor context.parent.bbox.height == floor context.self.bbox.height)
849 ((floor context.parent.bbox.height == floor context.self.bbox.height)
@@ -568,33 +881,134 @@ heightHelper maybeMin maybeMax len =
568 |> addMin
881 |> addMin
569 |> addMax
882 |> addMax
884+ , id = Testable.IsHeight
572 \context ->
886 \context ->
887+ case context.selfElement of
574− childWidth child =
890+ childHeight child =
575− -- TODO: add margin values to heights
576− child.bbox.height
891+ child.bbox.height
578− totalChildren =
893+ if List.isEmpty context.children then
579− context.children
894+ -- context.self.textMetrics
580− |> List.map childWidth
895+ -- |> List.map Testable.textHeight
581− |> List.sum
896+ -- |> List.sum
582−
897+ -- TODO: apparently the font metrics we have are for the literal characters rendered
583− verticalPadding =
898+ -- not for the font itself.
584− context.self.bbox.padding.top + context.self.bbox.padding.bottom
899+ [ Testable.todo "calculate height from actual text metrics"
587− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
589− if totalChildren == 0 then
590− -- 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.
592− [ expectRoundedEquality context.self.bbox.height context.self.bbox.height ]
595− -- This fails if this element is actually a column
903+ [ expectRoundedEquality
596− -- So we need to capture what this element is in order to do this calculation.
904+ { expected =
906+ |> List.map childHeight
908+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
909+ , found = context.self.bbox.height
911+ , Testable.lessThanOrEqual "not larger than parent"
912+ context.self.bbox.height
913+ context.parent.bbox.height
916+ Testable.Link _ _ _ ->
921+ if List.isEmpty context.children then
922+ -- context.self.textMetrics
923+ -- |> List.map Testable.textHeight
925+ -- TODO: apparently the font metrics we have are for the literal characters rendered
926+ -- not for the font itself.
927+ [ Testable.todo "calculate height from actual text metrics"
931+ [ expectRoundedEquality
934+ |> List.map childHeight
936+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
937+ , found = context.self.bbox.height
939+ , Testable.lessThanOrEqual "not larger than parent"
940+ context.self.bbox.height
941+ context.parent.bbox.height
949+ if List.isEmpty context.children then
950+ -- context.self.textMetrics
951+ -- |> List.map Testable.textHeight
953+ -- TODO: apparently the font metrics we have are for the literal characters rendered
954+ -- not for the font itself.
955+ [ Testable.todo "calculate height from actual text metrics" ]
958+ [ expectRoundedEquality
961+ |> List.map childHeight
963+ |> Maybe.withDefault 0
964+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
965+ , found = context.self.bbox.height
967+ , Testable.lessThanOrEqual "not larger than parent"
968+ context.self.bbox.height
969+ context.parent.bbox.height
972+ Testable.Column colAttrs _ ->
979+ |> List.map childHeight
980+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
984+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
987+ Testable.getSpacingFromAttributes colAttrs
990+ toFloat spacingAmount * (toFloat (List.length context.children) - 1)
992+ [ expectRoundedEquality
597− [ expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height ]
993+ { expected = totalChildren + verticalPadding + totalSpacing
994+ , found = context.self.bbox.height
996+ , Testable.lessThanOrEqual "not larger than parent"
997+ context.self.bbox.height
998+ context.parent.bbox.height
1001+ Testable.TextColumn _ _ ->
1004+ Testable.Paragraph _ _ ->
@@ -615,6 +1029,7 @@ spacing space =
615 , Testable.LabeledTest
1029 , Testable.LabeledTest
616 { label = "spacing: " ++ String.fromInt space
1030 { label = "spacing: " ++ String.fromInt space
617 , attr = Element.spacing space
1031 , attr = Element.spacing space
1032+ , id = Testable.NoId
618 , test =
1033 , test =
619 \found ->
1034 \found ->
@@ -693,13 +1108,14 @@ alignLeft =
693 Testable.LabeledTest
1108 Testable.LabeledTest
694 { label = "alignLeft"
1109 { label = "alignLeft"
695 , attr = Element.alignLeft
1110 , attr = Element.alignLeft
1111+ , id = Testable.NoId
696 , test =
1112 , test =
697 \found ->
1113 \found ->
698− [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1114+ [ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
699 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
1115 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
702− List.member found.location
1118+ List.member found.parentLayout
703 [ Testable.IsNearby Testable.InFront
1119 [ Testable.IsNearby Testable.InFront
704 , Testable.IsNearby Testable.Behind
1120 , Testable.IsNearby Testable.Behind
705 , Testable.IsNearby Testable.Above
1121 , Testable.IsNearby Testable.Above
@@ -707,16 +1123,18 @@ alignLeft =
709 expectRoundedEquality
1125 expectRoundedEquality
710− found.self.bbox.left
1126+ { found = found.self.bbox.left
711− found.parent.bbox.left
1127+ , expected = found.parent.bbox.left
713 else if List.length found.siblings == 0 then
1130 else if List.length found.siblings == 0 then
714 expectRoundedEquality
1131 expectRoundedEquality
715− found.self.bbox.left
1132+ { found = found.self.bbox.left
716− (found.parent.bbox.left + found.parent.bbox.padding.left)
1133+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
719− case found.location of
1137+ case found.parentLayout of
720 Testable.InRow ->
1138 Testable.InRow ->
722 siblingsOnLeft =
1140 siblingsOnLeft =
@@ -731,13 +1149,15 @@ alignLeft =
731 |> List.sum
1149 |> List.sum
733 expectRoundedEquality
1151 expectRoundedEquality
734− found.self.bbox.left
1152+ { found = found.self.bbox.left
735− (found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings))
1153+ , expected = found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings)
738 expectRoundedEquality
1157 expectRoundedEquality
739− found.self.bbox.left
1158+ { found = found.self.bbox.left
740− (found.parent.bbox.left + found.parent.bbox.padding.left)
1159+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
@@ -748,6 +1168,7 @@ centerX =
748 Testable.LabeledTest
1168 Testable.LabeledTest
749 { label = "centerX"
1169 { label = "centerX"
750 , attr = Element.centerX
1170 , attr = Element.centerX
1171+ , id = Testable.NoId
751 , test =
1172 , test =
752 \found ->
1173 \found ->
@@ -759,17 +1180,18 @@ centerX =
759 parentCenter =
1180 parentCenter =
760 found.parent.bbox.left + (found.parent.bbox.width / 2)
1181 found.parent.bbox.left + (found.parent.bbox.width / 2)
762− if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
1183+ if List.member found.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
763 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
1184 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
765 else if List.length found.siblings == 0 then
1186 else if List.length found.siblings == 0 then
766 [ expectRoundedEquality
1187 [ expectRoundedEquality
767− selfCenter
1188+ { found = selfCenter
768− parentCenter
1189+ , expected = parentCenter
772− case found.location of
1194+ case found.parentLayout of
773 Testable.InRow ->
1195 Testable.InRow ->
775 siblingsOnLeft =
1197 siblingsOnLeft =
@@ -800,12 +1222,17 @@ centerX =
802 [ expectRoundedEquality
1224 [ expectRoundedEquality
803− selfCenter
1225+ { found = selfCenter
804− expectedCenter
1226+ , expected = expectedCenter
808− [ expectRoundedEquality selfCenter parentCenter ]
1231+ [ expectRoundedEquality
1232+ { found = selfCenter
1233+ , expected = parentCenter
@@ -815,13 +1242,14 @@ alignRight =
815 Testable.LabeledTest
1242 Testable.LabeledTest
816 { label = "alignRight"
1243 { label = "alignRight"
817 , attr = Element.alignRight
1244 , attr = Element.alignRight
1245+ , id = Testable.NoId
818 , test =
1246 , test =
819 \found ->
1247 \found ->
820− if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1248+ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
821 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
1249 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
824− List.member found.location
1252+ List.member found.parentLayout
825 [ Testable.IsNearby Testable.InFront
1253 [ Testable.IsNearby Testable.InFront
826 , Testable.IsNearby Testable.Behind
1254 , Testable.IsNearby Testable.Behind
827 , Testable.IsNearby Testable.Above
1255 , Testable.IsNearby Testable.Above
@@ -829,18 +1257,20 @@ alignRight =
831 [ expectRoundedEquality
1259 [ expectRoundedEquality
832− found.self.bbox.right
1260+ { found = found.self.bbox.right
833− found.parent.bbox.right
1261+ , expected = found.parent.bbox.right
836 else if List.length found.siblings == 0 then
1265 else if List.length found.siblings == 0 then
837 [ expectRoundedEquality
1266 [ expectRoundedEquality
838− found.self.bbox.right
1267+ { found = found.self.bbox.right
839− (found.parent.bbox.right + found.parent.bbox.padding.right)
1268+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
843− case found.location of
1273+ case found.parentLayout of
844 Testable.InRow ->
1274 Testable.InRow ->
846 siblingsOnRight =
1276 siblingsOnRight =
@@ -855,14 +1285,16 @@ alignRight =
855 |> List.sum
1285 |> List.sum
857 [ expectRoundedEquality
1287 [ expectRoundedEquality
858− found.self.bbox.right
1288+ { found = found.self.bbox.right
859− (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
1289+ , expected = found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings)
863 [ expectRoundedEquality
1294 [ expectRoundedEquality
864− found.self.bbox.right
1295+ { found = found.self.bbox.right
865− (found.parent.bbox.right + found.parent.bbox.padding.right)
1296+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
@@ -873,13 +1305,14 @@ alignTop =
873 Testable.LabeledTest
1305 Testable.LabeledTest
874 { label = "alignTop"
1306 { label = "alignTop"
875 , attr = Element.alignTop
1307 , attr = Element.alignTop
1308+ , id = Testable.NoId
876 , test =
1309 , test =
877 \found ->
1310 \found ->
878− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1311+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
879 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
1312 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
882− List.member found.location
1315+ List.member found.parentLayout
883 [ Testable.IsNearby Testable.InFront
1316 [ Testable.IsNearby Testable.InFront
884 , Testable.IsNearby Testable.Behind
1317 , Testable.IsNearby Testable.Behind
885 , Testable.IsNearby Testable.OnRight
1318 , Testable.IsNearby Testable.OnRight
@@ -887,18 +1320,20 @@ alignTop =
889 [ expectRoundedEquality
1322 [ expectRoundedEquality
890− found.self.bbox.top
1323+ { found = found.self.bbox.top
891− found.parent.bbox.top
1324+ , expected = found.parent.bbox.top
894 else if List.length found.siblings == 0 then
1328 else if List.length found.siblings == 0 then
895 [ expectRoundedEquality
1329 [ expectRoundedEquality
896− found.self.bbox.top
1330+ { found = found.self.bbox.top
897− (found.parent.bbox.top + found.parent.bbox.padding.top)
1331+ , expected = found.parent.bbox.top + found.parent.bbox.padding.top
901− case found.location of
1336+ case found.parentLayout of
902 Testable.InColumn ->
1337 Testable.InColumn ->
904 siblingsAbove =
1339 siblingsAbove =
@@ -913,14 +1348,16 @@ alignTop =
913 |> List.sum
1348 |> List.sum
915 [ expectRoundedEquality
1350 [ expectRoundedEquality
916− found.self.bbox.top
1351+ { found = found.self.bbox.top
917− (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
1352+ , expected = found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings)
921 [ expectRoundedEquality
1357 [ expectRoundedEquality
922− found.self.bbox.top
1358+ { found = found.self.bbox.top
923− found.parent.bbox.top
1359+ , expected = found.parent.bbox.top
@@ -931,13 +1368,14 @@ alignBottom =
931 Testable.LabeledTest
1368 Testable.LabeledTest
932 { label = "alignBottom"
1369 { label = "alignBottom"
933 , attr = Element.alignBottom
1370 , attr = Element.alignBottom
1371+ , id = Testable.NoId
934 , test =
1372 , test =
935 \found ->
1373 \found ->
936− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1374+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
937 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
1375 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
940− List.member found.location
1378+ List.member found.parentLayout
941 [ Testable.IsNearby Testable.InFront
1379 [ Testable.IsNearby Testable.InFront
942 , Testable.IsNearby Testable.Behind
1380 , Testable.IsNearby Testable.Behind
943 , Testable.IsNearby Testable.OnRight
1381 , Testable.IsNearby Testable.OnRight
@@ -945,18 +1383,20 @@ alignBottom =
947 [ expectRoundedEquality
1385 [ expectRoundedEquality
948− found.self.bbox.bottom
1386+ { found = found.self.bbox.bottom
949− found.parent.bbox.bottom
1387+ , expected = found.parent.bbox.bottom
952 else if List.length found.siblings == 0 then
1391 else if List.length found.siblings == 0 then
953 [ expectRoundedEquality
1392 [ expectRoundedEquality
954− found.self.bbox.bottom
1393+ { found = found.self.bbox.bottom
955− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1394+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
959− case found.location of
1399+ case found.parentLayout of
960 Testable.InColumn ->
1400 Testable.InColumn ->
962 siblingsBelow =
1402 siblingsBelow =
@@ -971,22 +1411,25 @@ alignBottom =
971 |> List.sum
1411 |> List.sum
973 [ expectRoundedEquality
1413 [ expectRoundedEquality
974− found.self.bbox.bottom
1414+ { found = found.self.bbox.bottom
975− (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
1415+ , expected = found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings)
979 [ expectRoundedEquality
1420 [ expectRoundedEquality
980− found.self.bbox.bottom
1421+ { found = found.self.bbox.bottom
981− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1422+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
986−expectRoundedEquality x y =
1428+expectRoundedEquality : { expected : Float, found : Float } -> Testable.LayoutExpectation
1429+expectRoundedEquality { expected, found } =
987 Testable.true
1430 Testable.true
988− ("within 1 of each other " ++ floatToString x ++ ", " ++ floatToString y)
1431+ ("expected " ++ floatToString expected ++ ", found " ++ floatToString found)
989− (abs (x - y) < 1)
1432+ (abs (expected - found) < 1)
992floatToString : Float -> String
1435floatToString : Float -> String
@@ -1000,6 +1443,7 @@ centerY =
1000 Testable.LabeledTest
1443 Testable.LabeledTest
1001 { label = "centerY"
1444 { label = "centerY"
1002 , attr = Element.centerY
1445 , attr = Element.centerY
1446+ , id = Testable.NoId
1003 , test =
1447 , test =
1004 \found ->
1448 \found ->
@@ -1009,17 +1453,18 @@ centerY =
1009 parentCenter =
1453 parentCenter =
1010 found.parent.bbox.top + (found.parent.bbox.height / 2)
1454 found.parent.bbox.top + (found.parent.bbox.height / 2)
1012− if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1456+ if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1013 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
1457 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
1015 else if List.length found.siblings == 0 then
1459 else if List.length found.siblings == 0 then
1016 [ expectRoundedEquality
1460 [ expectRoundedEquality
1017− selfCenter
1461+ { found = selfCenter
1018− parentCenter
1462+ , expected = parentCenter
1022− case found.location of
1467+ case found.parentLayout of
1023 Testable.InColumn ->
1468 Testable.InColumn ->
1025 siblingsOnTop =
1470 siblingsOnTop =
@@ -1050,12 +1495,17 @@ centerY =
1052 [ expectRoundedEquality
1497 [ expectRoundedEquality
1053− selfCenter
1498+ { found = selfCenter
1054− expectedCenter
1499+ , expected = expectedCenter
1058− [ expectRoundedEquality selfCenter parentCenter ]
1504+ [ expectRoundedEquality
1505+ { found = selfCenter
1506+ , expected = parentCenter
@@ -1068,7 +1518,11 @@ above element =
1068 , label = "above"
1518 , label = "above"
1069 , test =
1519 , test =
1070 \found ->
1520 \found ->
1071− [ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top ]
1521+ [ expectRoundedEquality
1522+ { found = found.self.bbox.bottom
1523+ , expected = found.parent.bbox.top
@@ -1081,7 +1535,11 @@ below element =
1081 , label = "below"
1535 , label = "below"
1082 , test =
1536 , test =
1083 \found ->
1537 \found ->
1084− [ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom ]
1538+ [ expectRoundedEquality
1539+ { found = found.self.bbox.top
1540+ , expected = found.parent.bbox.bottom
@@ -1094,7 +1552,11 @@ onRight element =
1094 , label = "onRight"
1552 , label = "onRight"
1095 , test =
1553 , test =
1096 \found ->
1554 \found ->
1097− [ expectRoundedEquality found.self.bbox.left found.parent.bbox.right ]
1555+ [ expectRoundedEquality
1556+ { found = found.self.bbox.left
1557+ , expected = found.parent.bbox.right
@@ -1107,7 +1569,11 @@ onLeft element =
1107 , label = "onLeft"
1569 , label = "onLeft"
1108 , test =
1570 , test =
1109 \found ->
1571 \found ->
1110− [ expectRoundedEquality found.self.bbox.right found.parent.bbox.left ]
1572+ [ expectRoundedEquality
1573+ { found = found.self.bbox.right
1574+ , expected = found.parent.bbox.left
@@ -1173,3 +1639,85 @@ behindContent element =
1173 \found ->
1639 \found ->
1174 [ withinHelper found ]
1640 [ withinHelper found ]
1645+{- Implicit width/height calcualtions -}
1648+implicitWidthHeightShrink attrs =
1651+ implicitTest (widthHelper Nothing Nothing Shrink)
1652+ :: implicitTest (heightHelper Nothing Nothing Shrink)
1655+ skipOverridden withImplicits
1660+ Testable.LabeledTest details ->
1663+ Testable.AttrTest details ->
1672+ (\attr ( found, caught ) ->
1675+ case attrId attr of
1679+ Testable.IsWidth ->
1681+ , { hasWidth = True
1682+ , hasHeight = found.hasHeight
1686+ Testable.IsHeight ->
1688+ , { hasWidth = found.hasWidth
1701+ ( { hasWidth = False
1702+ , hasHeight = False
1711+{-| This is taking a normal test and rmoving its ability to attach a real `Element` attribute.
1715+ Testable.LabeledTest details ->
1717+ { test = details.test
1718+ , label = "Implicit -> " ++ details.label