@@ -10,7 +10,6 @@ module Testable.Element exposing
1010 , below
1111 , centerX
1212 , centerY
13− , clip
1413 , column
1514 , el
1615 , expectRoundedEquality
@@ -38,14 +37,10 @@ module Testable.Element exposing
3837 , rgb
3938 , rgba
4039 , row
41− , scrollbarX
42− , scrollbarY
43− , scrollbars
4440 , shrink
4541 , spacing
4642 , text
4743 , textColumn
48− , toProgram
4944 , transparent
5045 , width
5146 )
@@ -69,16 +64,11 @@ import Testable
6964import Testable.Runner
7065
7166
72−{-| This is used when we want to run all tests in a test suite instead of one at a time.
73−-}
74−toProgram : Testable.Runner.Testable -> Testable.Runner.TestableProgram
75−toProgram testable =
76− Testable.Runner.program [ testable ]
77−
78−
79−layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.Testable
67+layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
8068layout attrs elem =
81− Testable.Runner.testable "Test" elem
69+ Testable.Runner.program
70+ [ ( "Tests Run", elem )
71+ ]
8272
8373
8474text : String -> Testable.Element msg
@@ -136,31 +126,8 @@ link :
136126 }
137127 -> Testable.Element msg
138128link 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
129+ -- TODO: this is not actually a link element!!
130+ Testable.El (implicitWidthHeightShrink attrs) details.label
164131
165132
166133{-| Old labeling mechanism that i removed to hastily
@@ -334,11 +301,6 @@ paddingXY x y =
334301 }
335302
336303
337−listIf ls =
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
340−
341−
342304widthHelper maybeMin maybeMax len =
343305 let
344306 addMin l =
@@ -497,31 +459,12 @@ widthHelper maybeMin maybeMax len =
497459 totalChildren + horizontalPadding
498460
499461 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
462+ ceiling (totalCalculatedWidth / context.self.bbox.width)
513463 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− )
464+ [ Testable.rounded "text wrapping, checking height"
465+ { expected = toFloat (expectedLines * 22)
466+ , found = context.self.bbox.height
467+ }
525468 ]
526469
527470 _ ->
@@ -555,50 +498,23 @@ widthHelper maybeMin maybeMax len =
555498
556499 horizontalPadding =
557500 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
578−
579− totalChildren =
580− context.children
581− |> List.map childWidth
582− |> List.append (List.map .width context.self.textMetrics)
583− |> List.sum
584501
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
502+ _ =
503+ Debug.log "widths"
504+ { children =
505+ context.children
506+ |> List.map childWidth
507+ , text = List.map .width context.self.textMetrics
594508 }
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− ]
509+ in
510+ [ Testable.rounded "equals children"
511+ { expected = totalChildren + horizontalPadding
512+ , found = context.self.bbox.width
513+ }
514+ , Testable.lessThanOrEqual "not larger than parent"
515+ context.self.bbox.width
516+ context.parent.bbox.width
517+ ]
602518
603519 Testable.Row rowAttrs _ ->
604520 -- width of row is the sum of all children widths
@@ -622,19 +538,14 @@ widthHelper maybeMin maybeMax len =
622538 totalSpacing =
623539 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
624540 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− ]
541+ [ expectRoundedEquality
542+ { expected = totalChildren + horizontalPadding + totalSpacing
543+ , found = context.self.bbox.width
544+ }
545+ , Testable.lessThanOrEqual "not larger than parent"
546+ context.self.bbox.width
547+ context.parent.bbox.width
548+ ]
638549
639550 Testable.Column _ _ ->
640551 -- The width of the column is the width of the widest child.
@@ -658,19 +569,14 @@ widthHelper maybeMin maybeMax len =
658569 |> List.map childWidth
659570 |> List.append textChildren
660571 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− ]
572+ [ expectRoundedEquality
573+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
574+ , found = context.self.bbox.width
575+ }
576+ , Testable.lessThanOrEqual "not larger than parent"
577+ context.self.bbox.width
578+ context.parent.bbox.width
579+ ]
674580
675581 Testable.TextColumn _ _ ->
676582 -- The width of the column is the width of the widest child.
@@ -694,19 +600,14 @@ widthHelper maybeMin maybeMax len =
694600 |> List.map childWidth
695601 |> List.append textChildren
696602 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− ]
603+ [ expectRoundedEquality
604+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
605+ , found = context.self.bbox.width
606+ }
607+ , Testable.lessThanOrEqual "not larger than parent"
608+ context.self.bbox.width
609+ context.parent.bbox.width
610+ ]
710611
711612 Testable.Paragraph _ _ ->
712613 -- This should be the size it's text,
@@ -724,19 +625,14 @@ widthHelper maybeMin maybeMax len =
724625 horizontalPadding =
725626 context.self.bbox.padding.left + context.self.bbox.padding.right
726627 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− ]
628+ [ expectRoundedEquality
629+ { expected = totalChildren + horizontalPadding
630+ , found = context.self.bbox.width
631+ }
632+ , Testable.lessThanOrEqual "not larger than parent"
633+ context.self.bbox.width
634+ context.parent.bbox.width
635+ ]
740636
741637 Testable.Text _ ->
742638 []
@@ -890,45 +786,20 @@ heightHelper maybeMin maybeMax len =
890786 childHeight child =
891787 child.bbox.height
892788 in
893− if List.isEmpty context.children then
789+ [ if List.isEmpty context.children then
894790 -- context.self.textMetrics
895791 -- |> List.map Testable.textHeight
896792 -- |> List.sum
897793 -- TODO: apparently the font metrics we have are for the literal characters rendered
898794 -- 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
795+ -- so for now, we are stubbing this in as 20, which is the default font size + line height.
796+ Testable.rounded "expected multiple of 20"
797+ { expected = context.self.bbox.height
798+ , found = toFloat (List.length context.self.textMetrics * 20)
910799 }
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− ]
929800
930− else
931− [ expectRoundedEquality
801+ else
802+ expectRoundedEquality
932803 { expected =
933804 context.children
934805 |> List.map childHeight
@@ -936,26 +807,28 @@ heightHelper maybeMin maybeMax len =
936807 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
937808 , found = context.self.bbox.height
938809 }
939− , Testable.lessThanOrEqual "not larger than parent"
940− context.self.bbox.height
941− context.parent.bbox.height
942− ]
810+ , Testable.lessThanOrEqual "not larger than parent"
811+ context.self.bbox.height
812+ context.parent.bbox.height
813+ ]
943814
944815 Testable.Row _ _ ->
945816 let
946817 childHeight child =
947818 child.bbox.height
948819 in
949− if List.isEmpty context.children then
820+ [ if List.isEmpty context.children then
950821 -- context.self.textMetrics
951822 -- |> List.map Testable.textHeight
952823 -- |> List.sum
953824 -- TODO: apparently the font metrics we have are for the literal characters rendered
954825 -- not for the font itself.
955− [ Testable.todo "calculate height from actual text metrics" ]
826+ -- so for now, we are stubbing this in as 20, which is the default font size.
827+ Testable.true "expected multiple of 20"
828+ ((round context.self.bbox.height |> modBy 20) == 0)
956829
957− else
958− [ expectRoundedEquality
830+ else
831+ expectRoundedEquality
959832 { expected =
960833 context.children
961834 |> List.map childHeight
@@ -964,10 +837,10 @@ heightHelper maybeMin maybeMax len =
964837 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
965838 , found = context.self.bbox.height
966839 }
967− , Testable.lessThanOrEqual "not larger than parent"
968− context.self.bbox.height
969− context.parent.bbox.height
970− ]
840+ , Testable.lessThanOrEqual "not larger than parent"
841+ context.self.bbox.height
842+ context.parent.bbox.height
843+ ]
971844
972845 Testable.Column colAttrs _ ->
973846 let
@@ -999,10 +872,16 @@ heightHelper maybeMin maybeMax len =
999872 ]
1000873
1001874 Testable.TextColumn _ _ ->
1002− []
875+ [ Testable.lessThanOrEqual "not larger than parent"
876+ context.self.bbox.height
877+ context.parent.bbox.height
878+ ]
1003879
1004880 Testable.Paragraph _ _ ->
1005− []
881+ [ Testable.lessThanOrEqual "not larger than parent"
882+ context.self.bbox.height
883+ context.parent.bbox.height
884+ ]
1006885
1007886 Testable.Text _ ->
1008887 []