@@ -20,6 +20,7 @@ module Testable.Element exposing
2020 , isVisible
2121 , label
2222 , layout
23+ , link
2324 , maximum
2425 , minimum
2526 , moveDown
@@ -97,12 +98,36 @@ none =
9798
9899paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99100paragraph attrs =
100− Testable.Paragraph (implicitWidthHeightShrink attrs)
101+ let
102+ withImplicits =
103+ implicitTest (widthHelper Nothing Nothing (Fill 1))
104+ :: implicitTest (heightHelper Nothing Nothing Shrink)
105+ :: attrs
106+ in
107+ Testable.Paragraph (skipOverridden withImplicits)
101108
102109
103110textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
104111textColumn attrs =
105− Testable.TextColumn (implicitWidthHeightShrink attrs)
112+ let
113+ withImplicits =
114+ implicitTest (widthHelper (Just 500) (Just 750) (Fill 1))
115+ :: implicitTest (heightHelper Nothing Nothing Shrink)
116+ :: attrs
117+ in
118+ Testable.TextColumn (skipOverridden withImplicits)
119+
120+
121+link :
122+ List (Testable.Attr msg)
123+ ->
124+ { url : String
125+ , label : Testable.Element msg
126+ }
127+ -> Testable.Element msg
128+link attrs details =
129+ -- TODO: this is not actually a link element!!
130+ Testable.El (implicitWidthHeightShrink attrs) details.label
106131
107132
108133{-| Old labeling mechanism that i removed to hastily
@@ -344,7 +369,10 @@ widthHelper maybeMin maybeMax len =
344369 )
345370 , test =
346371 \found ->
347− [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
372+ [ expectRoundedEquality
373+ { expected = toFloat val
374+ , found = found.self.bbox.width
375+ }
348376 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
349377 ]
350378 }
@@ -400,6 +428,9 @@ widthHelper maybeMin maybeMax len =
400428 Testable.true "element has fill width" <|
401429 (floor spacePerPortion == floor context.self.bbox.width)
402430 || minMaxTest (floor context.self.bbox.width)
431+ , Testable.lessThanOrEqual "not larger than parent"
432+ context.self.bbox.width
433+ context.parent.bbox.width
403434 ]
404435 }
405436
@@ -434,6 +465,9 @@ widthHelper maybeMin maybeMax len =
434465 { expected = totalChildren + horizontalPadding
435466 , found = context.self.bbox.width
436467 }
468+ , Testable.lessThanOrEqual "not larger than parent"
469+ context.self.bbox.width
470+ context.parent.bbox.width
437471 ]
438472
439473 Testable.Row rowAttrs _ ->
@@ -462,6 +496,9 @@ widthHelper maybeMin maybeMax len =
462496 { expected = totalChildren + horizontalPadding + totalSpacing
463497 , found = context.self.bbox.width
464498 }
499+ , Testable.lessThanOrEqual "not larger than parent"
500+ context.self.bbox.width
501+ context.parent.bbox.width
465502 ]
466503
467504 Testable.Column _ _ ->
@@ -490,10 +527,41 @@ widthHelper maybeMin maybeMax len =
490527 { expected = Maybe.withDefault 0 (List.maximum allChildren)
491528 , found = context.self.bbox.width
492529 }
530+ , Testable.lessThanOrEqual "not larger than parent"
531+ context.self.bbox.width
532+ context.parent.bbox.width
493533 ]
494534
495535 Testable.TextColumn _ _ ->
496− []
536+ -- The width of the column is the width of the widest child.
537+ let
538+ childWidth child =
539+ child.bbox.width
540+ + context.self.bbox.padding.left
541+ + context.self.bbox.padding.right
542+
543+ textChildren =
544+ List.map
545+ (\txt ->
546+ txt.width
547+ + context.self.bbox.padding.left
548+ + context.self.bbox.padding.right
549+ )
550+ context.self.textMetrics
551+
552+ allChildren =
553+ context.children
554+ |> List.map childWidth
555+ |> List.append textChildren
556+ in
557+ [ expectRoundedEquality
558+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
559+ , found = context.self.bbox.width
560+ }
561+ , Testable.lessThanOrEqual "not larger than parent"
562+ context.self.bbox.width
563+ context.parent.bbox.width
564+ ]
497565
498566 Testable.Paragraph _ _ ->
499567 -- This should be the size it's text,
@@ -515,6 +583,9 @@ widthHelper maybeMin maybeMax len =
515583 { expected = totalChildren + horizontalPadding
516584 , found = context.self.bbox.width
517585 }
586+ , Testable.lessThanOrEqual "not larger than parent"
587+ context.self.bbox.width
588+ context.parent.bbox.width
518589 ]
519590
520591 Testable.Text _ ->
@@ -593,8 +664,10 @@ heightHelper maybeMin maybeMax len =
593664 , id = Testable.IsHeight
594665 , test =
595666 \found ->
596− [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
597− (floor found.self.bbox.height == val)
667+ [ expectRoundedEquality
668+ { expected = toFloat val
669+ , found = found.self.bbox.height
670+ }
598671 , Testable.true "min/max holds true"
599672 (minMaxTest (floor found.self.bbox.height))
600673 ]
@@ -665,46 +738,60 @@ heightHelper maybeMin maybeMax len =
665738 Testable.El _ _ ->
666739 let
667740 childHeight child =
668− -- TODO: add margin values to heights
669741 child.bbox.height
670−
671− totalChildren =
672− context.children
673− |> List.map childHeight
674− |> List.append (List.map Testable.textHeight context.self.textMetrics)
675− |> List.sum
676−
677− verticalPadding =
678− context.self.bbox.padding.top + context.self.bbox.padding.bottom
679−
680− spacingValue =
681− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
682742 in
683− [ expectRoundedEquality
684− { expected = totalChildren + verticalPadding + spacingValue
685− , found = context.self.bbox.height
686− }
743+ [ if List.isEmpty context.children then
744+ -- context.self.textMetrics
745+ -- |> List.map Testable.textHeight
746+ -- |> List.sum
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)
752+
753+ else
754+ expectRoundedEquality
755+ { expected =
756+ context.children
757+ |> List.map childHeight
758+ |> List.sum
759+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
760+ , found = context.self.bbox.height
761+ }
762+ , Testable.lessThanOrEqual "not larger than parent"
763+ context.self.bbox.height
764+ context.parent.bbox.height
687765 ]
688766
689767 Testable.Row _ _ ->
690768 let
691769 childHeight child =
692770 child.bbox.height
693−
694− totalChildren =
695− context.children
696− |> List.map childHeight
697− |> List.append (List.map Testable.textHeight context.self.textMetrics)
698− |> List.maximum
699− |> Maybe.withDefault 0
700−
701− verticalPadding =
702− context.self.bbox.padding.top + context.self.bbox.padding.bottom
703771 in
704− [ expectRoundedEquality
705− { expected = totalChildren + verticalPadding
706− , found = context.self.bbox.height
707− }
772+ [ if List.isEmpty context.children then
773+ -- context.self.textMetrics
774+ -- |> List.map Testable.textHeight
775+ -- |> List.sum
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)
781+
782+ else
783+ expectRoundedEquality
784+ { expected =
785+ context.children
786+ |> List.map childHeight
787+ |> List.maximum
788+ |> Maybe.withDefault 0
789+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
790+ , found = context.self.bbox.height
791+ }
792+ , Testable.lessThanOrEqual "not larger than parent"
793+ context.self.bbox.height
794+ context.parent.bbox.height
708795 ]
709796
710797 Testable.Column colAttrs _ ->
@@ -731,13 +818,22 @@ heightHelper maybeMin maybeMax len =
731818 { expected = totalChildren + verticalPadding + totalSpacing
732819 , found = context.self.bbox.height
733820 }
821+ , Testable.lessThanOrEqual "not larger than parent"
822+ context.self.bbox.height
823+ context.parent.bbox.height
734824 ]
735825
736826 Testable.TextColumn _ _ ->
737− []
827+ [ Testable.lessThanOrEqual "not larger than parent"
828+ context.self.bbox.height
829+ context.parent.bbox.height
830+ ]
738831
739832 Testable.Paragraph _ _ ->
740− []
833+ [ Testable.lessThanOrEqual "not larger than parent"
834+ context.self.bbox.height
835+ context.parent.bbox.height
836+ ]
741837
742838 Testable.Text _ ->
743839 []