git.iko.soy/typeable/elm-ui
on master help sign in
testing: allow implicit width/height testing (and in the process break a lot of tests!)
80e267cElm UI Automation
tests-rendering/automation/run.js+1−1
@@ -287,7 +287,7 @@ function print_results(label, tests) {
287 }
287 }
288 failed = failed + 1;
288 failed = failed + 1;
289 console.log(" " + chalk.red("fail") + " ->");
289 console.log(" " + chalk.red("fail") + " ->");
290− console.log(" " + tests[i].results[j][1].description);
290+ console.log(" " + tests[i].results[j].description);
291 }
291 }
292 }
292 }
293 total_passed = total_passed + passed;
293 total_passed = total_passed + passed;
tests-rendering/src/Testable.elm+19
@@ -1,5 +1,6 @@
1module Testable exposing
1module Testable exposing
2 ( Attr(..)
2 ( Attr(..)
3+ , AttributeId(..)
3 , BoundingBox
4 , BoundingBox
4 , Element(..)
5 , Element(..)
5 , Found
6 , Found
@@ -42,11 +43,27 @@ type Element msg
42 | Empty
43 | Empty
43
44
44
45
46+{-| We have an attribute id in order to remove tests when an overriding attribtue is assigned.
47+
48+Basically, we want to implictly test for height/width shrink.
49+
50+But we want to skip this test if width/height is already set.
51+
52+This allows us to do that by comparing identities.
53+
54+-}
55+type AttributeId
56+ = NoId
57+ | IsWidth
58+ | IsHeight
59+
60+
45type Attr msg
61type Attr msg
46 = Attr (Element.Attribute msg)
62 = Attr (Element.Attribute msg)
47 | AttrTest
63 | AttrTest
48 { test : Surroundings -> List LayoutExpectation
64 { test : Surroundings -> List LayoutExpectation
49 , label : String
65 , label : String
66+ , id : AttributeId
50 }
67 }
51 | Batch (List (Attr msg))
68 | Batch (List (Attr msg))
52 | Spacing Int
69 | Spacing Int
@@ -60,6 +77,7 @@ type Attr msg
60 { test : Surroundings -> List LayoutExpectation
77 { test : Surroundings -> List LayoutExpectation
61 , label : String
78 , label : String
62 , attr : Element.Attribute msg
79 , attr : Element.Attribute msg
80+ , id : AttributeId
63 }
81 }
64
82
65
83
@@ -627,6 +645,7 @@ createAttributeTest parent cache level attrIndex surroundings attr =
627 { label = nearby.label
645 { label = nearby.label
628 , test =
646 , test =
629 nearby.test
647 nearby.test
648+ , id = NoId
630 }
649 }
631 )
650 )
632 nearby.element
651 nearby.element
tests-rendering/src/Testable/Element.elm+220−67
@@ -58,7 +58,6 @@ In order to run the test:
58
58
59import Dict
59import Dict
60import Element
60import Element
61−import Expect
62import Html.Attributes
61import Html.Attributes
63import Testable
62import Testable
64import Testable.Runner
63import Testable.Runner
@@ -67,7 +66,7 @@ import Testable.Runner
67layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
66layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
68layout attrs elem =
67layout attrs elem =
69 Testable.Runner.program
68 Testable.Runner.program
70− [ ( "Open Case", elem )
69+ [ ( "Tests Run", elem )
71 ]
70 ]
72
71
73
72
@@ -77,18 +76,18 @@ text =
77
76
78
77
79el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
78el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
80−el =
79+el attrs =
81− Testable.El
80+ Testable.El (implicitWidthHeightShrink attrs)
82
81
83
82
84row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
83row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
85−row =
84+row attrs =
86− Testable.Row
85+ Testable.Row (implicitWidthHeightShrink attrs)
87
86
88
87
89column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
88column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
90−column =
89+column attrs =
91− Testable.Column
90+ Testable.Column (implicitWidthHeightShrink attrs)
92
91
93
92
94none : Testable.Element msg
93none : Testable.Element msg
@@ -102,8 +101,8 @@ paragraph =
102
101
103
102
104textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
105−textColumn =
104+textColumn attrs =
106− Testable.TextColumn
105+ Testable.TextColumn (implicitWidthHeightShrink attrs)
107
106
108
107
109{-| Old labeling mechanism that i removed to hastily
108{-| Old labeling mechanism that i removed to hastily
@@ -182,6 +181,7 @@ transparent on =
182 else
181 else
183 "opaque"
182 "opaque"
184 , attr = Element.transparent on
183 , attr = Element.transparent on
184+ , id = Testable.NoId
185 , test =
185 , test =
186 \context ->
186 \context ->
187 let
187 let
@@ -204,9 +204,9 @@ transparent on =
204{-| -}
204{-| -}
205isVisible : Testable.Attr msg
205isVisible : Testable.Attr msg
206isVisible =
206isVisible =
207− Testable.LabeledTest
207+ Testable.AttrTest
208 { label = "is-visible"
208 { label = "is-visible"
209− , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
209+ , id = Testable.NoId
210 , test =
210 , test =
211 \context ->
211 \context ->
212 [ Testable.equal context.self.isVisible True ]
212 [ Testable.equal context.self.isVisible True ]
@@ -219,6 +219,7 @@ alpha a =
219 Testable.LabeledTest
219 Testable.LabeledTest
220 { label = "alpha-" ++ String.fromFloat a
220 { label = "alpha-" ++ String.fromFloat a
221 , attr = Element.alpha a
221 , attr = Element.alpha a
222+ , id = Testable.NoId
222 , test =
223 , test =
223 \context ->
224 \context ->
224 let
225 let
@@ -237,6 +238,7 @@ padding pad =
237 Testable.LabeledTest
238 Testable.LabeledTest
238 { label = "padding " ++ String.fromInt pad
239 { label = "padding " ++ String.fromInt pad
239 , attr = Element.padding pad
240 , attr = Element.padding pad
241+ , id = Testable.NoId
240 , test =
242 , test =
241 \found ->
243 \found ->
242 [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
244 [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
@@ -257,6 +259,7 @@ paddingXY x y =
257 Testable.LabeledTest
259 Testable.LabeledTest
258 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
260 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
259 , attr = Element.paddingXY x y
261 , attr = Element.paddingXY x y
262+ , id = Testable.NoId
260 , test =
263 , test =
261 \found ->
264 \found ->
262 [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
265 [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
@@ -332,6 +335,7 @@ widthHelper maybeMin maybeMax len =
332 -- Pixel values should ignore min and max?
335 -- Pixel values should ignore min and max?
333 Testable.LabeledTest
336 Testable.LabeledTest
334 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
337 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
338+ , id = Testable.IsWidth
335 , attr =
339 , attr =
336 Element.width
340 Element.width
337 (Element.px val
341 (Element.px val
@@ -353,6 +357,7 @@ widthHelper maybeMin maybeMax len =
353
357
354 else
358 else
355 "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
359 "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
360+ , id = Testable.IsWidth
356 , attr =
361 , attr =
357 Element.width
362 Element.width
358 (Element.fillPortion portion
363 (Element.fillPortion portion
@@ -407,6 +412,7 @@ widthHelper maybeMin maybeMax len =
407 |> addMin
412 |> addMin
408 |> addMax
413 |> addMax
409 )
414 )
415+ , id = Testable.IsWidth
410 , test =
416 , test =
411 \context ->
417 \context ->
412 let
418 let
@@ -428,12 +434,17 @@ widthHelper maybeMin maybeMax len =
428 if totalChildren == 0 then
434 if totalChildren == 0 then
429 -- TODO: The issue is that we have a hard time measuring `text` elements
435 -- TODO: The issue is that we have a hard time measuring `text` elements
430 -- So if a element has a text child, then it's width isn't going to show up in the system.
436 -- So if a element has a text child, then it's width isn't going to show up in the system.
431− [ expectRoundedEquality context.self.bbox.width context.self.bbox.width ]
437+ [ Testable.Todo "Calculate text size for width-shrink calculation"
438+ ]
432
439
433 else
440 else
434 -- This fails if this element is actually a column
441 -- This fails if this element is actually a column
435 -- So we need to capture what this element is in order to do this calculation.
442 -- So we need to capture what this element is in order to do this calculation.
443+ [ expectRoundedEquality
436− [ expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width ]
444+ { expected = totalChildren + horizontalPadding + spacingValue
445+ , found = context.self.bbox.width
446+ }
447+ ]
437 }
448 }
438
449
439
450
@@ -502,6 +513,7 @@ heightHelper maybeMin maybeMax len =
502 |> addMin
513 |> addMin
503 |> addMax
514 |> addMax
504 )
515 )
516+ , id = Testable.IsHeight
505 , test =
517 , test =
506 \found ->
518 \found ->
507 [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
519 [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
@@ -520,6 +532,7 @@ heightHelper maybeMin maybeMax len =
520 |> addMin
532 |> addMin
521 |> addMax
533 |> addMax
522 )
534 )
535+ , id = Testable.IsHeight
523 , test =
536 , test =
524 \context ->
537 \context ->
525 [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
538 [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
@@ -568,16 +581,17 @@ heightHelper maybeMin maybeMax len =
568 |> addMin
581 |> addMin
569 |> addMax
582 |> addMax
570 )
583 )
584+ , id = Testable.IsHeight
571 , test =
585 , test =
572 \context ->
586 \context ->
573 let
587 let
574− childWidth child =
588+ childHeight child =
575 -- TODO: add margin values to heights
589 -- TODO: add margin values to heights
576 child.bbox.height
590 child.bbox.height
577
591
578 totalChildren =
592 totalChildren =
579 context.children
593 context.children
580− |> List.map childWidth
594+ |> List.map childHeight
581 |> List.sum
595 |> List.sum
582
596
583 verticalPadding =
597 verticalPadding =
@@ -589,12 +603,17 @@ heightHelper maybeMin maybeMax len =
589 if totalChildren == 0 then
603 if totalChildren == 0 then
590 -- TODO: The issue is that we have a hard time measuring `text` elements
604 -- TODO: The issue is that we have a hard time measuring `text` elements
591 -- So if a element has a text child, then it's height isn't going to show up in the system.
605 -- So if a element has a text child, then it's height isn't going to show up in the system.
592− [ expectRoundedEquality context.self.bbox.height context.self.bbox.height ]
606+ [ Testable.Todo "Calculate expected height shrink"
607+ ]
593
608
594 else
609 else
595 -- This fails if this element is actually a column
610 -- This fails if this element is actually a column
596 -- So we need to capture what this element is in order to do this calculation.
611 -- So we need to capture what this element is in order to do this calculation.
612+ [ expectRoundedEquality
597− [ expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height ]
613+ { expected = totalChildren + verticalPadding + spacingValue
614+ , found = context.self.bbox.height
615+ }
616+ ]
598 }
617 }
599
618
600
619
@@ -615,6 +634,7 @@ spacing space =
615 , Testable.LabeledTest
634 , Testable.LabeledTest
616 { label = "spacing: " ++ String.fromInt space
635 { label = "spacing: " ++ String.fromInt space
617 , attr = Element.spacing space
636 , attr = Element.spacing space
637+ , id = Testable.NoId
618 , test =
638 , test =
619 \found ->
639 \found ->
620 let
640 let
@@ -693,6 +713,7 @@ alignLeft =
693 Testable.LabeledTest
713 Testable.LabeledTest
694 { label = "alignLeft"
714 { label = "alignLeft"
695 , attr = Element.alignLeft
715 , attr = Element.alignLeft
716+ , id = Testable.NoId
696 , test =
717 , test =
697 \found ->
718 \found ->
698 [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
719 [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
@@ -707,13 +728,15 @@ alignLeft =
707 ]
728 ]
708 then
729 then
709 expectRoundedEquality
730 expectRoundedEquality
710− found.self.bbox.left
731+ { found = found.self.bbox.left
711− found.parent.bbox.left
732+ , expected = found.parent.bbox.left
733+ }
712
734
713 else if List.length found.siblings == 0 then
735 else if List.length found.siblings == 0 then
714 expectRoundedEquality
736 expectRoundedEquality
715− found.self.bbox.left
737+ { found = found.self.bbox.left
716− (found.parent.bbox.left + found.parent.bbox.padding.left)
738+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
739+ }
717
740
718 else
741 else
719 case found.location of
742 case found.location of
@@ -731,13 +754,15 @@ alignLeft =
731 |> List.sum
754 |> List.sum
732 in
755 in
733 expectRoundedEquality
756 expectRoundedEquality
734− found.self.bbox.left
757+ { found = found.self.bbox.left
735− (found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings))
758+ , expected = found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings)
759+ }
736
760
737 _ ->
761 _ ->
738 expectRoundedEquality
762 expectRoundedEquality
739− found.self.bbox.left
763+ { found = found.self.bbox.left
740− (found.parent.bbox.left + found.parent.bbox.padding.left)
764+ , expected = found.parent.bbox.left + found.parent.bbox.padding.left
765+ }
741 ]
766 ]
742 }
767 }
743
768
@@ -748,6 +773,7 @@ centerX =
748 Testable.LabeledTest
773 Testable.LabeledTest
749 { label = "centerX"
774 { label = "centerX"
750 , attr = Element.centerX
775 , attr = Element.centerX
776+ , id = Testable.NoId
751 , test =
777 , test =
752 \found ->
778 \found ->
753 let
779 let
@@ -764,8 +790,9 @@ centerX =
764
790
765 else if List.length found.siblings == 0 then
791 else if List.length found.siblings == 0 then
766 [ expectRoundedEquality
792 [ expectRoundedEquality
767− selfCenter
793+ { found = selfCenter
768− parentCenter
794+ , expected = parentCenter
795+ }
769 ]
796 ]
770
797
771 else
798 else
@@ -800,12 +827,17 @@ centerX =
800 )
827 )
801 in
828 in
802 [ expectRoundedEquality
829 [ expectRoundedEquality
803− selfCenter
830+ { found = selfCenter
804− expectedCenter
831+ , expected = expectedCenter
832+ }
805 ]
833 ]
806
834
807 _ ->
835 _ ->
808− [ expectRoundedEquality selfCenter parentCenter ]
836+ [ expectRoundedEquality
837+ { found = selfCenter
838+ , expected = parentCenter
839+ }
840+ ]
809 }
841 }
810
842
811
843
@@ -815,6 +847,7 @@ alignRight =
815 Testable.LabeledTest
847 Testable.LabeledTest
816 { label = "alignRight"
848 { label = "alignRight"
817 , attr = Element.alignRight
849 , attr = Element.alignRight
850+ , id = Testable.NoId
818 , test =
851 , test =
819 \found ->
852 \found ->
820 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
853 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
@@ -829,14 +862,16 @@ alignRight =
829 ]
862 ]
830 then
863 then
831 [ expectRoundedEquality
864 [ expectRoundedEquality
832− found.self.bbox.right
865+ { found = found.self.bbox.right
833− found.parent.bbox.right
866+ , expected = found.parent.bbox.right
867+ }
834 ]
868 ]
835
869
836 else if List.length found.siblings == 0 then
870 else if List.length found.siblings == 0 then
837 [ expectRoundedEquality
871 [ expectRoundedEquality
838− found.self.bbox.right
872+ { found = found.self.bbox.right
839− (found.parent.bbox.right + found.parent.bbox.padding.right)
873+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
874+ }
840 ]
875 ]
841
876
842 else
877 else
@@ -855,14 +890,16 @@ alignRight =
855 |> List.sum
890 |> List.sum
856 in
891 in
857 [ expectRoundedEquality
892 [ expectRoundedEquality
858− found.self.bbox.right
893+ { found = found.self.bbox.right
859− (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
894+ , expected = found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings)
895+ }
860 ]
896 ]
861
897
862 _ ->
898 _ ->
863 [ expectRoundedEquality
899 [ expectRoundedEquality
864− found.self.bbox.right
900+ { found = found.self.bbox.right
865− (found.parent.bbox.right + found.parent.bbox.padding.right)
901+ , expected = found.parent.bbox.right + found.parent.bbox.padding.right
902+ }
866 ]
903 ]
867 }
904 }
868
905
@@ -873,6 +910,7 @@ alignTop =
873 Testable.LabeledTest
910 Testable.LabeledTest
874 { label = "alignTop"
911 { label = "alignTop"
875 , attr = Element.alignTop
912 , attr = Element.alignTop
913+ , id = Testable.NoId
876 , test =
914 , test =
877 \found ->
915 \found ->
878 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
916 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
@@ -887,14 +925,16 @@ alignTop =
887 ]
925 ]
888 then
926 then
889 [ expectRoundedEquality
927 [ expectRoundedEquality
890− found.self.bbox.top
928+ { found = found.self.bbox.top
891− found.parent.bbox.top
929+ , expected = found.parent.bbox.top
930+ }
892 ]
931 ]
893
932
894 else if List.length found.siblings == 0 then
933 else if List.length found.siblings == 0 then
895 [ expectRoundedEquality
934 [ expectRoundedEquality
896− found.self.bbox.top
935+ { found = found.self.bbox.top
897− (found.parent.bbox.top + found.parent.bbox.padding.top)
936+ , expected = found.parent.bbox.top + found.parent.bbox.padding.top
937+ }
898 ]
938 ]
899
939
900 else
940 else
@@ -913,14 +953,16 @@ alignTop =
913 |> List.sum
953 |> List.sum
914 in
954 in
915 [ expectRoundedEquality
955 [ expectRoundedEquality
916− found.self.bbox.top
956+ { found = found.self.bbox.top
917− (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
957+ , expected = found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings)
958+ }
918 ]
959 ]
919
960
920 _ ->
961 _ ->
921 [ expectRoundedEquality
962 [ expectRoundedEquality
922− found.self.bbox.top
963+ { found = found.self.bbox.top
923− found.parent.bbox.top
964+ , expected = found.parent.bbox.top
965+ }
924 ]
966 ]
925 }
967 }
926
968
@@ -931,6 +973,7 @@ alignBottom =
931 Testable.LabeledTest
973 Testable.LabeledTest
932 { label = "alignBottom"
974 { label = "alignBottom"
933 , attr = Element.alignBottom
975 , attr = Element.alignBottom
976+ , id = Testable.NoId
934 , test =
977 , test =
935 \found ->
978 \found ->
936 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
979 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
@@ -945,14 +988,16 @@ alignBottom =
945 ]
988 ]
946 then
989 then
947 [ expectRoundedEquality
990 [ expectRoundedEquality
948− found.self.bbox.bottom
991+ { found = found.self.bbox.bottom
949− found.parent.bbox.bottom
992+ , expected = found.parent.bbox.bottom
993+ }
950 ]
994 ]
951
995
952 else if List.length found.siblings == 0 then
996 else if List.length found.siblings == 0 then
953 [ expectRoundedEquality
997 [ expectRoundedEquality
954− found.self.bbox.bottom
998+ { found = found.self.bbox.bottom
955− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
999+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
1000+ }
956 ]
1001 ]
957
1002
958 else
1003 else
@@ -971,22 +1016,25 @@ alignBottom =
971 |> List.sum
1016 |> List.sum
972 in
1017 in
973 [ expectRoundedEquality
1018 [ expectRoundedEquality
974− found.self.bbox.bottom
1019+ { found = found.self.bbox.bottom
975− (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
1020+ , expected = found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings)
1021+ }
976 ]
1022 ]
977
1023
978 _ ->
1024 _ ->
979 [ expectRoundedEquality
1025 [ expectRoundedEquality
980− found.self.bbox.bottom
1026+ { found = found.self.bbox.bottom
981− (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1027+ , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
1028+ }
982 ]
1029 ]
983 }
1030 }
984
1031
985
1032
986−expectRoundedEquality x y =
1033+expectRoundedEquality : { expected : Float, found : Float } -> Testable.LayoutExpectation
1034+expectRoundedEquality { expected, found } =
987 Testable.true
1035 Testable.true
988− ("within 1 of each other " ++ floatToString x ++ ", " ++ floatToString y)
1036+ ("expected " ++ floatToString expected ++ ", found " ++ floatToString found)
989− (abs (x - y) < 1)
1037+ (abs (expected - found) < 1)
990
1038
991
1039
992floatToString : Float -> String
1040floatToString : Float -> String
@@ -1000,6 +1048,7 @@ centerY =
1000 Testable.LabeledTest
1048 Testable.LabeledTest
1001 { label = "centerY"
1049 { label = "centerY"
1002 , attr = Element.centerY
1050 , attr = Element.centerY
1051+ , id = Testable.NoId
1003 , test =
1052 , test =
1004 \found ->
1053 \found ->
1005 let
1054 let
@@ -1014,8 +1063,9 @@ centerY =
1014
1063
1015 else if List.length found.siblings == 0 then
1064 else if List.length found.siblings == 0 then
1016 [ expectRoundedEquality
1065 [ expectRoundedEquality
1017− selfCenter
1066+ { found = selfCenter
1018− parentCenter
1067+ , expected = parentCenter
1068+ }
1019 ]
1069 ]
1020
1070
1021 else
1071 else
@@ -1050,12 +1100,17 @@ centerY =
1050 )
1100 )
1051 in
1101 in
1052 [ expectRoundedEquality
1102 [ expectRoundedEquality
1053− selfCenter
1103+ { found = selfCenter
1054− expectedCenter
1104+ , expected = expectedCenter
1105+ }
1055 ]
1106 ]
1056
1107
1057 _ ->
1108 _ ->
1058− [ expectRoundedEquality selfCenter parentCenter ]
1109+ [ expectRoundedEquality
1110+ { found = selfCenter
1111+ , expected = parentCenter
1112+ }
1113+ ]
1059 }
1114 }
1060
1115
1061
1116
@@ -1068,7 +1123,11 @@ above element =
1068 , label = "above"
1123 , label = "above"
1069 , test =
1124 , test =
1070 \found ->
1125 \found ->
1071− [ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top ]
1126+ [ expectRoundedEquality
1127+ { found = found.self.bbox.bottom
1128+ , expected = found.parent.bbox.top
1129+ }
1130+ ]
1072 }
1131 }
1073
1132
1074
1133
@@ -1081,7 +1140,11 @@ below element =
1081 , label = "below"
1140 , label = "below"
1082 , test =
1141 , test =
1083 \found ->
1142 \found ->
1084− [ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom ]
1143+ [ expectRoundedEquality
1144+ { found = found.self.bbox.top
1145+ , expected = found.parent.bbox.bottom
1146+ }
1147+ ]
1085 }
1148 }
1086
1149
1087
1150
@@ -1094,7 +1157,11 @@ onRight element =
1094 , label = "onRight"
1157 , label = "onRight"
1095 , test =
1158 , test =
1096 \found ->
1159 \found ->
1097− [ expectRoundedEquality found.self.bbox.left found.parent.bbox.right ]
1160+ [ expectRoundedEquality
1161+ { found = found.self.bbox.left
1162+ , expected = found.parent.bbox.right
1163+ }
1164+ ]
1098 }
1165 }
1099
1166
1100
1167
@@ -1107,7 +1174,11 @@ onLeft element =
1107 , label = "onLeft"
1174 , label = "onLeft"
1108 , test =
1175 , test =
1109 \found ->
1176 \found ->
1110− [ expectRoundedEquality found.self.bbox.right found.parent.bbox.left ]
1177+ [ expectRoundedEquality
1178+ { found = found.self.bbox.right
1179+ , expected = found.parent.bbox.left
1180+ }
1181+ ]
1111 }
1182 }
1112
1183
1113
1184
@@ -1173,3 +1244,85 @@ behindContent element =
1173 \found ->
1244 \found ->
1174 [ withinHelper found ]
1245 [ withinHelper found ]
1175 }
1246 }
1247+
1248+
1249+
1250+{- Implicit width/height calcualtions -}
1251+
1252+
1253+implicitWidthHeightShrink attrs =
1254+ let
1255+ withImplicits =
1256+ implicitTest (widthHelper Nothing Nothing Shrink)
1257+ :: implicitTest (heightHelper Nothing Nothing Shrink)
1258+ :: attrs
1259+ in
1260+ skipOverridden withImplicits
1261+
1262+
1263+attrId attr =
1264+ case attr of
1265+ Testable.LabeledTest details ->
1266+ details.id
1267+
1268+ Testable.AttrTest details ->
1269+ details.id
1270+
1271+ _ ->
1272+ Testable.NoId
1273+
1274+
1275+skipOverridden ls =
1276+ List.foldr
1277+ (\attr ( found, caught ) ->
1278+ let
1279+ ( skip, has ) =
1280+ case attrId attr of
1281+ Testable.NoId ->
1282+ ( False, found )
1283+
1284+ Testable.IsWidth ->
1285+ ( found.hasWidth
1286+ , { hasWidth = True
1287+ , hasHeight = found.hasHeight
1288+ }
1289+ )
1290+
1291+ Testable.IsHeight ->
1292+ ( found.hasHeight
1293+ , { hasWidth = found.hasWidth
1294+ , hasHeight = True
1295+ }
1296+ )
1297+ in
1298+ ( has
1299+ , if skip then
1300+ caught
1301+
1302+ else
1303+ attr :: caught
1304+ )
1305+ )
1306+ ( { hasWidth = False
1307+ , hasHeight = False
1308+ }
1309+ , []
1310+ )
1311+ ls
1312+ |> Tuple.second
1313+ |> List.reverse
1314+
1315+
1316+{-| This is taking a normal test and rmoving its ability to attach a real `Element` attribute.
1317+-}
1318+implicitTest attr =
1319+ case attr of
1320+ Testable.LabeledTest details ->
1321+ Testable.AttrTest
1322+ { test = details.test
1323+ , label = "Implicit -> " ++ details.label
1324+ , id = details.id
1325+ }
1326+
1327+ otherwise ->
1328+ otherwise
tests-rendering/src/Testable/Element/Background.elm+2−1
@@ -13,6 +13,7 @@ color clr =
13 Testable.LabeledTest
13 Testable.LabeledTest
14 { label = "background color"
14 { label = "background color"
15 , attr = Background.color clr
15 , attr = Background.color clr
16+ , id = Testable.NoId
16 , test =
17 , test =
17 \context ->
18 \context ->
18 let
19 let
@@ -21,7 +22,7 @@ color clr =
21 |> Dict.get "background-color"
22 |> Dict.get "background-color"
22 |> Maybe.withDefault "notfound"
23 |> Maybe.withDefault "notfound"
23 in
24 in
24− [ Testable.true ("expected: " ++ (Testable.formatColor clr ++ ", found:" ++ selfBackgroundColor))
25+ [ Testable.true ("expected " ++ (Testable.formatColor clr ++ ", found " ++ selfBackgroundColor))
25 (Testable.compareFormattedColor clr selfBackgroundColor)
26 (Testable.compareFormattedColor clr selfBackgroundColor)
26 ]
27 ]
27 }
28 }
tests-rendering/src/Testable/Element/Font.elm+2−1
@@ -5,7 +5,6 @@ module Testable.Element.Font exposing (color)
5import Dict
5import Dict
6import Element exposing (Color)
6import Element exposing (Color)
7import Element.Font as Font
7import Element.Font as Font
8−import Expect
9import Testable
8import Testable
10
9
11
10
@@ -14,6 +13,7 @@ color clr =
14 Testable.LabeledTest
13 Testable.LabeledTest
15 { label = "font color-" ++ Testable.formatColor clr
14 { label = "font color-" ++ Testable.formatColor clr
16 , attr = Font.color clr
15 , attr = Font.color clr
16+ , id = Testable.NoId
17 , test =
17 , test =
18 \context ->
18 \context ->
19 let
19 let
@@ -33,6 +33,7 @@ size i =
33 Testable.LabeledTest
33 Testable.LabeledTest
34 { label = "font size-" ++ String.fromInt i
34 { label = "font size-" ++ String.fromInt i
35 , attr = Font.size i
35 , attr = Font.size i
36+ , id = Testable.NoId
36 , test =
37 , test =
37 \context ->
38 \context ->
38 let
39 let
tests-rendering/src/Testable/Runner.elm+2−3
@@ -258,6 +258,7 @@ view model =
258 , Border.dashed
258 , Border.dashed
259 , Border.width 2
259 , Border.width 2
260 , Border.color palette.lightGrey
260 , Border.color palette.lightGrey
261+ , Font.size 20
261 , Element.inFront
262 , Element.inFront
262 (Element.el
263 (Element.el
263 [ Font.size 14
264 [ Font.size 14
@@ -342,11 +343,9 @@ viewResult testable =
342 , Element.spacing 16
343 , Element.spacing 16
343 ]
344 ]
344 [ Element.el [ Font.size 24 ] (Element.text testable.label)
345 [ Element.el [ Font.size 24 ] (Element.text testable.label)
345− , Element.column [ Element.alignLeft, Element.spacing 20 ]
346− (List.map viewLayoutTest failing)
347 , Element.column
346 , Element.column
348 [ Element.alignLeft, Element.spacing 16 ]
347 [ Element.alignLeft, Element.spacing 16 ]
349− (passing
348+ (testable.results
350 |> groupBy .elementDomId
349 |> groupBy .elementDomId
351 |> List.map viewLayoutTestGroup
350 |> List.map viewLayoutTestGroup
352 )
351 )