@@ -10,6 +10,7 @@ module Testable.Element exposing
15 , expectRoundedEquality
16 , expectRoundedEquality
@@ -20,6 +21,7 @@ module Testable.Element exposing
20 , isVisible
21 , isVisible
25 , moveDown
27 , moveDown
@@ -36,10 +38,14 @@ module Testable.Element exposing
42 , textColumn
47 , textColumn
43 , transparent
49 , transparent
@@ -63,11 +69,16 @@ import Testable
63import 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 ]
66−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
67layout attrs elem =
80layout attrs elem =
68− Testable.Runner.program
81+ Testable.Runner.testable "Test" elem
69− [ ( "Tests Run", elem )
73text : String -> Testable.Element msg
84text : String -> Testable.Element msg
@@ -97,12 +108,59 @@ none =
98paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
109paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
99paragraph attrs =
110paragraph attrs =
100− Testable.Paragraph (implicitWidthHeightShrink attrs)
111+ let
113+ implicitTest (widthHelper Nothing Nothing (Fill 1))
114+ :: implicitTest (heightHelper Nothing Nothing Shrink)
117+ Testable.Paragraph (skipOverridden withImplicits)
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
120textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
104textColumn attrs =
121textColumn attrs =
124+ implicitTest (widthHelper (Just 500) (Just 750) (Fill 1))
125+ :: implicitTest (heightHelper Nothing Nothing Shrink)
128+ Testable.TextColumn (skipOverridden withImplicits)
132+ List (Testable.Attr msg)
135+ , label : Testable.Element msg
137+ -> Testable.Element msg
139+ Testable.Link details.url
105− Testable.TextColumn (implicitWidthHeightShrink attrs)
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
108{-| Old labeling mechanism that i removed to hastily
166{-| Old labeling mechanism that i removed to hastily
@@ -276,6 +334,11 @@ paddingXY x y =
338+ List.filter Tuple.first ls
339+ |> List.map Tuple.second
279widthHelper maybeMin maybeMax len =
342widthHelper maybeMin maybeMax len =
281 addMin l =
344 addMin l =
@@ -344,7 +407,10 @@ widthHelper maybeMin maybeMax len =
346 \found ->
409 \found ->
410+ [ expectRoundedEquality
411+ { expected = toFloat val
347− [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
412+ , found = found.self.bbox.width
348 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
414 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
@@ -374,33 +440,93 @@ widthHelper maybeMin maybeMax len =
374 parentAvailableWidth =
440 parentAvailableWidth =
375 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
441 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
377− [ case context.parentLayout of
444+ [ case context.parentLayout of
378− Testable.IsNearby _ ->
445+ Testable.IsNearby _ ->
379− Testable.true "Nearby Element has fill width"
446+ [ Testable.true "Nearby Element has fill width"
380− ((floor context.parent.bbox.width == floor context.self.bbox.width)
447+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
381− || minMaxTest (floor context.self.bbox.width)
448+ || minMaxTest (floor context.self.bbox.width)
384− Testable.InColumn ->
385− Testable.true "Element within column has fill width"
386− ((floor parentAvailableWidth == floor context.self.bbox.width)
387− || minMaxTest (floor context.self.bbox.width)
452+ Testable.InColumn ->
453+ [ Testable.true "Element within column has fill width"
454+ ((floor parentAvailableWidth == floor context.self.bbox.width)
455+ || minMaxTest (floor context.self.bbox.width)
390− Testable.InEl ->
459+ Testable.InEl ->
391− Testable.true "Element within element has fill width" <|
460+ [ Testable.true "Element within element has fill width" <|
392− (floor parentAvailableWidth == floor context.self.bbox.width)
461+ (floor parentAvailableWidth == floor context.self.bbox.width)
462+ || 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)
393− || minMaxTest (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)
398− parentAvailableWidth / toFloat (List.length context.siblings + 1)
400− Testable.true "element has fill width" <|
401− (floor spacePerPortion == floor context.self.bbox.width)
402− || minMaxTest (floor context.self.bbox.width)
406 Shrink ->
532 Shrink ->
@@ -430,13 +556,51 @@ widthHelper maybeMin maybeMax len =
430 horizontalPadding =
556 horizontalPadding =
431 context.self.bbox.padding.left + context.self.bbox.padding.right
557 context.self.bbox.padding.left + context.self.bbox.padding.right
433− [ expectRoundedEquality
559+ listIf
560+ [ ( (context.parentLayout /= Testable.InParagraph)
561+ && (context.parentLayout /= Testable.InTextCol)
562+ , Testable.rounded "equals children"
434− { expected = totalChildren + horizontalPadding
563+ { expected = totalChildren + horizontalPadding
435− , found = context.self.bbox.width
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
439− Testable.Row _ _ ->
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)
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
599+ context.parent.bbox.width
603+ Testable.Row rowAttrs _ ->
440 -- width of row is the sum of all children widths
604 -- width of row is the sum of all children widths
441 -- both text elements and others.
605 -- both text elements and others.
@@ -452,14 +616,25 @@ widthHelper maybeMin maybeMax len =
452 horizontalPadding =
616 horizontalPadding =
453 context.self.bbox.padding.left + context.self.bbox.padding.right
617 context.self.bbox.padding.left + context.self.bbox.padding.right
455− spacingValue =
619+ spacingAmount =
620+ Testable.getSpacingFromAttributes rowAttrs
456− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
623+ toFloat spacingAmount * (toFloat (List.length context.children) - 1)
458− [ expectRoundedEquality
627+ , expectRoundedEquality
459− { expected = totalChildren + horizontalPadding + spacingValue
628+ { expected = totalChildren + horizontalPadding + totalSpacing
460− , found = context.self.bbox.width
629+ , found = context.self.bbox.width
632+ , ( context.parentLayout /= Testable.AtRoot
633+ , Testable.lessThanOrEqual "not larger than parent"
634+ context.self.bbox.width
635+ context.parent.bbox.width
464 Testable.Column _ _ ->
639 Testable.Column _ _ ->
465 -- 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.
@@ -483,14 +658,55 @@ widthHelper maybeMin maybeMax len =
483 |> List.map childWidth
658 |> List.map childWidth
484 |> List.append textChildren
659 |> List.append textChildren
486− [ expectRoundedEquality
663+ , expectRoundedEquality
487− { expected = Maybe.withDefault 0 (List.maximum allChildren)
664+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
488− , found = context.self.bbox.width
665+ , found = context.self.bbox.width
668+ , ( context.parentLayout /= Testable.AtRoot
669+ , Testable.lessThanOrEqual "not larger than parent"
670+ context.self.bbox.width
671+ context.parent.bbox.width
492 Testable.TextColumn _ _ ->
675 Testable.TextColumn _ _ ->
676+ -- The width of the column is the width of the widest child.
680+ + context.self.bbox.padding.left
681+ + context.self.bbox.padding.right
687+ + context.self.bbox.padding.left
688+ + context.self.bbox.padding.right
690+ context.self.textMetrics
694+ |> List.map childWidth
695+ |> List.append textChildren
699+ , expectRoundedEquality
700+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
701+ , found = context.self.bbox.width
704+ , ( context.parentLayout /= Testable.AtRoot
705+ , Testable.lessThanOrEqual "not larger than parent"
706+ context.self.bbox.width
707+ context.parent.bbox.width
495 Testable.Paragraph _ _ ->
711 Testable.Paragraph _ _ ->
496 -- This should be the size it's text,
712 -- This should be the size it's text,
@@ -508,11 +724,19 @@ widthHelper maybeMin maybeMax len =
508 horizontalPadding =
724 horizontalPadding =
509 context.self.bbox.padding.left + context.self.bbox.padding.right
725 context.self.bbox.padding.left + context.self.bbox.padding.right
511− [ expectRoundedEquality
729+ , expectRoundedEquality
512− { expected = totalChildren + horizontalPadding
730+ { expected = totalChildren + horizontalPadding
513− , found = context.self.bbox.width
731+ , found = context.self.bbox.width
734+ , ( context.parentLayout /= Testable.AtRoot
735+ , Testable.lessThanOrEqual "not larger than parent"
736+ context.self.bbox.width
737+ context.parent.bbox.width
517 Testable.Text _ ->
741 Testable.Text _ ->
@@ -590,8 +814,10 @@ heightHelper maybeMin maybeMax len =
590 , id = Testable.IsHeight
814 , id = Testable.IsHeight
592 \found ->
816 \found ->
593− [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
817+ [ expectRoundedEquality
818+ { expected = toFloat val
594− (floor found.self.bbox.height == val)
819+ , found = found.self.bbox.height
595 , Testable.true "min/max holds true"
821 , Testable.true "min/max holds true"
596 (minMaxTest (floor found.self.bbox.height))
822 (minMaxTest (floor found.self.bbox.height))
@@ -662,49 +888,88 @@ heightHelper maybeMin maybeMax len =
662 Testable.El _ _ ->
888 Testable.El _ _ ->
664 childHeight child =
890 childHeight child =
665− -- TODO: add margin values to heights
666 child.bbox.height
891 child.bbox.height
893+ if List.isEmpty context.children then
894+ -- context.self.textMetrics
895+ -- |> List.map Testable.textHeight
897+ -- TODO: apparently the font metrics we have are for the literal characters rendered
898+ -- not for the font itself.
899+ [ Testable.todo "calculate height from actual text metrics"
668− totalChildren =
902+ else
903+ [ expectRoundedEquality
669− context.children
905+ context.children
670− |> List.map childHeight
906+ |> List.map childHeight
671− |> List.append (List.map Testable.textHeight context.self.textMetrics)
672− |> List.sum
907+ |> List.sum
675− context.self.bbox.padding.top + context.self.bbox.padding.bottom
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
677− spacingValue =
916+ Testable.Link _ _ _ ->
678− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
917+ let
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"
680− [ expectRoundedEquality
931+ [ expectRoundedEquality
681− { expected = totalChildren + verticalPadding + spacingValue
932+ { expected =
934+ |> List.map childHeight
936+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
682− , found = context.self.bbox.height
937+ , found = context.self.bbox.height
939+ , Testable.lessThanOrEqual "not larger than parent"
940+ context.self.bbox.height
941+ context.parent.bbox.height
686 Testable.Row _ _ ->
944 Testable.Row _ _ ->
688 childHeight child =
946 childHeight child =
689 child.bbox.height
947 child.bbox.height
693− |> List.map childHeight
694− |> List.append (List.map Testable.textHeight context.self.textMetrics)
696− |> Maybe.withDefault 0
699− context.self.bbox.padding.top + context.self.bbox.padding.bottom
949+ if List.isEmpty context.children then
950+ -- context.self.textMetrics
951+ -- |> List.map Testable.textHeight
953+ -- TODO: apparently the font metrics we have are for the literal characters rendered
954+ -- not for the font itself.
955+ [ Testable.todo "calculate height from actual text metrics" ]
701− [ expectRoundedEquality
958+ [ expectRoundedEquality
702− { expected = totalChildren + verticalPadding
959+ { expected =
961+ |> List.map childHeight
963+ |> Maybe.withDefault 0
964+ |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
703− , found = context.self.bbox.height
965+ , found = context.self.bbox.height
967+ , Testable.lessThanOrEqual "not larger than parent"
968+ context.self.bbox.height
969+ context.parent.bbox.height
707− Testable.Column _ _ ->
972+ Testable.Column colAttrs _ ->
709 childHeight child =
974 childHeight child =
710 child.bbox.height
975 child.bbox.height
@@ -718,13 +983,19 @@ heightHelper maybeMin maybeMax len =
718 verticalPadding =
983 verticalPadding =
719 context.self.bbox.padding.top + context.self.bbox.padding.bottom
984 context.self.bbox.padding.top + context.self.bbox.padding.bottom
721− spacingValue =
986+ spacingAmount =
987+ Testable.getSpacingFromAttributes colAttrs
722− toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
990+ toFloat spacingAmount * (toFloat (List.length context.children) - 1)
724 [ expectRoundedEquality
992 [ expectRoundedEquality
725− { expected = totalChildren + verticalPadding + spacingValue
993+ { expected = totalChildren + verticalPadding + totalSpacing
726 , found = context.self.bbox.height
994 , found = context.self.bbox.height
996+ , Testable.lessThanOrEqual "not larger than parent"
997+ context.self.bbox.height
998+ context.parent.bbox.height
730 Testable.TextColumn _ _ ->
1001 Testable.TextColumn _ _ ->