@@ -20,6 +20,7 @@ module Testable.Element exposing
20 , isVisible
20 , isVisible
25 , moveDown
26 , moveDown
@@ -97,12 +98,36 @@ none =
98paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99paragraph attrs =
100paragraph attrs =
100− Testable.Paragraph (implicitWidthHeightShrink attrs)
101+ let
103+ implicitTest (widthHelper Nothing Nothing (Fill 1))
104+ :: implicitTest (heightHelper Nothing Nothing Shrink)
107+ Testable.Paragraph (skipOverridden withImplicits)
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
110textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
104textColumn attrs =
111textColumn attrs =
114+ implicitTest (widthHelper (Just 500) (Just 750) (Fill 1))
115+ :: implicitTest (heightHelper Nothing Nothing Shrink)
118+ Testable.TextColumn (skipOverridden withImplicits)
122+ List (Testable.Attr msg)
125+ , label : Testable.Element msg
127+ -> Testable.Element msg
129+ -- TODO: this is not actually a link element!!
105− Testable.TextColumn (implicitWidthHeightShrink attrs)
130+ Testable.El (implicitWidthHeightShrink attrs) details.label
108{-| Old labeling mechanism that i removed to hastily
133{-| Old labeling mechanism that i removed to hastily
@@ -344,7 +369,10 @@ widthHelper maybeMin maybeMax len =
346 \found ->
371 \found ->
372+ [ expectRoundedEquality
373+ { expected = toFloat val
347− [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
374+ , found = found.self.bbox.width
348 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
376 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
@@ -400,6 +428,9 @@ widthHelper maybeMin maybeMax len =
400 Testable.true "element has fill width" <|
428 Testable.true "element has fill width" <|
401 (floor spacePerPortion == floor context.self.bbox.width)
429 (floor spacePerPortion == floor context.self.bbox.width)
402 || minMaxTest (floor context.self.bbox.width)
430 || minMaxTest (floor context.self.bbox.width)
431+ , Testable.lessThanOrEqual "not larger than parent"
432+ context.self.bbox.width
433+ context.parent.bbox.width
@@ -434,6 +465,9 @@ widthHelper maybeMin maybeMax len =
434 { expected = totalChildren + horizontalPadding
465 { expected = totalChildren + horizontalPadding
435 , found = context.self.bbox.width
466 , found = context.self.bbox.width
468+ , Testable.lessThanOrEqual "not larger than parent"
469+ context.self.bbox.width
470+ context.parent.bbox.width
439 Testable.Row rowAttrs _ ->
473 Testable.Row rowAttrs _ ->
@@ -462,6 +496,9 @@ widthHelper maybeMin maybeMax len =
462 { expected = totalChildren + horizontalPadding + totalSpacing
496 { expected = totalChildren + horizontalPadding + totalSpacing
463 , found = context.self.bbox.width
497 , found = context.self.bbox.width
499+ , Testable.lessThanOrEqual "not larger than parent"
500+ context.self.bbox.width
501+ context.parent.bbox.width
467 Testable.Column _ _ ->
504 Testable.Column _ _ ->
@@ -490,10 +527,41 @@ widthHelper maybeMin maybeMax len =
490 { expected = Maybe.withDefault 0 (List.maximum allChildren)
527 { expected = Maybe.withDefault 0 (List.maximum allChildren)
491 , found = context.self.bbox.width
528 , found = context.self.bbox.width
530+ , Testable.lessThanOrEqual "not larger than parent"
531+ context.self.bbox.width
532+ context.parent.bbox.width
495 Testable.TextColumn _ _ ->
535 Testable.TextColumn _ _ ->
536+ -- The width of the column is the width of the widest child.
540+ + context.self.bbox.padding.left
541+ + context.self.bbox.padding.right
547+ + context.self.bbox.padding.left
548+ + context.self.bbox.padding.right
550+ context.self.textMetrics
554+ |> List.map childWidth
555+ |> List.append textChildren
557+ [ expectRoundedEquality
558+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
559+ , found = context.self.bbox.width
561+ , Testable.lessThanOrEqual "not larger than parent"
562+ context.self.bbox.width
563+ context.parent.bbox.width
498 Testable.Paragraph _ _ ->
566 Testable.Paragraph _ _ ->
499 -- This should be the size it's text,
567 -- This should be the size it's text,
@@ -515,6 +583,9 @@ widthHelper maybeMin maybeMax len =
515 { expected = totalChildren + horizontalPadding
583 { expected = totalChildren + horizontalPadding
516 , found = context.self.bbox.width
584 , found = context.self.bbox.width
586+ , Testable.lessThanOrEqual "not larger than parent"
587+ context.self.bbox.width
588+ context.parent.bbox.width
520 Testable.Text _ ->
591 Testable.Text _ ->
@@ -593,8 +664,10 @@ heightHelper maybeMin maybeMax len =
593 , id = Testable.IsHeight
664 , id = Testable.IsHeight
595 \found ->
666 \found ->
596− [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
667+ [ expectRoundedEquality
668+ { expected = toFloat val
597− (floor found.self.bbox.height == val)
669+ , found = found.self.bbox.height
598 , Testable.true "min/max holds true"
671 , Testable.true "min/max holds true"
599 (minMaxTest (floor found.self.bbox.height))
672 (minMaxTest (floor found.self.bbox.height))
@@ -665,46 +738,60 @@ heightHelper maybeMin maybeMax len =
665 Testable.El _ _ ->
738 Testable.El _ _ ->
667 childHeight child =
740 childHeight child =
668− -- TODO: add margin values to heights
669 child.bbox.height
741 child.bbox.height
673− |> List.map childHeight
674− |> List.append (List.map Testable.textHeight context.self.textMetrics)
678− context.self.bbox.padding.top + context.self.bbox.padding.bottom
681− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
743+ [ if List.isEmpty context.children then
744+ -- context.self.textMetrics
745+ -- |> List.map Testable.textHeight
747+ -- TODO: apparently the font metrics we have are for the literal characters rendered
748+ -- not for the font itself.
749+ -- so for now, we are stubbing this in as 20, which is the default font size.
750+ Testable.true "expected multiple of 20"
751+ ((round context.self.bbox.height |> modBy 20) == 0)
683− [ expectRoundedEquality
754+ expectRoundedEquality
684− { expected = totalChildren + verticalPadding + spacingValue
755+ { expected =
757+ |> List.map childHeight
759+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
685− , found = context.self.bbox.height
760+ , found = context.self.bbox.height
762+ , Testable.lessThanOrEqual "not larger than parent"
763+ context.self.bbox.height
764+ context.parent.bbox.height
689 Testable.Row _ _ ->
767 Testable.Row _ _ ->
691 childHeight child =
769 childHeight child =
692 child.bbox.height
770 child.bbox.height
696− |> List.map childHeight
697− |> List.append (List.map Testable.textHeight context.self.textMetrics)
699− |> Maybe.withDefault 0
702− context.self.bbox.padding.top + context.self.bbox.padding.bottom
772+ [ if List.isEmpty context.children then
773+ -- context.self.textMetrics
774+ -- |> List.map Testable.textHeight
776+ -- TODO: apparently the font metrics we have are for the literal characters rendered
777+ -- not for the font itself.
778+ -- so for now, we are stubbing this in as 20, which is the default font size.
779+ Testable.true "expected multiple of 20"
780+ ((round context.self.bbox.height |> modBy 20) == 0)
704− [ expectRoundedEquality
783+ expectRoundedEquality
705− { expected = totalChildren + verticalPadding
784+ { expected =
786+ |> List.map childHeight
788+ |> Maybe.withDefault 0
789+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
706− , found = context.self.bbox.height
790+ , found = context.self.bbox.height
792+ , Testable.lessThanOrEqual "not larger than parent"
793+ context.self.bbox.height
794+ context.parent.bbox.height
710 Testable.Column colAttrs _ ->
797 Testable.Column colAttrs _ ->
@@ -731,13 +818,22 @@ heightHelper maybeMin maybeMax len =
731 { expected = totalChildren + verticalPadding + totalSpacing
818 { expected = totalChildren + verticalPadding + totalSpacing
732 , found = context.self.bbox.height
819 , found = context.self.bbox.height
821+ , Testable.lessThanOrEqual "not larger than parent"
822+ context.self.bbox.height
823+ context.parent.bbox.height
736 Testable.TextColumn _ _ ->
826 Testable.TextColumn _ _ ->
827+ [ Testable.lessThanOrEqual "not larger than parent"
828+ context.self.bbox.height
829+ context.parent.bbox.height
739 Testable.Paragraph _ _ ->
832 Testable.Paragraph _ _ ->
833+ [ Testable.lessThanOrEqual "not larger than parent"
834+ context.self.bbox.height
835+ context.parent.bbox.height
742 Testable.Text _ ->
838 Testable.Text _ ->