@@ -10,7 +10,6 @@ module Testable.Element exposing
16 , expectRoundedEquality
15 , expectRoundedEquality
@@ -38,14 +37,10 @@ module Testable.Element exposing
47 , textColumn
43 , textColumn
49 , transparent
44 , transparent
@@ -69,16 +64,11 @@ import Testable
69import Testable.Runner
64import 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 ]
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
80layout attrs elem =
68layout attrs elem =
81− Testable.Runner.testable "Test" elem
69+ Testable.Runner.program
70+ [ ( "Tests Run", elem )
84text : String -> Testable.Element msg
74text : String -> Testable.Element msg
@@ -136,31 +126,8 @@ link :
137 -> Testable.Element msg
127 -> Testable.Element msg
138link attrs details =
128link attrs details =
139− Testable.Link details.url
129+ -- TODO: this is not actually a link element!!
140− (implicitWidthHeightShrink attrs)
130+ Testable.El (implicitWidthHeightShrink attrs) details.label
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
166{-| Old labeling mechanism that i removed to hastily
133{-| Old labeling mechanism that i removed to hastily
@@ -334,11 +301,6 @@ paddingXY x y =
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
342widthHelper maybeMin maybeMax len =
304widthHelper maybeMin maybeMax len =
344 addMin l =
306 addMin l =
@@ -440,93 +402,36 @@ widthHelper maybeMin maybeMax len =
440 parentAvailableWidth =
402 parentAvailableWidth =
441 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
403 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
444− [ case context.parentLayout of
405+ [ case context.parentLayout of
445− Testable.IsNearby _ ->
406+ Testable.IsNearby _ ->
446− [ Testable.true "Nearby Element has fill width"
407+ Testable.true "Nearby Element has fill width"
447− ((floor context.parent.bbox.width == floor context.self.bbox.width)
408+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
448− || minMaxTest (floor context.self.bbox.width)
409+ || minMaxTest (floor context.self.bbox.width)
452− Testable.InColumn ->
412+ Testable.InColumn ->
453− [ Testable.true "Element within column has fill width"
413+ Testable.true "Element within column has fill width"
454− ((floor parentAvailableWidth == floor context.self.bbox.width)
414+ ((floor parentAvailableWidth == floor context.self.bbox.width)
455− || minMaxTest (floor context.self.bbox.width)
460− [ Testable.true "Element within element has fill width" <|
461− (floor parentAvailableWidth == floor context.self.bbox.width)
462− || minMaxTest (floor context.self.bbox.width)
415+ || minMaxTest (floor context.self.bbox.width)
468− parentAvailableWidth / toFloat (List.length context.siblings + 1)
470− [ Testable.true "element has fill width" <|
471− (floor spacePerPortion == floor context.self.bbox.width)
472− || minMaxTest (floor context.self.bbox.width)
474− , [ Testable.lessThanOrEqual "not larger than parent"
475− context.self.bbox.width
476− context.parent.bbox.width
478− , case context.selfElement of
479− Testable.Paragraph _ _ ->
480− -- A paragraph with width fill
481− -- we want to test for correct text wrapping here.
489− |> List.map childWidth
490− |> List.append (List.map .width context.self.textMetrics)
494− context.self.bbox.padding.left + context.self.bbox.padding.right
496− totalCalculatedWidth =
497− totalChildren + horizontalPadding
500− if boxChildrenHeight > 20 then
501− ceiling (boxChildrenHeight / 20)
504− ceiling (totalCalculatedWidth / context.self.bbox.width)
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)
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)
419+ Testable.true "Element within element has fill width" <|
420+ (floor parentAvailableWidth == floor context.self.bbox.width)
421+ || minMaxTest (floor context.self.bbox.width)
426+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
428+ Testable.true "element has fill width" <|
429+ (floor spacePerPortion == 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
532 Shrink ->
437 Shrink ->
@@ -556,49 +461,14 @@ widthHelper maybeMin maybeMax len =
556 horizontalPadding =
461 horizontalPadding =
557 context.self.bbox.padding.left + context.self.bbox.padding.right
462 context.self.bbox.padding.left + context.self.bbox.padding.right
559− listIf
464+ [ expectRoundedEquality
560− [ ( (context.parentLayout /= Testable.InParagraph)
561− && (context.parentLayout /= Testable.InTextCol)
562− , Testable.rounded "equals children"
563− { expected = totalChildren + horizontalPadding
465+ { expected = totalChildren + horizontalPadding
564− , found = context.self.bbox.width
466+ , found = context.self.bbox.width
567− , ( context.parentLayout /= Testable.AtRoot
568− , Testable.lessThanOrEqual "not larger than parent"
468+ , 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
469+ context.self.bbox.width
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
596− , ( context.parentLayout /= Testable.AtRoot
597− , Testable.lessThanOrEqual "not larger than parent"
598− context.self.bbox.width
470+ context.parent.bbox.width
599− context.parent.bbox.width
603 Testable.Row rowAttrs _ ->
473 Testable.Row rowAttrs _ ->
604 -- width of row is the sum of all children widths
474 -- width of row is the sum of all children widths
@@ -622,19 +492,14 @@ widthHelper maybeMin maybeMax len =
622 totalSpacing =
492 totalSpacing =
623 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
493 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
627− , expectRoundedEquality
495+ [ expectRoundedEquality
628− { expected = totalChildren + horizontalPadding + totalSpacing
496+ { expected = totalChildren + horizontalPadding + totalSpacing
629− , found = context.self.bbox.width
497+ , found = context.self.bbox.width
632− , ( context.parentLayout /= Testable.AtRoot
633− , Testable.lessThanOrEqual "not larger than parent"
499+ , Testable.lessThanOrEqual "not larger than parent"
634− context.self.bbox.width
500+ context.self.bbox.width
635− context.parent.bbox.width
501+ context.parent.bbox.width
639 Testable.Column _ _ ->
504 Testable.Column _ _ ->
640 -- The width of the column is the width of the widest child.
505 -- The width of the column is the width of the widest child.
@@ -658,19 +523,14 @@ widthHelper maybeMin maybeMax len =
658 |> List.map childWidth
523 |> List.map childWidth
659 |> List.append textChildren
524 |> List.append textChildren
663− , expectRoundedEquality
526+ [ expectRoundedEquality
664− { expected = Maybe.withDefault 0 (List.maximum allChildren)
527+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
665− , found = context.self.bbox.width
528+ , found = context.self.bbox.width
668− , ( context.parentLayout /= Testable.AtRoot
669− , Testable.lessThanOrEqual "not larger than parent"
530+ , Testable.lessThanOrEqual "not larger than parent"
670− context.self.bbox.width
531+ context.self.bbox.width
671− context.parent.bbox.width
532+ context.parent.bbox.width
675 Testable.TextColumn _ _ ->
535 Testable.TextColumn _ _ ->
676 -- The width of the column is the width of the widest child.
536 -- The width of the column is the width of the widest child.
@@ -694,19 +554,14 @@ widthHelper maybeMin maybeMax len =
694 |> List.map childWidth
554 |> List.map childWidth
695 |> List.append textChildren
555 |> List.append textChildren
699− , expectRoundedEquality
557+ [ expectRoundedEquality
700− { expected = Maybe.withDefault 0 (List.maximum allChildren)
558+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
701− , found = context.self.bbox.width
559+ , found = context.self.bbox.width
704− , ( context.parentLayout /= Testable.AtRoot
705− , Testable.lessThanOrEqual "not larger than parent"
561+ , Testable.lessThanOrEqual "not larger than parent"
706− context.self.bbox.width
562+ context.self.bbox.width
707− context.parent.bbox.width
563+ context.parent.bbox.width
711 Testable.Paragraph _ _ ->
566 Testable.Paragraph _ _ ->
712 -- This should be the size it's text,
567 -- This should be the size it's text,
@@ -724,19 +579,14 @@ widthHelper maybeMin maybeMax len =
724 horizontalPadding =
579 horizontalPadding =
725 context.self.bbox.padding.left + context.self.bbox.padding.right
580 context.self.bbox.padding.left + context.self.bbox.padding.right
729− , expectRoundedEquality
582+ [ expectRoundedEquality
730− { expected = totalChildren + horizontalPadding
583+ { expected = totalChildren + horizontalPadding
731− , found = context.self.bbox.width
584+ , found = context.self.bbox.width
734− , ( context.parentLayout /= Testable.AtRoot
735− , Testable.lessThanOrEqual "not larger than parent"
586+ , Testable.lessThanOrEqual "not larger than parent"
736− context.self.bbox.width
587+ context.self.bbox.width
737− context.parent.bbox.width
588+ context.parent.bbox.width
741 Testable.Text _ ->
591 Testable.Text _ ->
@@ -890,17 +740,18 @@ heightHelper maybeMin maybeMax len =
890 childHeight child =
740 childHeight child =
891 child.bbox.height
741 child.bbox.height
893− if List.isEmpty context.children then
743+ [ if List.isEmpty context.children then
894 -- context.self.textMetrics
744 -- context.self.textMetrics
895 -- |> List.map Testable.textHeight
745 -- |> List.map Testable.textHeight
896 -- |> List.sum
746 -- |> List.sum
897 -- TODO: apparently the font metrics we have are for the literal characters rendered
747 -- TODO: apparently the font metrics we have are for the literal characters rendered
898 -- not for the font itself.
748 -- not for the font itself.
899− [ Testable.todo "calculate height from actual text metrics"
749+ -- so for now, we are stubbing this in as 20, which is the default font size.
900− ]
750+ Testable.true "expected multiple of 20"
751+ ((round context.self.bbox.height |> modBy 20) == 0)
903− [ expectRoundedEquality
754+ expectRoundedEquality
904 { expected =
755 { expected =
905 context.children
756 context.children
906 |> List.map childHeight
757 |> List.map childHeight
@@ -908,54 +759,28 @@ heightHelper maybeMin maybeMax len =
908 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
759 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
909 , found = context.self.bbox.height
760 , found = context.self.bbox.height
911− , Testable.lessThanOrEqual "not larger than parent"
762+ , 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
763+ context.self.bbox.height
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"
931− [ expectRoundedEquality
934− |> List.map childHeight
936− |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
937− , found = context.self.bbox.height
939− , Testable.lessThanOrEqual "not larger than parent"
940− context.self.bbox.height
941− context.parent.bbox.height
764+ context.parent.bbox.height
944 Testable.Row _ _ ->
767 Testable.Row _ _ ->
946 childHeight child =
769 childHeight child =
947 child.bbox.height
770 child.bbox.height
949− if List.isEmpty context.children then
772+ [ if List.isEmpty context.children then
950 -- context.self.textMetrics
773 -- context.self.textMetrics
951 -- |> List.map Testable.textHeight
774 -- |> List.map Testable.textHeight
952 -- |> List.sum
775 -- |> List.sum
953 -- TODO: apparently the font metrics we have are for the literal characters rendered
776 -- TODO: apparently the font metrics we have are for the literal characters rendered
954 -- not for the font itself.
777 -- not for the font itself.
955− [ Testable.todo "calculate height from actual text metrics" ]
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)
958− [ expectRoundedEquality
783+ expectRoundedEquality
959 { expected =
784 { expected =
960 context.children
785 context.children
961 |> List.map childHeight
786 |> List.map childHeight
@@ -964,10 +789,10 @@ heightHelper maybeMin maybeMax len =
964 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
789 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
965 , found = context.self.bbox.height
790 , found = context.self.bbox.height
967− , Testable.lessThanOrEqual "not larger than parent"
792+ , Testable.lessThanOrEqual "not larger than parent"
968− context.self.bbox.height
793+ context.self.bbox.height
969− context.parent.bbox.height
794+ context.parent.bbox.height
972 Testable.Column colAttrs _ ->
797 Testable.Column colAttrs _ ->
@@ -999,10 +824,16 @@ heightHelper maybeMin maybeMax len =
1001 Testable.TextColumn _ _ ->
826 Testable.TextColumn _ _ ->
827+ [ Testable.lessThanOrEqual "not larger than parent"
828+ context.self.bbox.height
829+ context.parent.bbox.height
1004 Testable.Paragraph _ _ ->
832 Testable.Paragraph _ _ ->
833+ [ Testable.lessThanOrEqual "not larger than parent"
834+ context.self.bbox.height
835+ context.parent.bbox.height
1007 Testable.Text _ ->
838 Testable.Text _ ->