@@ -10,6 +10,7 @@ module Testable.Element exposing
15 , expectRoundedEquality
16 , expectRoundedEquality
@@ -37,10 +38,14 @@ module Testable.Element exposing
43 , textColumn
47 , textColumn
44 , transparent
49 , transparent
@@ -64,11 +69,16 @@ import 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− [ ( "Tests Run", elem )
74text : String -> Testable.Element msg
84text : String -> Testable.Element msg
@@ -126,8 +136,31 @@ link :
127 -> Testable.Element msg
137 -> Testable.Element msg
128link attrs details =
138link attrs details =
129− -- TODO: this is not actually a link element!!
139+ Testable.Link details.url
130− Testable.El (implicitWidthHeightShrink attrs) details.label
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
133{-| Old labeling mechanism that i removed to hastily
166{-| Old labeling mechanism that i removed to hastily
@@ -301,6 +334,11 @@ paddingXY x y =
338+ List.filter Tuple.first ls
339+ |> List.map Tuple.second
304widthHelper maybeMin maybeMax len =
342widthHelper maybeMin maybeMax len =
306 addMin l =
344 addMin l =
@@ -459,12 +497,31 @@ widthHelper maybeMin maybeMax len =
459 totalChildren + horizontalPadding
497 totalChildren + horizontalPadding
461 expectedLines =
499 expectedLines =
500+ if boxChildrenHeight > 20 then
501+ ceiling (boxChildrenHeight / 20)
462− ceiling (totalCalculatedWidth / context.self.bbox.width)
504+ ceiling (totalCalculatedWidth / context.self.bbox.width)
464− [ Testable.rounded "text wrapping, checking height"
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.
465− { expected = toFloat (expectedLines * 22)
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.
466− , found = context.self.bbox.height
523+ context.self.bbox.height < (20 * 2)
@@ -498,23 +555,50 @@ widthHelper maybeMin maybeMax len =
499 horizontalPadding =
556 horizontalPadding =
500 context.self.bbox.padding.left + context.self.bbox.padding.right
557 context.self.bbox.padding.left + context.self.bbox.padding.right
503− Debug.log "widths"
560+ [ ( (context.parentLayout /= Testable.InParagraph)
504− { children =
561+ && (context.parentLayout /= Testable.InTextCol)
505− context.children
562+ , Testable.rounded "equals children"
506− |> List.map childWidth
563+ { expected = totalChildren + horizontalPadding
507− , text = List.map .width context.self.textMetrics
564+ , found = context.self.bbox.width
567+ , ( context.parentLayout /= Testable.AtRoot
568+ , Testable.lessThanOrEqual "not larger than parent"
569+ context.self.bbox.width
570+ context.parent.bbox.width
574+ Testable.Link _ _ _ ->
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)
510− [ Testable.rounded "equals children"
591+ , Testable.rounded "equals children"
511− { expected = totalChildren + horizontalPadding
592+ { expected = totalChildren + horizontalPadding
512− , found = context.self.bbox.width
593+ , found = context.self.bbox.width
596+ , ( context.parentLayout /= Testable.AtRoot
514− , Testable.lessThanOrEqual "not larger than parent"
597+ , Testable.lessThanOrEqual "not larger than parent"
515− context.self.bbox.width
598+ context.self.bbox.width
516− context.parent.bbox.width
599+ context.parent.bbox.width
519 Testable.Row rowAttrs _ ->
603 Testable.Row rowAttrs _ ->
520 -- width of row is the sum of all children widths
604 -- width of row is the sum of all children widths
@@ -538,14 +622,19 @@ widthHelper maybeMin maybeMax len =
538 totalSpacing =
622 totalSpacing =
539 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
623 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
541− [ expectRoundedEquality
627+ , expectRoundedEquality
542− { expected = totalChildren + horizontalPadding + totalSpacing
628+ { expected = totalChildren + horizontalPadding + totalSpacing
543− , found = context.self.bbox.width
629+ , found = context.self.bbox.width
632+ , ( context.parentLayout /= Testable.AtRoot
545− , Testable.lessThanOrEqual "not larger than parent"
633+ , Testable.lessThanOrEqual "not larger than parent"
546− context.self.bbox.width
634+ context.self.bbox.width
547− context.parent.bbox.width
635+ context.parent.bbox.width
550 Testable.Column _ _ ->
639 Testable.Column _ _ ->
551 -- The width of the column is the width of the widest child.
640 -- The width of the column is the width of the widest child.
@@ -569,14 +658,19 @@ widthHelper maybeMin maybeMax len =
569 |> List.map childWidth
658 |> List.map childWidth
570 |> List.append textChildren
659 |> List.append textChildren
572− [ expectRoundedEquality
663+ , expectRoundedEquality
573− { expected = Maybe.withDefault 0 (List.maximum allChildren)
664+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
574− , found = context.self.bbox.width
665+ , found = context.self.bbox.width
668+ , ( context.parentLayout /= Testable.AtRoot
576− , Testable.lessThanOrEqual "not larger than parent"
669+ , Testable.lessThanOrEqual "not larger than parent"
577− context.self.bbox.width
670+ context.self.bbox.width
578− context.parent.bbox.width
671+ context.parent.bbox.width
581 Testable.TextColumn _ _ ->
675 Testable.TextColumn _ _ ->
582 -- The width of the column is the width of the widest child.
676 -- The width of the column is the width of the widest child.
@@ -600,14 +694,19 @@ widthHelper maybeMin maybeMax len =
600 |> List.map childWidth
694 |> List.map childWidth
601 |> List.append textChildren
695 |> List.append textChildren
603− [ expectRoundedEquality
699+ , expectRoundedEquality
604− { expected = Maybe.withDefault 0 (List.maximum allChildren)
700+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
605− , found = context.self.bbox.width
701+ , found = context.self.bbox.width
704+ , ( context.parentLayout /= Testable.AtRoot
607− , Testable.lessThanOrEqual "not larger than parent"
705+ , Testable.lessThanOrEqual "not larger than parent"
608− context.self.bbox.width
706+ context.self.bbox.width
609− context.parent.bbox.width
707+ context.parent.bbox.width
612 Testable.Paragraph _ _ ->
711 Testable.Paragraph _ _ ->
613 -- This should be the size it's text,
712 -- This should be the size it's text,
@@ -625,14 +724,19 @@ widthHelper maybeMin maybeMax len =
625 horizontalPadding =
724 horizontalPadding =
626 context.self.bbox.padding.left + context.self.bbox.padding.right
725 context.self.bbox.padding.left + context.self.bbox.padding.right
628− [ expectRoundedEquality
729+ , expectRoundedEquality
629− { expected = totalChildren + horizontalPadding
730+ { expected = totalChildren + horizontalPadding
630− , found = context.self.bbox.width
731+ , found = context.self.bbox.width
734+ , ( context.parentLayout /= Testable.AtRoot
632− , Testable.lessThanOrEqual "not larger than parent"
735+ , Testable.lessThanOrEqual "not larger than parent"
633− context.self.bbox.width
736+ context.self.bbox.width
634− context.parent.bbox.width
737+ context.parent.bbox.width
637 Testable.Text _ ->
741 Testable.Text _ ->
@@ -786,20 +890,45 @@ heightHelper maybeMin maybeMax len =
786 childHeight child =
890 childHeight child =
787 child.bbox.height
891 child.bbox.height
789− [ if List.isEmpty context.children then
893+ if List.isEmpty context.children then
790 -- context.self.textMetrics
894 -- context.self.textMetrics
791 -- |> List.map Testable.textHeight
895 -- |> List.map Testable.textHeight
792 -- |> List.sum
896 -- |> List.sum
793 -- TODO: apparently the font metrics we have are for the literal characters rendered
897 -- TODO: apparently the font metrics we have are for the literal characters rendered
794 -- not for the font itself.
898 -- not for the font itself.
795− -- so for now, we are stubbing this in as 20, which is the default font size + line height.
899+ [ Testable.todo "calculate height from actual text metrics"
796− Testable.rounded "expected multiple of 20"
900+ ]
903+ [ expectRoundedEquality
797− { expected = context.self.bbox.height
904+ { expected =
798− , found = toFloat (List.length context.self.textMetrics * 20)
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"
802− expectRoundedEquality
931+ [ expectRoundedEquality
803 { expected =
932 { expected =
804 context.children
933 context.children
805 |> List.map childHeight
934 |> List.map childHeight
@@ -807,28 +936,26 @@ heightHelper maybeMin maybeMax len =
807 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
936 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
808 , found = context.self.bbox.height
937 , found = context.self.bbox.height
810− , Testable.lessThanOrEqual "not larger than parent"
939+ , Testable.lessThanOrEqual "not larger than parent"
811− context.self.bbox.height
940+ context.self.bbox.height
812− context.parent.bbox.height
941+ context.parent.bbox.height
815 Testable.Row _ _ ->
944 Testable.Row _ _ ->
817 childHeight child =
946 childHeight child =
818 child.bbox.height
947 child.bbox.height
820− [ if List.isEmpty context.children then
949+ if List.isEmpty context.children then
821 -- context.self.textMetrics
950 -- context.self.textMetrics
822 -- |> List.map Testable.textHeight
951 -- |> List.map Testable.textHeight
823 -- |> List.sum
952 -- |> List.sum
824 -- TODO: apparently the font metrics we have are for the literal characters rendered
953 -- TODO: apparently the font metrics we have are for the literal characters rendered
825 -- not for the font itself.
954 -- not for the font itself.
826− -- so for now, we are stubbing this in as 20, which is the default font size.
955+ [ Testable.todo "calculate height from actual text metrics" ]
827− Testable.true "expected multiple of 20"
828− ((round context.self.bbox.height |> modBy 20) == 0)
831− expectRoundedEquality
958+ [ expectRoundedEquality
832 { expected =
959 { expected =
833 context.children
960 context.children
834 |> List.map childHeight
961 |> List.map childHeight
@@ -837,10 +964,10 @@ heightHelper maybeMin maybeMax len =
837 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
964 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
838 , found = context.self.bbox.height
965 , found = context.self.bbox.height
840− , Testable.lessThanOrEqual "not larger than parent"
967+ , Testable.lessThanOrEqual "not larger than parent"
841− context.self.bbox.height
968+ context.self.bbox.height
842− context.parent.bbox.height
969+ context.parent.bbox.height
845 Testable.Column colAttrs _ ->
972 Testable.Column colAttrs _ ->
@@ -872,16 +999,10 @@ heightHelper maybeMin maybeMax len =
874 Testable.TextColumn _ _ ->
1001 Testable.TextColumn _ _ ->
875− [ Testable.lessThanOrEqual "not larger than parent"
876− context.self.bbox.height
877− context.parent.bbox.height
880 Testable.Paragraph _ _ ->
1004 Testable.Paragraph _ _ ->
881− [ Testable.lessThanOrEqual "not larger than parent"
882− context.self.bbox.height
883− context.parent.bbox.height
886 Testable.Text _ ->
1007 Testable.Text _ ->