@@ -10,7 +10,6 @@ module Testable.Element exposing
1010 , below
1111 , centerX
1212 , centerY
13− , clip
1413 , column
1514 , el
1615 , expectRoundedEquality
@@ -38,9 +37,6 @@ module Testable.Element exposing
3837 , rgb
3938 , rgba
4039 , row
41− , scrollbarX
42− , scrollbarY
43− , scrollbars
4440 , shrink
4541 , spacing
4642 , text
@@ -136,31 +132,8 @@ link :
136132 }
137133 -> Testable.Element msg
138134link attrs details =
139− Testable.Link details.url
140− (implicitWidthHeightShrink attrs)
141− details.label
142−
143−
144−clip =
145− Testable.Attr Element.clip
146−
147−
148−{-| -}
149−scrollbars : Testable.Attr msg
150−scrollbars =
151− Testable.Attr Element.scrollbars
152−
153−
154−{-| -}
155−scrollbarY : Testable.Attr msg
156−scrollbarY =
157− Testable.Attr Element.scrollbarY
158−
159−
160−{-| -}
161−scrollbarX : Testable.Attr msg
162−scrollbarX =
163− Testable.Attr Element.scrollbarX
135+ -- TODO: this is not actually a link element!!
136+ Testable.El (implicitWidthHeightShrink attrs) details.label
164137
165138
166139{-| Old labeling mechanism that i removed to hastily
@@ -334,11 +307,6 @@ paddingXY x y =
334307 }
335308
336309
337−listIf ls =
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
340−
341−
342310widthHelper maybeMin maybeMax len =
343311 let
344312 addMin l =
@@ -497,31 +465,12 @@ widthHelper maybeMin maybeMax len =
497465 totalChildren + horizontalPadding
498466
499467 expectedLines =
500− if boxChildrenHeight > 20 then
501− ceiling (boxChildrenHeight / 20)
502−
503− else
504− ceiling (totalCalculatedWidth / context.self.bbox.width)
505−
506− boxChildrenHeight =
507− context.children
508− |> List.map
509− (\c ->
510− c.bbox.height
511− )
512− |> List.sum
468+ ceiling (totalCalculatedWidth / context.self.bbox.width)
513469 in
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)
519−
520− else
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)
524− )
470+ [ Testable.rounded "text wrapping, checking height"
471+ { expected = toFloat (expectedLines * 22)
472+ , found = context.self.bbox.height
473+ }
525474 ]
526475
527476 _ ->
@@ -555,50 +504,23 @@ widthHelper maybeMin maybeMax len =
555504
556505 horizontalPadding =
557506 context.self.bbox.padding.left + context.self.bbox.padding.right
558− in
559− listIf
560− [ ( (context.parentLayout /= Testable.InParagraph)
561− && (context.parentLayout /= Testable.InTextCol)
562− , Testable.rounded "equals children"
563− { expected = totalChildren + horizontalPadding
564− , found = context.self.bbox.width
565− }
566− )
567− , ( context.parentLayout /= Testable.AtRoot
568− , Testable.lessThanOrEqual "not larger than parent"
569− context.self.bbox.width
570− context.parent.bbox.width
571− )
572− ]
573−
574− Testable.Link _ _ _ ->
575− let
576− childWidth child =
577− child.bbox.width
578507
579− totalChildren =
580− context.children
581− |> List.map childWidth
582− |> List.append (List.map .width context.self.textMetrics)
583− |> List.sum
584−
585− horizontalPadding =
586− context.self.bbox.padding.left + context.self.bbox.padding.right
587− in
588− listIf
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
508+ _ =
509+ Debug.log "widths"
510+ { children =
511+ context.children
512+ |> List.map childWidth
513+ , text = List.map .width context.self.textMetrics
594514 }
595− )
596− , ( context.parentLayout /= Testable.AtRoot
597− , Testable.lessThanOrEqual "not larger than parent"
598− context.self.bbox.width
599− context.parent.bbox.width
600− )
601− ]
515+ in
516+ [ Testable.rounded "equals children"
517+ { expected = totalChildren + horizontalPadding
518+ , found = context.self.bbox.width
519+ }
520+ , Testable.lessThanOrEqual "not larger than parent"
521+ context.self.bbox.width
522+ context.parent.bbox.width
523+ ]
602524
603525 Testable.Row rowAttrs _ ->
604526 -- width of row is the sum of all children widths
@@ -622,19 +544,14 @@ widthHelper maybeMin maybeMax len =
622544 totalSpacing =
623545 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
624546 in
625− listIf
626− [ ( True
627− , expectRoundedEquality
628− { expected = totalChildren + horizontalPadding + totalSpacing
629− , found = context.self.bbox.width
630− }
631− )
632− , ( context.parentLayout /= Testable.AtRoot
633− , Testable.lessThanOrEqual "not larger than parent"
634− context.self.bbox.width
635− context.parent.bbox.width
636− )
637− ]
547+ [ expectRoundedEquality
548+ { expected = totalChildren + horizontalPadding + totalSpacing
549+ , found = context.self.bbox.width
550+ }
551+ , Testable.lessThanOrEqual "not larger than parent"
552+ context.self.bbox.width
553+ context.parent.bbox.width
554+ ]
638555
639556 Testable.Column _ _ ->
640557 -- The width of the column is the width of the widest child.
@@ -658,19 +575,14 @@ widthHelper maybeMin maybeMax len =
658575 |> List.map childWidth
659576 |> List.append textChildren
660577 in
661− listIf
662− [ ( True
663− , expectRoundedEquality
664− { expected = Maybe.withDefault 0 (List.maximum allChildren)
665− , found = context.self.bbox.width
666− }
667− )
668− , ( context.parentLayout /= Testable.AtRoot
669− , Testable.lessThanOrEqual "not larger than parent"
670− context.self.bbox.width
671− context.parent.bbox.width
672− )
673− ]
578+ [ expectRoundedEquality
579+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
580+ , found = context.self.bbox.width
581+ }
582+ , Testable.lessThanOrEqual "not larger than parent"
583+ context.self.bbox.width
584+ context.parent.bbox.width
585+ ]
674586
675587 Testable.TextColumn _ _ ->
676588 -- The width of the column is the width of the widest child.
@@ -694,19 +606,14 @@ widthHelper maybeMin maybeMax len =
694606 |> List.map childWidth
695607 |> List.append textChildren
696608 in
697− listIf
698− [ ( True
699− , expectRoundedEquality
700− { expected = Maybe.withDefault 0 (List.maximum allChildren)
701− , found = context.self.bbox.width
702− }
703− )
704− , ( context.parentLayout /= Testable.AtRoot
705− , Testable.lessThanOrEqual "not larger than parent"
706− context.self.bbox.width
707− context.parent.bbox.width
708− )
709− ]
609+ [ expectRoundedEquality
610+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
611+ , found = context.self.bbox.width
612+ }
613+ , Testable.lessThanOrEqual "not larger than parent"
614+ context.self.bbox.width
615+ context.parent.bbox.width
616+ ]
710617
711618 Testable.Paragraph _ _ ->
712619 -- This should be the size it's text,
@@ -724,19 +631,14 @@ widthHelper maybeMin maybeMax len =
724631 horizontalPadding =
725632 context.self.bbox.padding.left + context.self.bbox.padding.right
726633 in
727− listIf
728− [ ( True
729− , expectRoundedEquality
730− { expected = totalChildren + horizontalPadding
731− , found = context.self.bbox.width
732− }
733− )
734− , ( context.parentLayout /= Testable.AtRoot
735− , Testable.lessThanOrEqual "not larger than parent"
736− context.self.bbox.width
737− context.parent.bbox.width
738− )
739− ]
634+ [ expectRoundedEquality
635+ { expected = totalChildren + horizontalPadding
636+ , found = context.self.bbox.width
637+ }
638+ , Testable.lessThanOrEqual "not larger than parent"
639+ context.self.bbox.width
640+ context.parent.bbox.width
641+ ]
740642
741643 Testable.Text _ ->
742644 []
@@ -890,45 +792,20 @@ heightHelper maybeMin maybeMax len =
890792 childHeight child =
891793 child.bbox.height
892794 in
893− if List.isEmpty context.children then
795+ [ if List.isEmpty context.children then
894796 -- context.self.textMetrics
895797 -- |> List.map Testable.textHeight
896798 -- |> List.sum
897799 -- TODO: apparently the font metrics we have are for the literal characters rendered
898800 -- not for the font itself.
899− [ Testable.todo "calculate height from actual text metrics"
900− ]
901−
902− else
903− [ expectRoundedEquality
904− { expected =
905− context.children
906− |> List.map childHeight
907− |> List.sum
908− |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
909− , found = context.self.bbox.height
801+ -- so for now, we are stubbing this in as 20, which is the default font size + line height.
802+ Testable.rounded "expected multiple of 20"
803+ { expected = context.self.bbox.height
804+ , found = toFloat (List.length context.self.textMetrics * 20)
910805 }
911− , Testable.lessThanOrEqual "not larger than parent"
912− context.self.bbox.height
913− context.parent.bbox.height
914− ]
915−
916− Testable.Link _ _ _ ->
917− let
918− childHeight child =
919− child.bbox.height
920− in
921− if List.isEmpty context.children then
922− -- context.self.textMetrics
923− -- |> List.map Testable.textHeight
924− -- |> List.sum
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"
928− ]
929806
930− else
931− [ expectRoundedEquality
807+ else
808+ expectRoundedEquality
932809 { expected =
933810 context.children
934811 |> List.map childHeight
@@ -936,26 +813,28 @@ heightHelper maybeMin maybeMax len =
936813 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
937814 , found = context.self.bbox.height
938815 }
939− , Testable.lessThanOrEqual "not larger than parent"
940− context.self.bbox.height
941− context.parent.bbox.height
942− ]
816+ , Testable.lessThanOrEqual "not larger than parent"
817+ context.self.bbox.height
818+ context.parent.bbox.height
819+ ]
943820
944821 Testable.Row _ _ ->
945822 let
946823 childHeight child =
947824 child.bbox.height
948825 in
949− if List.isEmpty context.children then
826+ [ if List.isEmpty context.children then
950827 -- context.self.textMetrics
951828 -- |> List.map Testable.textHeight
952829 -- |> List.sum
953830 -- TODO: apparently the font metrics we have are for the literal characters rendered
954831 -- not for the font itself.
955− [ Testable.todo "calculate height from actual text metrics" ]
832+ -- so for now, we are stubbing this in as 20, which is the default font size.
833+ Testable.true "expected multiple of 20"
834+ ((round context.self.bbox.height |> modBy 20) == 0)
956835
957− else
958− [ expectRoundedEquality
836+ else
837+ expectRoundedEquality
959838 { expected =
960839 context.children
961840 |> List.map childHeight
@@ -964,10 +843,10 @@ heightHelper maybeMin maybeMax len =
964843 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
965844 , found = context.self.bbox.height
966845 }
967− , Testable.lessThanOrEqual "not larger than parent"
968− context.self.bbox.height
969− context.parent.bbox.height
970− ]
846+ , Testable.lessThanOrEqual "not larger than parent"
847+ context.self.bbox.height
848+ context.parent.bbox.height
849+ ]
971850
972851 Testable.Column colAttrs _ ->
973852 let
@@ -999,10 +878,16 @@ heightHelper maybeMin maybeMax len =
999878 ]
1000879
1001880 Testable.TextColumn _ _ ->
1002− []
881+ [ Testable.lessThanOrEqual "not larger than parent"
882+ context.self.bbox.height
883+ context.parent.bbox.height
884+ ]
1003885
1004886 Testable.Paragraph _ _ ->
1005− []
887+ [ Testable.lessThanOrEqual "not larger than parent"
888+ context.self.bbox.height
889+ context.parent.bbox.height
890+ ]
1006891
1007892 Testable.Text _ ->
1008893 []