@@ -10,7 +10,6 @@ module Testable.Element exposing
1010 , below
1111 , centerX
1212 , centerY
13− , clip
1413 , column
1514 , el
1615 , expectRoundedEquality
@@ -21,7 +20,6 @@ module Testable.Element exposing
2120 , isVisible
2221 , label
2322 , layout
24− , link
2523 , maximum
2624 , minimum
2725 , moveDown
@@ -38,14 +36,10 @@ module Testable.Element exposing
3836 , rgb
3937 , rgba
4038 , row
41− , scrollbarX
42− , scrollbarY
43− , scrollbars
4439 , shrink
4540 , spacing
4641 , text
4742 , textColumn
48− , toProgram
4943 , transparent
5044 , width
5145 )
@@ -69,16 +63,11 @@ import Testable
6963import Testable.Runner
7064
7165
72−{-| This is used when we want to run all tests in a test suite instead of one at a time.
73−-}
74−toProgram : Testable.Runner.Testable -> Testable.Runner.TestableProgram
75−toProgram testable =
76− Testable.Runner.program [ testable ]
77−
78−
79−layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.Testable
66+layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
8067layout attrs elem =
81− Testable.Runner.testable "Test" elem
68+ Testable.Runner.program
69+ [ ( "Tests Run", elem )
70+ ]
8271
8372
8473text : String -> Testable.Element msg
@@ -108,59 +97,12 @@ none =
10897
10998paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
11099paragraph attrs =
111− let
112− withImplicits =
113− implicitTest (widthHelper Nothing Nothing (Fill 1))
114− :: implicitTest (heightHelper Nothing Nothing Shrink)
115− :: attrs
116− in
117− Testable.Paragraph (skipOverridden withImplicits)
100+ Testable.Paragraph (implicitWidthHeightShrink attrs)
118101
119102
120103textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
121104textColumn attrs =
122− let
123− withImplicits =
124− implicitTest (widthHelper (Just 500) (Just 750) (Fill 1))
125− :: implicitTest (heightHelper Nothing Nothing Shrink)
126− :: attrs
127− in
128− Testable.TextColumn (skipOverridden withImplicits)
129−
130−
131−link :
132− List (Testable.Attr msg)
133− ->
134− { url : String
135− , label : Testable.Element msg
136− }
137− -> Testable.Element msg
138−link attrs details =
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
105+ Testable.TextColumn (implicitWidthHeightShrink attrs)
164106
165107
166108{-| Old labeling mechanism that i removed to hastily
@@ -334,11 +276,6 @@ paddingXY x y =
334276 }
335277
336278
337−listIf ls =
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
340−
341−
342279widthHelper maybeMin maybeMax len =
343280 let
344281 addMin l =
@@ -407,10 +344,7 @@ widthHelper maybeMin maybeMax len =
407344 )
408345 , test =
409346 \found ->
410− [ expectRoundedEquality
411− { expected = toFloat val
412− , found = found.self.bbox.width
413− }
347+ [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
414348 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
415349 ]
416350 }
@@ -440,93 +374,33 @@ widthHelper maybeMin maybeMax len =
440374 parentAvailableWidth =
441375 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
442376 in
443− List.concat
444− [ case context.parentLayout of
445− Testable.IsNearby _ ->
446− [ Testable.true "Nearby Element has fill width"
447− ((floor context.parent.bbox.width == floor context.self.bbox.width)
448− || minMaxTest (floor context.self.bbox.width)
449− )
450− ]
377+ [ case context.parentLayout of
378+ Testable.IsNearby _ ->
379+ Testable.true "Nearby Element has fill width"
380+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
381+ || minMaxTest (floor context.self.bbox.width)
382+ )
451383
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)
456− )
457− ]
458−
459− Testable.InEl ->
460− [ Testable.true "Element within element has fill width" <|
461− (floor parentAvailableWidth == floor context.self.bbox.width)
462− || minMaxTest (floor context.self.bbox.width)
463− ]
464−
465− _ ->
466− let
467− spacePerPortion =
468− parentAvailableWidth / toFloat (List.length context.siblings + 1)
469− in
470− [ Testable.true "element has fill width" <|
471− (floor spacePerPortion == floor context.self.bbox.width)
472− || minMaxTest (floor context.self.bbox.width)
473− ]
474− , [ Testable.lessThanOrEqual "not larger than parent"
475− context.self.bbox.width
476− context.parent.bbox.width
477− ]
478− , case context.selfElement of
479− Testable.Paragraph _ _ ->
480− -- A paragraph with width fill
481− -- we want to test for correct text wrapping here.
482− --
483− let
484− childWidth child =
485− child.bbox.width
486−
487− totalChildren =
488− context.children
489− |> List.map childWidth
490− |> List.append (List.map .width context.self.textMetrics)
491− |> List.sum
492−
493− horizontalPadding =
494− context.self.bbox.padding.left + context.self.bbox.padding.right
495−
496− totalCalculatedWidth =
497− totalChildren + horizontalPadding
498−
499− expectedLines =
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
513− in
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− )
525− ]
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)
388+ )
526389
527− _ ->
528− []
529− ]
390+ Testable.InEl ->
391+ Testable.true "Element within element has fill width" <|
392+ (floor parentAvailableWidth == floor context.self.bbox.width)
393+ || minMaxTest (floor context.self.bbox.width)
394+
395+ _ ->
396+ let
397+ spacePerPortion =
398+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
399+ in
400+ Testable.true "element has fill width" <|
401+ (floor spacePerPortion == floor context.self.bbox.width)
402+ || minMaxTest (floor context.self.bbox.width)
403+ ]
530404 }
531405
532406 Shrink ->
@@ -556,51 +430,13 @@ widthHelper maybeMin maybeMax len =
556430 horizontalPadding =
557431 context.self.bbox.padding.left + context.self.bbox.padding.right
558432 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
565− }
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
587− in
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− ]
433+ [ expectRoundedEquality
434+ { expected = totalChildren + horizontalPadding
435+ , found = context.self.bbox.width
436+ }
437+ ]
602438
603− Testable.Row rowAttrs _ ->
439+ Testable.Row _ _ ->
604440 -- width of row is the sum of all children widths
605441 -- both text elements and others.
606442 let
@@ -616,25 +452,14 @@ widthHelper maybeMin maybeMax len =
616452 horizontalPadding =
617453 context.self.bbox.padding.left + context.self.bbox.padding.right
618454
619− spacingAmount =
620− Testable.getSpacingFromAttributes rowAttrs
621−
622− totalSpacing =
623− toFloat spacingAmount * (toFloat (List.length context.children) - 1)
455+ spacingValue =
456+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
624457 in
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− ]
458+ [ expectRoundedEquality
459+ { expected = totalChildren + horizontalPadding + spacingValue
460+ , found = context.self.bbox.width
461+ }
462+ ]
638463
639464 Testable.Column _ _ ->
640465 -- The width of the column is the width of the widest child.
@@ -658,55 +483,14 @@ widthHelper maybeMin maybeMax len =
658483 |> List.map childWidth
659484 |> List.append textChildren
660485 in
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− ]
486+ [ expectRoundedEquality
487+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
488+ , found = context.self.bbox.width
489+ }
490+ ]
674491
675492 Testable.TextColumn _ _ ->
676− -- The width of the column is the width of the widest child.
677− let
678− childWidth child =
679− child.bbox.width
680− + context.self.bbox.padding.left
681− + context.self.bbox.padding.right
682−
683− textChildren =
684− List.map
685− (\txt ->
686− txt.width
687− + context.self.bbox.padding.left
688− + context.self.bbox.padding.right
689− )
690− context.self.textMetrics
691−
692− allChildren =
693− context.children
694− |> List.map childWidth
695− |> List.append textChildren
696− in
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− ]
493+ []
710494
711495 Testable.Paragraph _ _ ->
712496 -- This should be the size it's text,
@@ -724,19 +508,11 @@ widthHelper maybeMin maybeMax len =
724508 horizontalPadding =
725509 context.self.bbox.padding.left + context.self.bbox.padding.right
726510 in
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− ]
511+ [ expectRoundedEquality
512+ { expected = totalChildren + horizontalPadding
513+ , found = context.self.bbox.width
514+ }
515+ ]
740516
741517 Testable.Text _ ->
742518 []
@@ -814,10 +590,8 @@ heightHelper maybeMin maybeMax len =
814590 , id = Testable.IsHeight
815591 , test =
816592 \found ->
817− [ expectRoundedEquality
818− { expected = toFloat val
819− , found = found.self.bbox.height
820− }
593+ [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
594+ (floor found.self.bbox.height == val)
821595 , Testable.true "min/max holds true"
822596 (minMaxTest (floor found.self.bbox.height))
823597 ]
@@ -888,88 +662,49 @@ heightHelper maybeMin maybeMax len =
888662 Testable.El _ _ ->
889663 let
890664 childHeight child =
665+ -- TODO: add margin values to heights
891666 child.bbox.height
892− in
893− if List.isEmpty context.children then
894− -- context.self.textMetrics
895− -- |> List.map Testable.textHeight
896− -- |> List.sum
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"
900− ]
901667
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
910− }
911− , Testable.lessThanOrEqual "not larger than parent"
912− context.self.bbox.height
913− context.parent.bbox.height
914− ]
668+ totalChildren =
669+ context.children
670+ |> List.map childHeight
671+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
672+ |> List.sum
915673
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− ]
674+ verticalPadding =
675+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
929676
930− else
931− [ expectRoundedEquality
932− { expected =
933− context.children
934− |> List.map childHeight
935− |> List.sum
936− |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
937− , found = context.self.bbox.height
938− }
939− , Testable.lessThanOrEqual "not larger than parent"
940− context.self.bbox.height
941− context.parent.bbox.height
942− ]
677+ spacingValue =
678+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
679+ in
680+ [ expectRoundedEquality
681+ { expected = totalChildren + verticalPadding + spacingValue
682+ , found = context.self.bbox.height
683+ }
684+ ]
943685
944686 Testable.Row _ _ ->
945687 let
946688 childHeight child =
947689 child.bbox.height
690+
691+ totalChildren =
692+ context.children
693+ |> List.map childHeight
694+ |> List.append (List.map Testable.textHeight context.self.textMetrics)
695+ |> List.maximum
696+ |> Maybe.withDefault 0
697+
698+ verticalPadding =
699+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
948700 in
949− if List.isEmpty context.children then
950− -- context.self.textMetrics
951− -- |> List.map Testable.textHeight
952− -- |> List.sum
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" ]
956−
957− else
958− [ expectRoundedEquality
959− { expected =
960− context.children
961− |> List.map childHeight
962− |> List.maximum
963− |> Maybe.withDefault 0
964− |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
965− , found = context.self.bbox.height
966− }
967− , Testable.lessThanOrEqual "not larger than parent"
968− context.self.bbox.height
969− context.parent.bbox.height
970− ]
701+ [ expectRoundedEquality
702+ { expected = totalChildren + verticalPadding
703+ , found = context.self.bbox.height
704+ }
705+ ]
971706
972− Testable.Column colAttrs _ ->
707+ Testable.Column _ _ ->
973708 let
974709 childHeight child =
975710 child.bbox.height
@@ -983,19 +718,13 @@ heightHelper maybeMin maybeMax len =
983718 verticalPadding =
984719 context.self.bbox.padding.top + context.self.bbox.padding.bottom
985720
986− spacingAmount =
987− Testable.getSpacingFromAttributes colAttrs
988−
989− totalSpacing =
990− toFloat spacingAmount * (toFloat (List.length context.children) - 1)
721+ spacingValue =
722+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
991723 in
992724 [ expectRoundedEquality
993− { expected = totalChildren + verticalPadding + totalSpacing
725+ { expected = totalChildren + verticalPadding + spacingValue
994726 , found = context.self.bbox.height
995727 }
996− , Testable.lessThanOrEqual "not larger than parent"
997− context.self.bbox.height
998− context.parent.bbox.height
999728 ]
1000729
1001730 Testable.TextColumn _ _ ->