@@ -1,4 +1,43 @@
1−module Testable.Element exposing (..)
1+module Testable.Element exposing
15+ , expectRoundedEquality
3{-| This module should mirror the top level `Element` api, with one important distinction.
42{-| This module should mirror the top level `Element` api, with one important distinction.
@@ -15,6 +54,7 @@ In order to run the test:
15import Dict
54import Dict
16import Element
55import Element
17import Expect
56import Expect
57+import Html.Attributes
18import Testable
58import Testable
@@ -100,6 +140,7 @@ transparent on =
100 { label =
140 { label =
101 if on then
141 if on then
102 "transparent"
142 "transparent"
105 , attr = Element.transparent on
146 , attr = Element.transparent on
@@ -114,6 +155,7 @@ transparent on =
115 if on then
156 if on then
@@ -121,6 +163,18 @@ transparent on =
167+isVisible : Testable.Attr msg
169+ Testable.LabeledTest
170+ { label = "is-visible"
171+ , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
174+ Expect.equal context.self.isVisible True
125alpha : Float -> Testable.Attr msg
179alpha : Float -> Testable.Attr msg
@@ -265,6 +319,7 @@ widthHelper maybeMin maybeMax len =
265 \context _ ->
319 \context _ ->
266 if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
320 if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
267 Expect.true "width fill doesn't apply to onright/onleft elements" True
321 Expect.true "width fill doesn't apply to onright/onleft elements" True
270 parentAvailableWidth =
325 parentAvailableWidth =
@@ -329,6 +384,7 @@ widthHelper maybeMin maybeMax len =
329 -- TODO: The issue is that we have a hard time measuring `text` elements
384 -- TODO: The issue is that we have a hard time measuring `text` elements
330 -- So if a element has a text child, then it's width isn't going to show up in the system.
385 -- So if a element has a text child, then it's width isn't going to show up in the system.
331 expectRoundedEquality context.self.bbox.width context.self.bbox.width
386 expectRoundedEquality context.self.bbox.width context.self.bbox.width
333 -- This fails if this element is actually a column
389 -- This fails if this element is actually a column
334 -- So we need to capture what this element is in order to do this calculation.
390 -- So we need to capture what this element is in order to do this calculation.
@@ -422,6 +478,7 @@ heightHelper maybeMin maybeMax len =
422 \context _ ->
478 \context _ ->
423 if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
479 if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
424 Expect.true "height fill doesn't apply to above/below elements" True
480 Expect.true "height fill doesn't apply to above/below elements" True
427 parentAvailableHeight =
484 parentAvailableHeight =
@@ -486,6 +543,7 @@ heightHelper maybeMin maybeMax len =
486 -- TODO: The issue is that we have a hard time measuring `text` elements
543 -- TODO: The issue is that we have a hard time measuring `text` elements
487 -- So if a element has a text child, then it's height isn't going to show up in the system.
544 -- So if a element has a text child, then it's height isn't going to show up in the system.
488 expectRoundedEquality context.self.bbox.height context.self.bbox.height
545 expectRoundedEquality context.self.bbox.height context.self.bbox.height
490 -- This fails if this element is actually a column
548 -- This fails if this element is actually a column
491 -- So we need to capture what this element is in order to do this calculation.
549 -- So we need to capture what this element is in order to do this calculation.
@@ -529,10 +587,12 @@ spacing space =
530 [ if horizontal > 0 then
588 [ if horizontal > 0 then
531 horizontal
589 horizontal
534 , if vertical > 0 then
593 , if vertical > 0 then
@@ -548,6 +608,7 @@ spacing space =
548 (\x wrong ->
608 (\x wrong ->
549 if not (x >= space) then
609 if not (x >= space) then
550 x :: wrong
610 x :: wrong
@@ -588,6 +649,7 @@ alignLeft =
588 \found _ ->
649 \found _ ->
589 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
650 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
590 Expect.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
651 Expect.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
592 List.member found.location
654 List.member found.location
593 [ Testable.IsNearby Testable.InFront
655 [ Testable.IsNearby Testable.InFront
@@ -599,10 +661,12 @@ alignLeft =
599 expectRoundedEquality
661 expectRoundedEquality
600 found.self.bbox.left
662 found.self.bbox.left
601 found.parent.bbox.left
663 found.parent.bbox.left
602 else if List.length found.siblings == 0 then
665 else if List.length found.siblings == 0 then
603 expectRoundedEquality
666 expectRoundedEquality
604 found.self.bbox.left
667 found.self.bbox.left
605 (found.parent.bbox.left + found.parent.bbox.padding.left)
668 (found.parent.bbox.left + found.parent.bbox.padding.left)
607 case found.location of
671 case found.location of
608 Testable.InRow ->
672 Testable.InRow ->
@@ -648,10 +712,12 @@ centerX =
649 if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
713 if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
650 Expect.true "centerX doesn't apply to elements that are onLeft or onRight" True
714 Expect.true "centerX doesn't apply to elements that are onLeft or onRight" True
651 else if List.length found.siblings == 0 then
716 else if List.length found.siblings == 0 then
652 expectRoundedEquality
717 expectRoundedEquality
653 selfCenter
718 selfCenter
654 parentCenter
719 parentCenter
656 case found.location of
722 case found.location of
657 Testable.InRow ->
723 Testable.InRow ->
@@ -702,6 +768,7 @@ alignRight =
702 \found _ ->
768 \found _ ->
703 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
769 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
704 Expect.true "alignRight doesn't apply to elements that are onLeft or onRight" True
770 Expect.true "alignRight doesn't apply to elements that are onLeft or onRight" True
706 List.member found.location
773 List.member found.location
707 [ Testable.IsNearby Testable.InFront
774 [ Testable.IsNearby Testable.InFront
@@ -713,10 +780,12 @@ alignRight =
713 expectRoundedEquality
780 expectRoundedEquality
714 found.self.bbox.right
781 found.self.bbox.right
715 found.parent.bbox.right
782 found.parent.bbox.right
716 else if List.length found.siblings == 0 then
784 else if List.length found.siblings == 0 then
717 expectRoundedEquality
785 expectRoundedEquality
718 found.self.bbox.right
786 found.self.bbox.right
719 (found.parent.bbox.right + found.parent.bbox.padding.right)
787 (found.parent.bbox.right + found.parent.bbox.padding.right)
721 case found.location of
790 case found.location of
722 Testable.InRow ->
791 Testable.InRow ->
@@ -753,6 +822,7 @@ alignTop =
753 \found _ ->
822 \found _ ->
754 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
823 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
755 Expect.true "alignTop doesn't apply to elements that are above or below" True
824 Expect.true "alignTop doesn't apply to elements that are above or below" True
757 List.member found.location
827 List.member found.location
758 [ Testable.IsNearby Testable.InFront
828 [ Testable.IsNearby Testable.InFront
@@ -764,10 +834,12 @@ alignTop =
764 expectRoundedEquality
834 expectRoundedEquality
765 found.self.bbox.top
835 found.self.bbox.top
766 found.parent.bbox.top
836 found.parent.bbox.top
767 else if List.length found.siblings == 0 then
838 else if List.length found.siblings == 0 then
768 expectRoundedEquality
839 expectRoundedEquality
769 found.self.bbox.top
840 found.self.bbox.top
770 (found.parent.bbox.top + found.parent.bbox.padding.top)
841 (found.parent.bbox.top + found.parent.bbox.padding.top)
772 case found.location of
844 case found.location of
773 Testable.InColumn ->
845 Testable.InColumn ->
@@ -804,6 +876,7 @@ alignBottom =
804 \found _ ->
876 \found _ ->
805 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
877 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
806 Expect.true "alignBottom doesn't apply to elements that are above or below" True
878 Expect.true "alignBottom doesn't apply to elements that are above or below" True
808 List.member found.location
881 List.member found.location
809 [ Testable.IsNearby Testable.InFront
882 [ Testable.IsNearby Testable.InFront
@@ -815,10 +888,12 @@ alignBottom =
815 expectRoundedEquality
888 expectRoundedEquality
816 found.self.bbox.bottom
889 found.self.bbox.bottom
817 found.parent.bbox.bottom
890 found.parent.bbox.bottom
818 else if List.length found.siblings == 0 then
892 else if List.length found.siblings == 0 then
819 expectRoundedEquality
893 expectRoundedEquality
820 found.self.bbox.bottom
894 found.self.bbox.bottom
821 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
895 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
823 case found.location of
898 case found.location of
824 Testable.InColumn ->
899 Testable.InColumn ->
@@ -867,10 +942,12 @@ centerY =
868 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
943 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
869 Expect.true "centerY doesn't apply to elements that are above or below" True
944 Expect.true "centerY doesn't apply to elements that are above or below" True
870 else if List.length found.siblings == 0 then
946 else if List.length found.siblings == 0 then
871 expectRoundedEquality
947 expectRoundedEquality
872 selfCenter
948 selfCenter
873 parentCenter
949 parentCenter
875 case found.location of
952 case found.location of
876 Testable.InColumn ->
953 Testable.InColumn ->
@@ -978,6 +1055,7 @@ inFront element =
978 [ (found.self.bbox.right <= found.parent.bbox.right)
1055 [ (found.self.bbox.right <= found.parent.bbox.right)
979 || (found.self.bbox.left >= found.parent.bbox.left)
1056 || (found.self.bbox.left >= found.parent.bbox.left)
982 [ found.self.bbox.right <= found.parent.bbox.right
1060 [ found.self.bbox.right <= found.parent.bbox.right
983 , found.self.bbox.left >= found.parent.bbox.left
1061 , found.self.bbox.left >= found.parent.bbox.left
@@ -988,6 +1066,7 @@ inFront element =
988 [ (found.self.bbox.top >= found.parent.bbox.top)
1066 [ (found.self.bbox.top >= found.parent.bbox.top)
989 || (found.self.bbox.bottom <= found.parent.bbox.bottom)
1067 || (found.self.bbox.bottom <= found.parent.bbox.bottom)
992 [ found.self.bbox.top >= found.parent.bbox.top
1071 [ found.self.bbox.top >= found.parent.bbox.top
993 , found.self.bbox.bottom <= found.parent.bbox.bottom
1072 , found.self.bbox.bottom <= found.parent.bbox.bottom
@@ -1019,6 +1098,7 @@ behindContent element =
1019 [ (found.self.bbox.right <= found.parent.bbox.right)
1098 [ (found.self.bbox.right <= found.parent.bbox.right)
1020 || (found.self.bbox.left >= found.parent.bbox.left)
1099 || (found.self.bbox.left >= found.parent.bbox.left)
1023 [ found.self.bbox.right <= found.parent.bbox.right
1103 [ found.self.bbox.right <= found.parent.bbox.right
1024 , found.self.bbox.left >= found.parent.bbox.left
1104 , found.self.bbox.left >= found.parent.bbox.left
@@ -1029,6 +1109,7 @@ behindContent element =
1029 [ (found.self.bbox.top >= found.parent.bbox.top)
1109 [ (found.self.bbox.top >= found.parent.bbox.top)
1030 || (found.self.bbox.bottom <= found.parent.bbox.bottom)
1110 || (found.self.bbox.bottom <= found.parent.bbox.bottom)
1033 [ found.self.bbox.top >= found.parent.bbox.top
1114 [ found.self.bbox.top >= found.parent.bbox.top
1034 , found.self.bbox.bottom <= found.parent.bbox.bottom
1115 , found.self.bbox.bottom <= found.parent.bbox.bottom