@@ -10,6 +10,7 @@ module Testable.Element exposing
15 , expectRoundedEquality
16 , expectRoundedEquality
@@ -19,8 +20,14 @@ module Testable.Element exposing
20 , isVisible
21 , isVisible
@@ -28,11 +35,17 @@ module Testable.Element exposing
28 , paddingXY
35 , paddingXY
29 , paragraph
36 , paragraph
35 , textColumn
47 , textColumn
36 , transparent
49 , transparent
@@ -51,9 +64,21 @@ In order to run the test:
52import Dict
65import Dict
53import Element
66import Element
55import Html.Attributes
67import Html.Attributes
56import Testable
68import Testable
69+import 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 ]
79+layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.Testable
81+ Testable.Runner.testable "Test" elem
59text : String -> Testable.Element msg
84text : String -> Testable.Element msg
@@ -62,18 +87,18 @@ text =
64el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
89el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
66− Testable.El
91+ Testable.El (implicitWidthHeightShrink attrs)
69row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
94row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
71− Testable.Row
96+ Testable.Row (implicitWidthHeightShrink attrs)
74column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
75−column =
100+column attrs =
76− Testable.Column
101+ Testable.Column (implicitWidthHeightShrink attrs)
79none : Testable.Element msg
104none : Testable.Element msg
@@ -82,13 +107,82 @@ none =
84paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
109paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
85−paragraph =
110+paragraph attrs =
113+ implicitTest (widthHelper Nothing Nothing (Fill 1))
114+ :: implicitTest (heightHelper Nothing Nothing Shrink)
86− Testable.Paragraph
117+ Testable.Paragraph (skipOverridden withImplicits)
89textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
120textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
90−textColumn =
121+textColumn attrs =
124+ implicitTest (widthHelper (Just 500) (Just 750) (Fill 1))
125+ :: implicitTest (heightHelper Nothing Nothing Shrink)
91− 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
166+{-| Old labeling mechanism that i removed to hastily
173+ Testable.Attr (Element.moveUp x)
177+ Testable.Attr (Element.moveDown x)
181+ Testable.Attr (Element.moveRight x)
185+ Testable.Attr (Element.moveLeft x)
94type Length
188type Length
@@ -107,6 +201,14 @@ maximum =
110px : Int -> Length
212px : Int -> Length
@@ -127,11 +229,6 @@ fillPortion =
130−label : String -> Testable.Attr msg
135transparent : Bool -> Testable.Attr msg
232transparent : Bool -> Testable.Attr msg
136transparent on =
233transparent on =
137 Testable.LabeledTest
234 Testable.LabeledTest
@@ -142,8 +239,9 @@ transparent on =
144 , attr = Element.transparent on
241 , attr = Element.transparent on
242+ , id = Testable.NoId
146− \context _ ->
244+ \context ->
148 selfTransparency =
246 selfTransparency =
149 context.self.style
247 context.self.style
@@ -157,19 +255,19 @@ transparent on =
160− Expect.equal value selfTransparency
258+ [ Testable.equal value selfTransparency ]
165isVisible : Testable.Attr msg
263isVisible : Testable.Attr msg
166isVisible =
264isVisible =
167− Testable.LabeledTest
265+ Testable.AttrTest
168 { label = "is-visible"
266 { label = "is-visible"
169− , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
267+ , id = Testable.NoId
171− \context _ ->
269+ \context ->
172− Expect.equal context.self.isVisible True
270+ [ Testable.equal context.self.isVisible True ]
@@ -179,15 +277,16 @@ alpha a =
179 Testable.LabeledTest
277 Testable.LabeledTest
180 { label = "alpha-" ++ String.fromFloat a
278 { label = "alpha-" ++ String.fromFloat a
181 , attr = Element.alpha a
279 , attr = Element.alpha a
280+ , id = Testable.NoId
183− \context _ ->
282+ \context ->
185 selfTransparency =
284 selfTransparency =
186 context.self.style
285 context.self.style
187 |> Dict.get "opacity"
286 |> Dict.get "opacity"
188 |> Maybe.withDefault "notfound"
287 |> Maybe.withDefault "notfound"
190− Expect.equal (String.fromFloat a) selfTransparency
289+ [ Testable.equal (String.fromFloat a) selfTransparency ]
@@ -197,9 +296,10 @@ padding pad =
197 Testable.LabeledTest
296 Testable.LabeledTest
198 { label = "padding " ++ String.fromInt pad
297 { label = "padding " ++ String.fromInt pad
199 , attr = Element.padding pad
298 , attr = Element.padding pad
299+ , id = Testable.NoId
201− \found _ ->
301+ \found ->
202− Expect.true ("Padding " ++ String.fromInt pad ++ " is present")
302+ [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
203 (List.all ((==) pad)
303 (List.all ((==) pad)
204 [ floor found.self.bbox.padding.left
304 [ floor found.self.bbox.padding.left
205 , floor found.self.bbox.padding.right
305 , floor found.self.bbox.padding.right
@@ -207,6 +307,7 @@ padding pad =
207 , floor found.self.bbox.padding.bottom
307 , floor found.self.bbox.padding.bottom
@@ -216,9 +317,10 @@ paddingXY x y =
216 Testable.LabeledTest
317 Testable.LabeledTest
217 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
318 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
218 , attr = Element.paddingXY x y
319 , attr = Element.paddingXY x y
320+ , id = Testable.NoId
220− \found _ ->
322+ \found ->
221− Expect.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
323+ [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
222 (List.all ((==) x)
324 (List.all ((==) x)
223 [ floor found.self.bbox.padding.left
325 [ floor found.self.bbox.padding.left
224 , floor found.self.bbox.padding.right
326 , floor found.self.bbox.padding.right
@@ -228,9 +330,15 @@ paddingXY x y =
228 , floor found.self.bbox.padding.bottom
330 , floor found.self.bbox.padding.bottom
338+ List.filter Tuple.first ls
339+ |> List.map Tuple.second
234widthHelper maybeMin maybeMax len =
342widthHelper maybeMin maybeMax len =
236 addMin l =
344 addMin l =
@@ -290,6 +398,7 @@ widthHelper maybeMin maybeMax len =
290 -- Pixel values should ignore min and max?
398 -- Pixel values should ignore min and max?
291 Testable.LabeledTest
399 Testable.LabeledTest
292 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
400 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
401+ , id = Testable.IsWidth
294 Element.width
403 Element.width
295 (Element.px val
404 (Element.px val
@@ -297,18 +406,24 @@ widthHelper maybeMin maybeMax len =
297 |> addMax
406 |> addMax
300− \found _ ->
409+ \found ->
301− Expect.all
410+ [ expectRoundedEquality
302− [ \_ ->
411+ { expected = toFloat val
303− Expect.true "exact width is exact" (floor found.self.bbox.width == val)
412+ , found = found.self.bbox.width
304− , \_ -> Expect.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
414+ , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
309 Fill portion ->
418 Fill portion ->
310 Testable.LabeledTest
419 Testable.LabeledTest
421+ if portion == 1 then
422+ "width fill" ++ minLabel ++ maxLabel
311− { label = "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
425+ "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
426+ , id = Testable.IsWidth
313 Element.width
428 Element.width
314 (Element.fillPortion portion
429 (Element.fillPortion portion
@@ -316,41 +431,102 @@ widthHelper maybeMin maybeMax len =
316 |> addMax
431 |> addMax
319− \context _ ->
434+ \context ->
320− 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
321− Expect.true "width fill doesn't apply to onright/onleft elements" True
436+ [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
325 parentAvailableWidth =
440 parentAvailableWidth =
326 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)
328− case context.location of
444+ [ case context.parentLayout of
329− Testable.IsNearby _ ->
445+ Testable.IsNearby _ ->
330− Expect.true "Nearby Element has fill width"
446+ [ Testable.true "Nearby Element has fill width"
331− ((floor context.parent.bbox.width == floor context.self.bbox.width)
447+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
332− || minMaxTest (floor context.self.bbox.width)
448+ || minMaxTest (floor context.self.bbox.width)
335− Testable.InColumn ->
452+ Testable.InColumn ->
336− Expect.true "Element within column has fill width"
453+ [ Testable.true "Element within column has fill width"
337− ((floor parentAvailableWidth == floor context.self.bbox.width)
454+ ((floor parentAvailableWidth == floor context.self.bbox.width)
338− || minMaxTest (floor context.self.bbox.width)
455+ || minMaxTest (floor context.self.bbox.width)
341− Testable.InEl ->
459+ Testable.InEl ->
342− Expect.true "Element within element has fill width" <|
460+ [ Testable.true "Element within element has fill width" <|
343− (floor parentAvailableWidth == floor context.self.bbox.width)
461+ (floor parentAvailableWidth == floor context.self.bbox.width)
344− || minMaxTest (floor context.self.bbox.width)
462+ || minMaxTest (floor context.self.bbox.width)
348− spacePerPortion =
467+ spacePerPortion =
349− parentAvailableWidth / toFloat (List.length context.siblings + 1)
468+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
351− Expect.true "element has fill width" <|
470+ [ Testable.true "element has fill width" <|
352− (floor spacePerPortion == floor context.self.bbox.width)
471+ (floor spacePerPortion == floor context.self.bbox.width)
353− || 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)
356 Shrink ->
532 Shrink ->
@@ -362,33 +538,211 @@ widthHelper maybeMin maybeMax len =
362 |> addMin
538 |> addMin
363 |> addMax
539 |> addMax
541+ , id = Testable.IsWidth
366− \context _ ->
543+ \context ->
544+ case context.selfElement of
368− childWidth child =
547+ childWidth child =
369− -- TODO: add margin values to widths
370− child.bbox.width
548+ child.bbox.width
372− totalChildren =
550+ totalChildren =
373− context.children
551+ context.children
374− |> List.map childWidth
552+ |> List.map childWidth
553+ |> List.append (List.map .width context.self.textMetrics)
375− |> List.sum
554+ |> List.sum
377− horizontalPadding =
556+ horizontalPadding =
378− context.self.bbox.padding.left + context.self.bbox.padding.right
557+ context.self.bbox.padding.left + context.self.bbox.padding.right
380− spacingValue =
559+ listIf
381− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
560+ [ ( (context.parentLayout /= Testable.InParagraph)
382− in
561+ && (context.parentLayout /= Testable.InTextCol)
383− if totalChildren == 0 then
562+ , Testable.rounded "equals children"
384− -- TODO: The issue is that we have a hard time measuring `text` elements
563+ { expected = totalChildren + horizontalPadding
385− -- So if a element has a text child, then it's width isn't going to show up in the system.
564+ , found = context.self.bbox.width
567+ , ( context.parentLayout /= Testable.AtRoot
568+ , Testable.lessThanOrEqual "not larger than parent"
386− expectRoundedEquality context.self.bbox.width context.self.bbox.width
569+ context.self.bbox.width
570+ context.parent.bbox.width
388− else
574+ Testable.Link _ _ _ ->
389− -- This fails if this element is actually a column
575+ let
390− -- 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
391− 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
@@ -457,17 +811,16 @@ heightHelper maybeMin maybeMax len =
457 |> addMin
811 |> addMin
458 |> addMax
812 |> addMax
814+ , id = Testable.IsHeight
461− \found _ ->
816+ \found ->
462− Expect.all
817+ [ expectRoundedEquality
463− [ \_ ->
818+ { expected = toFloat val
464− Expect.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
465− (floor found.self.bbox.height == val)
819+ , found = found.self.bbox.height
467− Expect.true "min/max holds true"
821+ , Testable.true "min/max holds true"
468− (minMaxTest (floor found.self.bbox.height))
822+ (minMaxTest (floor found.self.bbox.height))
473 Fill portion ->
826 Fill portion ->
@@ -479,31 +832,32 @@ heightHelper maybeMin maybeMax len =
479 |> addMin
832 |> addMin
480 |> addMax
833 |> addMax
835+ , id = Testable.IsHeight
483− \context _ ->
837+ \context ->
484− 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
485− Expect.true "height fill doesn't apply to above/below elements" True
839+ Testable.true "height fill doesn't apply to above/below elements" True
489 parentAvailableHeight =
843 parentAvailableHeight =
490 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)
492− case context.location of
846+ case context.parentLayout of
493 Testable.IsNearby _ ->
847 Testable.IsNearby _ ->
494− Expect.true "Nearby Element has fill height"
848+ Testable.true "Nearby Element has fill height"
495 ((floor context.parent.bbox.height == floor context.self.bbox.height)
849 ((floor context.parent.bbox.height == floor context.self.bbox.height)
496 || minMaxTest (floor context.self.bbox.height)
850 || minMaxTest (floor context.self.bbox.height)
499 Testable.InColumn ->
853 Testable.InColumn ->
500− Expect.true "Element within column has fill height"
854+ Testable.true "Element within column has fill height"
501 ((floor parentAvailableHeight == floor context.self.bbox.height)
855 ((floor parentAvailableHeight == floor context.self.bbox.height)
502 || minMaxTest (floor context.self.bbox.height)
856 || minMaxTest (floor context.self.bbox.height)
505 Testable.InEl ->
859 Testable.InEl ->
506− Expect.true "Element within el has fill height" <|
860+ Testable.true "Element within el has fill height" <|
507 (floor parentAvailableHeight == floor context.self.bbox.height)
861 (floor parentAvailableHeight == floor context.self.bbox.height)
508 || minMaxTest (floor context.self.bbox.height)
862 || minMaxTest (floor context.self.bbox.height)
@@ -512,9 +866,10 @@ heightHelper maybeMin maybeMax len =
512 spacePerPortion =
866 spacePerPortion =
513 parentAvailableHeight / toFloat (List.length context.siblings + 1)
867 parentAvailableHeight / toFloat (List.length context.siblings + 1)
515− Expect.true "el has fill height" <|
869+ Testable.true "el has fill height" <|
516 (floor spacePerPortion == floor context.self.bbox.height)
870 (floor spacePerPortion == floor context.self.bbox.height)
517 || minMaxTest (floor context.self.bbox.height)
871 || minMaxTest (floor context.self.bbox.height)
520 Shrink ->
875 Shrink ->
@@ -526,33 +881,134 @@ heightHelper maybeMin maybeMax len =
526 |> addMin
881 |> addMin
527 |> addMax
882 |> addMax
884+ , id = Testable.IsHeight
530− \context _ ->
886+ \context ->
887+ case context.selfElement of
532− childWidth child =
890+ childHeight child =
533− -- TODO: add margin values to heights
534− child.bbox.height
891+ child.bbox.height
536− totalChildren =
893+ if List.isEmpty context.children then
537− context.children
894+ -- context.self.textMetrics
538− |> List.map childWidth
895+ -- |> List.map Testable.textHeight
539− |> List.sum
896+ -- |> List.sum
540−
897+ -- TODO: apparently the font metrics we have are for the literal characters rendered
541− verticalPadding =
898+ -- not for the font itself.
542− context.self.bbox.padding.top + context.self.bbox.padding.bottom
899+ [ Testable.todo "calculate height from actual text metrics"
545− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
547− if totalChildren == 0 then
548− -- TODO: The issue is that we have a hard time measuring `text` elements
549− -- So if a element has a text child, then it's height isn't going to show up in the system.
550− expectRoundedEquality context.self.bbox.height context.self.bbox.height
553− -- This fails if this element is actually a column
903+ [ expectRoundedEquality
554− -- So we need to capture what this element is in order to do this calculation.
904+ { expected =
555− expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height
905+ context.children
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
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 _ _ ->
@@ -573,8 +1029,9 @@ spacing space =
573 , Testable.LabeledTest
1029 , Testable.LabeledTest
574 { label = "spacing: " ++ String.fromInt space
1030 { label = "spacing: " ++ String.fromInt space
575 , attr = Element.spacing space
1031 , attr = Element.spacing space
1032+ , id = Testable.NoId
576 , test =
1033 , test =
577− \found _ ->
1034+ \found ->
579 findDistance child total =
1036 findDistance child total =
580 List.concatMap
1037 List.concatMap
@@ -620,7 +1077,7 @@ spacing space =
621 distances
1078 distances
623− Expect.true
1080+ [ Testable.true
624 ("All children are at least "
1081 ("All children are at least "
625 ++ String.fromInt space
1082 ++ String.fromInt space
626 ++ " pixels apart."
1083 ++ " pixels apart."
@@ -628,6 +1085,7 @@ spacing space =
628 ++ " are not though"
1085 ++ " are not though"
630 (allAreSpaced == [])
1087 (allAreSpaced == [])
@@ -650,30 +1108,33 @@ alignLeft =
650 Testable.LabeledTest
1108 Testable.LabeledTest
651 { label = "alignLeft"
1109 { label = "alignLeft"
652 , attr = Element.alignLeft
1110 , attr = Element.alignLeft
1111+ , id = Testable.NoId
653 , test =
1112 , test =
654− \found _ ->
1113+ \found ->
655− 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
656− Expect.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
658− else if
1117+ else if
659− List.member found.location
1118+ List.member found.parentLayout
660 [ Testable.IsNearby Testable.InFront
1119 [ Testable.IsNearby Testable.InFront
661 , Testable.IsNearby Testable.Behind
1120 , Testable.IsNearby Testable.Behind
662 , Testable.IsNearby Testable.Above
1121 , Testable.IsNearby Testable.Above
663 , Testable.IsNearby Testable.Below
1122 , Testable.IsNearby Testable.Below
666 expectRoundedEquality
1125 expectRoundedEquality
667− found.self.bbox.left
1126+ { found = found.self.bbox.left
668− found.parent.bbox.left
1127+ , expected = found.parent.bbox.left
670− else if List.length found.siblings == 0 then
1130+ else if List.length found.siblings == 0 then
671 expectRoundedEquality
1131 expectRoundedEquality
672− found.self.bbox.left
1132+ { found = found.self.bbox.left
673− (found.parent.bbox.left + found.parent.bbox.padding.left)
1133+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
676− case found.location of
1137+ case found.parentLayout of
677 Testable.InRow ->
1138 Testable.InRow ->
679 siblingsOnLeft =
1140 siblingsOnLeft =
@@ -688,13 +1149,16 @@ alignLeft =
688 |> List.sum
1149 |> List.sum
690 expectRoundedEquality
1151 expectRoundedEquality
691− found.self.bbox.left
1152+ { found = found.self.bbox.left
692− (found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings))
1153+ , expected = found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings)
695 expectRoundedEquality
1157 expectRoundedEquality
696− found.self.bbox.left
1158+ { found = found.self.bbox.left
697− (found.parent.bbox.left + found.parent.bbox.padding.left)
1159+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
@@ -704,8 +1168,9 @@ centerX =
704 Testable.LabeledTest
1168 Testable.LabeledTest
705 { label = "centerX"
1169 { label = "centerX"
706 , attr = Element.centerX
1170 , attr = Element.centerX
1171+ , id = Testable.NoId
707 , test =
1172 , test =
708− \found _ ->
1173+ \found ->
710 selfCenter : Float
1175 selfCenter : Float
711 selfCenter =
1176 selfCenter =
@@ -715,16 +1180,18 @@ centerX =
715 parentCenter =
1180 parentCenter =
716 found.parent.bbox.left + (found.parent.bbox.width / 2)
1181 found.parent.bbox.left + (found.parent.bbox.width / 2)
718− 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
719− Expect.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 ]
721 else if List.length found.siblings == 0 then
1186 else if List.length found.siblings == 0 then
722− expectRoundedEquality
1187+ [ expectRoundedEquality
723− selfCenter
1188+ { found = selfCenter
724− parentCenter
1189+ , expected = parentCenter
727− case found.location of
1194+ case found.parentLayout of
728 Testable.InRow ->
1195 Testable.InRow ->
730 siblingsOnLeft =
1197 siblingsOnLeft =
@@ -754,12 +1221,18 @@ centerX =
757− expectRoundedEquality
1224+ [ expectRoundedEquality
758− selfCenter
1225+ { found = selfCenter
759− expectedCenter
1226+ , expected = expectedCenter
762− expectRoundedEquality selfCenter parentCenter
1231+ [ expectRoundedEquality
1232+ { found = selfCenter
1233+ , expected = parentCenter
@@ -769,30 +1242,35 @@ alignRight =
769 Testable.LabeledTest
1242 Testable.LabeledTest
770 { label = "alignRight"
1243 { label = "alignRight"
771 , attr = Element.alignRight
1244 , attr = Element.alignRight
1245+ , id = Testable.NoId
772 , test =
1246 , test =
773− \found _ ->
1247+ \found ->
774− 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
775− Expect.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 ]
778− List.member found.location
1252+ List.member found.parentLayout
779 [ Testable.IsNearby Testable.InFront
1253 [ Testable.IsNearby Testable.InFront
780 , Testable.IsNearby Testable.Behind
1254 , Testable.IsNearby Testable.Behind
781 , Testable.IsNearby Testable.Above
1255 , Testable.IsNearby Testable.Above
782 , Testable.IsNearby Testable.Below
1256 , Testable.IsNearby Testable.Below
785− expectRoundedEquality
1259+ [ expectRoundedEquality
786− found.self.bbox.right
1260+ { found = found.self.bbox.right
787− found.parent.bbox.right
1261+ , expected = found.parent.bbox.right
789 else if List.length found.siblings == 0 then
1265 else if List.length found.siblings == 0 then
790− expectRoundedEquality
1266+ [ expectRoundedEquality
791− found.self.bbox.right
1267+ { found = found.self.bbox.right
792− (found.parent.bbox.right + found.parent.bbox.padding.right)
1268+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
795− case found.location of
1273+ case found.parentLayout of
796 Testable.InRow ->
1274 Testable.InRow ->
798 siblingsOnRight =
1276 siblingsOnRight =
@@ -806,14 +1284,18 @@ alignRight =
806 |> List.map (.width << .bbox)
1284 |> List.map (.width << .bbox)
807 |> List.sum
1285 |> List.sum
809− expectRoundedEquality
1287+ [ expectRoundedEquality
810− found.self.bbox.right
1288+ { found = found.self.bbox.right
811− (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
1289+ , expected = found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings)
814− expectRoundedEquality
1294+ [ expectRoundedEquality
815− found.self.bbox.right
1295+ { found = found.self.bbox.right
816− (found.parent.bbox.right + found.parent.bbox.padding.right)
1296+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
@@ -823,30 +1305,35 @@ alignTop =
823 Testable.LabeledTest
1305 Testable.LabeledTest
824 { label = "alignTop"
1306 { label = "alignTop"
825 , attr = Element.alignTop
1307 , attr = Element.alignTop
1308+ , id = Testable.NoId
826 , test =
1309 , test =
827− \found _ ->
1310+ \found ->
828− 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
829− Expect.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 ]
832− List.member found.location
1315+ List.member found.parentLayout
833 [ Testable.IsNearby Testable.InFront
1316 [ Testable.IsNearby Testable.InFront
834 , Testable.IsNearby Testable.Behind
1317 , Testable.IsNearby Testable.Behind
835 , Testable.IsNearby Testable.OnRight
1318 , Testable.IsNearby Testable.OnRight
836 , Testable.IsNearby Testable.OnLeft
1319 , Testable.IsNearby Testable.OnLeft
839− expectRoundedEquality
1322+ [ expectRoundedEquality
840− found.self.bbox.top
1323+ { found = found.self.bbox.top
841− found.parent.bbox.top
1324+ , expected = found.parent.bbox.top
843 else if List.length found.siblings == 0 then
1328 else if List.length found.siblings == 0 then
844− expectRoundedEquality
1329+ [ expectRoundedEquality
845− found.self.bbox.top
1330+ { found = found.self.bbox.top
846− (found.parent.bbox.top + found.parent.bbox.padding.top)
1331+ , expected = found.parent.bbox.top + found.parent.bbox.padding.top
849− case found.location of
1336+ case found.parentLayout of
850 Testable.InColumn ->
1337 Testable.InColumn ->
852 siblingsAbove =
1339 siblingsAbove =
@@ -860,14 +1347,18 @@ alignTop =
860 |> List.map (.height << .bbox)
1347 |> List.map (.height << .bbox)
861 |> List.sum
1348 |> List.sum
863− expectRoundedEquality
1350+ [ expectRoundedEquality
864− found.self.bbox.top
1351+ { found = found.self.bbox.top
865− (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
1352+ , expected = found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings)
868− expectRoundedEquality
1357+ [ expectRoundedEquality
869− found.self.bbox.top
1358+ { found = found.self.bbox.top
870− found.parent.bbox.top
1359+ , expected = found.parent.bbox.top
@@ -877,30 +1368,35 @@ alignBottom =
877 Testable.LabeledTest
1368 Testable.LabeledTest
878 { label = "alignBottom"
1369 { label = "alignBottom"
879 , attr = Element.alignBottom
1370 , attr = Element.alignBottom
1371+ , id = Testable.NoId
880 , test =
1372 , test =
881− \found _ ->
1373+ \found ->
882− 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
883− Expect.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 ]
886− List.member found.location
1378+ List.member found.parentLayout
887 [ Testable.IsNearby Testable.InFront
1379 [ Testable.IsNearby Testable.InFront
888 , Testable.IsNearby Testable.Behind
1380 , Testable.IsNearby Testable.Behind
889 , Testable.IsNearby Testable.OnRight
1381 , Testable.IsNearby Testable.OnRight
890 , Testable.IsNearby Testable.OnLeft
1382 , Testable.IsNearby Testable.OnLeft
893− expectRoundedEquality
1385+ [ expectRoundedEquality
894− found.self.bbox.bottom
1386+ { found = found.self.bbox.bottom
895− found.parent.bbox.bottom
1387+ , expected = found.parent.bbox.bottom
897 else if List.length found.siblings == 0 then
1391 else if List.length found.siblings == 0 then
898− expectRoundedEquality
1392+ [ expectRoundedEquality
899− found.self.bbox.bottom
1393+ { found = found.self.bbox.bottom
900− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1394+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
903− case found.location of
1399+ case found.parentLayout of
904 Testable.InColumn ->
1400 Testable.InColumn ->
906 siblingsBelow =
1402 siblingsBelow =
@@ -914,20 +1410,31 @@ alignBottom =
914 |> List.map (.height << .bbox)
1410 |> List.map (.height << .bbox)
915 |> List.sum
1411 |> List.sum
917− expectRoundedEquality
1413+ [ expectRoundedEquality
918− found.self.bbox.bottom
1414+ { found = found.self.bbox.bottom
919− (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
1415+ , expected = found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings)
922− expectRoundedEquality
1420+ [ expectRoundedEquality
923− found.self.bbox.bottom
1421+ { found = found.self.bbox.bottom
924− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1422+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
928−expectRoundedEquality x y =
1428+expectRoundedEquality : { expected : Float, found : Float } -> Testable.LayoutExpectation
929− Expect.true ("within 1 of each other " ++ String.fromFloat x ++ ":" ++ String.fromFloat y)
1429+expectRoundedEquality { expected, found } =
930− (abs (x - y) < 1)
1430+ Testable.true
1431+ ("expected " ++ floatToString expected ++ ", found " ++ floatToString found)
1432+ (abs (expected - found) < 1)
1435+floatToString : Float -> String
1437+ String.fromFloat (toFloat (round (x * 100)) / 100)
@@ -936,8 +1443,9 @@ centerY =
936 Testable.LabeledTest
1443 Testable.LabeledTest
937 { label = "centerY"
1444 { label = "centerY"
938 , attr = Element.centerY
1445 , attr = Element.centerY
1446+ , id = Testable.NoId
939 , test =
1447 , test =
940− \found _ ->
1448+ \found ->
942 selfCenter =
1450 selfCenter =
943 found.self.bbox.top + (found.self.bbox.height / 2)
1451 found.self.bbox.top + (found.self.bbox.height / 2)
@@ -945,16 +1453,18 @@ centerY =
945 parentCenter =
1453 parentCenter =
946 found.parent.bbox.top + (found.parent.bbox.height / 2)
1454 found.parent.bbox.top + (found.parent.bbox.height / 2)
948− 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
949− Expect.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 ]
951 else if List.length found.siblings == 0 then
1459 else if List.length found.siblings == 0 then
952− expectRoundedEquality
1460+ [ expectRoundedEquality
953− selfCenter
1461+ { found = selfCenter
954− parentCenter
1462+ , expected = parentCenter
957− case found.location of
1467+ case found.parentLayout of
958 Testable.InColumn ->
1468 Testable.InColumn ->
960 siblingsOnTop =
1470 siblingsOnTop =
@@ -984,12 +1494,18 @@ centerY =
987− expectRoundedEquality
1497+ [ expectRoundedEquality
988− selfCenter
1498+ { found = selfCenter
989− expectedCenter
1499+ , expected = expectedCenter
992− expectRoundedEquality selfCenter parentCenter
1504+ [ expectRoundedEquality
1505+ { found = selfCenter
1506+ , expected = parentCenter
@@ -1001,8 +1517,12 @@ above element =
1001 , element = element
1517 , element = element
1002 , label = "above"
1518 , label = "above"
1003 , test =
1519 , test =
1004− \found _ ->
1520+ \found ->
1005− expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top
1521+ [ expectRoundedEquality
1522+ { found = found.self.bbox.bottom
1523+ , expected = found.parent.bbox.top
@@ -1014,8 +1534,12 @@ below element =
1014 , element = element
1534 , element = element
1015 , label = "below"
1535 , label = "below"
1016 , test =
1536 , test =
1017− \found _ ->
1537+ \found ->
1018− expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom
1538+ [ expectRoundedEquality
1539+ { found = found.self.bbox.top
1540+ , expected = found.parent.bbox.bottom
@@ -1027,8 +1551,12 @@ onRight element =
1027 , element = element
1551 , element = element
1028 , label = "onRight"
1552 , label = "onRight"
1029 , test =
1553 , test =
1030− \found _ ->
1554+ \found ->
1031− expectRoundedEquality found.self.bbox.left found.parent.bbox.right
1555+ [ expectRoundedEquality
1556+ { found = found.self.bbox.left
1557+ , expected = found.parent.bbox.right
@@ -1040,8 +1568,12 @@ onLeft element =
1040 , element = element
1568 , element = element
1041 , label = "onLeft"
1569 , label = "onLeft"
1042 , test =
1570 , test =
1043− \found _ ->
1571+ \found ->
1044− expectRoundedEquality found.self.bbox.right found.parent.bbox.left
1572+ [ expectRoundedEquality
1573+ { found = found.self.bbox.right
1574+ , expected = found.parent.bbox.left
@@ -1057,11 +1589,12 @@ inFront element =
1057 , element = element
1589 , element = element
1058 , label = "inFront"
1590 , label = "inFront"
1059 , test =
1591 , test =
1060− withinHelper
1592+ \found ->
1593+ [ withinHelper found ]
1064−withinHelper found _ =
1597+withinHelper found =
1066 horizontalCheck =
1599 horizontalCheck =
1067 if found.self.bbox.width > found.parent.bbox.width then
1600 if found.self.bbox.width > found.parent.bbox.width then
@@ -1085,7 +1618,7 @@ withinHelper found _ =
1085 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
1618 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
1088− Expect.true "within the confines of the parent"
1621+ Testable.true "within the confines of the parent"
1089 (List.all ((==) True)
1622 (List.all ((==) True)
1090 (List.concat
1623 (List.concat
1091 [ horizontalCheck
1624 [ horizontalCheck
@@ -1103,5 +1636,88 @@ behindContent element =
1103 , element = element
1636 , element = element
1104 , label = "behindContent"
1637 , label = "behindContent"
1105 , test =
1638 , test =
1106− withinHelper
1639+ \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