@@ -10,6 +10,7 @@ module Testable.Element exposing
1010 , below
1111 , centerX
1212 , centerY
13+ , clip
1314 , column
1415 , el
1516 , expectRoundedEquality
@@ -37,6 +38,9 @@ module Testable.Element exposing
3738 , rgb
3839 , rgba
3940 , row
41+ , scrollbarX
42+ , scrollbarY
43+ , scrollbars
4044 , shrink
4145 , spacing
4246 , text
@@ -132,8 +136,31 @@ link :
132136 }
133137 -> Testable.Element msg
134138link attrs details =
135− -- TODO: this is not actually a link element!!
136− Testable.El (implicitWidthHeightShrink attrs) details.label
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
137164
138165
139166{-| Old labeling mechanism that i removed to hastily
@@ -307,6 +334,11 @@ paddingXY x y =
307334 }
308335
309336
337+listIf ls =
338+ List.filter Tuple.first ls
339+ |> List.map Tuple.second
340+
341+
310342widthHelper maybeMin maybeMax len =
311343 let
312344 addMin l =
@@ -465,12 +497,31 @@ widthHelper maybeMin maybeMax len =
465497 totalChildren + horizontalPadding
466498
467499 expectedLines =
468− ceiling (totalCalculatedWidth / context.self.bbox.width)
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
469513 in
470− [ Testable.rounded "text wrapping, checking height"
471− { expected = toFloat (expectedLines * 22)
472− , found = context.self.bbox.height
473− }
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+ )
474525 ]
475526
476527 _ ->
@@ -504,23 +555,50 @@ widthHelper maybeMin maybeMax len =
504555
505556 horizontalPadding =
506557 context.self.bbox.padding.left + context.self.bbox.padding.right
507−
508− _ =
509− Debug.log "widths"
510− { children =
511− context.children
512− |> List.map childWidth
513− , text = List.map .width context.self.textMetrics
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
514565 }
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
584+
585+ horizontalPadding =
586+ context.self.bbox.padding.left + context.self.bbox.padding.right
515587 in
516− [ Testable.rounded "equals children"
517− { expected = totalChildren + horizontalPadding
518− , found = context.self.bbox.width
519− }
520− , Testable.lessThanOrEqual "not larger than parent"
521− context.self.bbox.width
522− context.parent.bbox.width
523− ]
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
594+ }
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+ ]
524602
525603 Testable.Row rowAttrs _ ->
526604 -- width of row is the sum of all children widths
@@ -544,14 +622,19 @@ widthHelper maybeMin maybeMax len =
544622 totalSpacing =
545623 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
546624 in
547− [ expectRoundedEquality
548− { expected = totalChildren + horizontalPadding + totalSpacing
549− , found = context.self.bbox.width
550− }
551− , Testable.lessThanOrEqual "not larger than parent"
552− context.self.bbox.width
553− context.parent.bbox.width
554− ]
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+ ]
555638
556639 Testable.Column _ _ ->
557640 -- The width of the column is the width of the widest child.
@@ -575,14 +658,19 @@ widthHelper maybeMin maybeMax len =
575658 |> List.map childWidth
576659 |> List.append textChildren
577660 in
578− [ expectRoundedEquality
579− { expected = Maybe.withDefault 0 (List.maximum allChildren)
580− , found = context.self.bbox.width
581− }
582− , Testable.lessThanOrEqual "not larger than parent"
583− context.self.bbox.width
584− context.parent.bbox.width
585− ]
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+ ]
586674
587675 Testable.TextColumn _ _ ->
588676 -- The width of the column is the width of the widest child.
@@ -606,14 +694,19 @@ widthHelper maybeMin maybeMax len =
606694 |> List.map childWidth
607695 |> List.append textChildren
608696 in
609− [ expectRoundedEquality
610− { expected = Maybe.withDefault 0 (List.maximum allChildren)
611− , found = context.self.bbox.width
612− }
613− , Testable.lessThanOrEqual "not larger than parent"
614− context.self.bbox.width
615− context.parent.bbox.width
616− ]
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+ ]
617710
618711 Testable.Paragraph _ _ ->
619712 -- This should be the size it's text,
@@ -631,14 +724,19 @@ widthHelper maybeMin maybeMax len =
631724 horizontalPadding =
632725 context.self.bbox.padding.left + context.self.bbox.padding.right
633726 in
634− [ expectRoundedEquality
635− { expected = totalChildren + horizontalPadding
636− , found = context.self.bbox.width
637− }
638− , Testable.lessThanOrEqual "not larger than parent"
639− context.self.bbox.width
640− context.parent.bbox.width
641− ]
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+ ]
642740
643741 Testable.Text _ ->
644742 []
@@ -792,20 +890,45 @@ heightHelper maybeMin maybeMax len =
792890 childHeight child =
793891 child.bbox.height
794892 in
795− [ if List.isEmpty context.children then
893+ if List.isEmpty context.children then
796894 -- context.self.textMetrics
797895 -- |> List.map Testable.textHeight
798896 -- |> List.sum
799897 -- TODO: apparently the font metrics we have are for the literal characters rendered
800898 -- not for the font itself.
801− -- so for now, we are stubbing this in as 20, which is the default font size + line height.
802− Testable.rounded "expected multiple of 20"
803− { expected = context.self.bbox.height
804− , found = toFloat (List.length context.self.textMetrics * 20)
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
805910 }
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+ ]
806929
807− else
808− expectRoundedEquality
930+ else
931+ [ expectRoundedEquality
809932 { expected =
810933 context.children
811934 |> List.map childHeight
@@ -813,28 +936,26 @@ heightHelper maybeMin maybeMax len =
813936 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
814937 , found = context.self.bbox.height
815938 }
816− , Testable.lessThanOrEqual "not larger than parent"
817− context.self.bbox.height
818− context.parent.bbox.height
819− ]
939+ , Testable.lessThanOrEqual "not larger than parent"
940+ context.self.bbox.height
941+ context.parent.bbox.height
942+ ]
820943
821944 Testable.Row _ _ ->
822945 let
823946 childHeight child =
824947 child.bbox.height
825948 in
826− [ if List.isEmpty context.children then
949+ if List.isEmpty context.children then
827950 -- context.self.textMetrics
828951 -- |> List.map Testable.textHeight
829952 -- |> List.sum
830953 -- TODO: apparently the font metrics we have are for the literal characters rendered
831954 -- not for the font itself.
832− -- so for now, we are stubbing this in as 20, which is the default font size.
833− Testable.true "expected multiple of 20"
834− ((round context.self.bbox.height |> modBy 20) == 0)
955+ [ Testable.todo "calculate height from actual text metrics" ]
835956
836− else
837− expectRoundedEquality
957+ else
958+ [ expectRoundedEquality
838959 { expected =
839960 context.children
840961 |> List.map childHeight
@@ -843,10 +964,10 @@ heightHelper maybeMin maybeMax len =
843964 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
844965 , found = context.self.bbox.height
845966 }
846− , Testable.lessThanOrEqual "not larger than parent"
847− context.self.bbox.height
848− context.parent.bbox.height
849− ]
967+ , Testable.lessThanOrEqual "not larger than parent"
968+ context.self.bbox.height
969+ context.parent.bbox.height
970+ ]
850971
851972 Testable.Column colAttrs _ ->
852973 let
@@ -878,16 +999,10 @@ heightHelper maybeMin maybeMax len =
878999 ]
8791000
8801001 Testable.TextColumn _ _ ->
881− [ Testable.lessThanOrEqual "not larger than parent"
882− context.self.bbox.height
883− context.parent.bbox.height
884− ]
1002+ []
8851003
8861004 Testable.Paragraph _ _ ->
887− [ Testable.lessThanOrEqual "not larger than parent"
888− context.self.bbox.height
889− context.parent.bbox.height
890− ]
1005+ []
8911006
8921007 Testable.Text _ ->
8931008 []