@@ -10,7 +10,6 @@ module Testable.Element exposing
1010 , below
1111 , centerX
1212 , centerY
13− , clip
1413 , column
1514 , el
1615 , expectRoundedEquality
@@ -38,14 +37,10 @@ module Testable.Element exposing
3837 , rgb
3938 , rgba
4039 , row
41− , scrollbarX
42− , scrollbarY
43− , scrollbars
4440 , shrink
4541 , spacing
4642 , text
4743 , textColumn
48− , toProgram
4944 , transparent
5045 , width
5146 )
@@ -69,16 +64,11 @@ import Testable
6964import Testable.Runner
7065
7166
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
67+layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
8068layout attrs elem =
81− Testable.Runner.testable "Test" elem
69+ Testable.Runner.program
70+ [ ( "Tests Run", elem )
71+ ]
8272
8373
8474text : String -> Testable.Element msg
@@ -136,31 +126,8 @@ link :
136126 }
137127 -> Testable.Element msg
138128link 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
129+ -- TODO: this is not actually a link element!!
130+ Testable.El (implicitWidthHeightShrink attrs) details.label
164131
165132
166133{-| Old labeling mechanism that i removed to hastily
@@ -334,11 +301,6 @@ paddingXY x y =
334301 }
335302
336303
337−listIf ls =
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
340−
341−
342304widthHelper maybeMin maybeMax len =
343305 let
344306 addMin l =
@@ -440,93 +402,36 @@ widthHelper maybeMin maybeMax len =
440402 parentAvailableWidth =
441403 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
442404 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− ]
405+ [ case context.parentLayout of
406+ Testable.IsNearby _ ->
407+ Testable.true "Nearby Element has fill width"
408+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
409+ || minMaxTest (floor context.self.bbox.width)
410+ )
451411
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− ]
412+ Testable.InColumn ->
413+ Testable.true "Element within column has fill width"
414+ ((floor parentAvailableWidth == floor context.self.bbox.width)
415+ || minMaxTest (floor context.self.bbox.width)
416+ )
526417
527− _ ->
528− []
529− ]
418+ Testable.InEl ->
419+ Testable.true "Element within element has fill width" <|
420+ (floor parentAvailableWidth == floor context.self.bbox.width)
421+ || minMaxTest (floor context.self.bbox.width)
422+
423+ _ ->
424+ let
425+ spacePerPortion =
426+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
427+ in
428+ Testable.true "element has fill width" <|
429+ (floor spacePerPortion == floor context.self.bbox.width)
430+ || minMaxTest (floor context.self.bbox.width)
431+ , Testable.lessThanOrEqual "not larger than parent"
432+ context.self.bbox.width
433+ context.parent.bbox.width
434+ ]
530435 }
531436
532437 Shrink ->
@@ -556,49 +461,14 @@ widthHelper maybeMin maybeMax len =
556461 horizontalPadding =
557462 context.self.bbox.padding.left + context.self.bbox.padding.right
558463 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− ]
464+ [ expectRoundedEquality
465+ { expected = totalChildren + horizontalPadding
466+ , found = context.self.bbox.width
467+ }
468+ , Testable.lessThanOrEqual "not larger than parent"
469+ context.self.bbox.width
470+ context.parent.bbox.width
471+ ]
602472
603473 Testable.Row rowAttrs _ ->
604474 -- width of row is the sum of all children widths
@@ -622,19 +492,14 @@ widthHelper maybeMin maybeMax len =
622492 totalSpacing =
623493 toFloat spacingAmount * (toFloat (List.length context.children) - 1)
624494 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− ]
495+ [ expectRoundedEquality
496+ { expected = totalChildren + horizontalPadding + totalSpacing
497+ , found = context.self.bbox.width
498+ }
499+ , Testable.lessThanOrEqual "not larger than parent"
500+ context.self.bbox.width
501+ context.parent.bbox.width
502+ ]
638503
639504 Testable.Column _ _ ->
640505 -- The width of the column is the width of the widest child.
@@ -658,19 +523,14 @@ widthHelper maybeMin maybeMax len =
658523 |> List.map childWidth
659524 |> List.append textChildren
660525 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− ]
526+ [ expectRoundedEquality
527+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
528+ , found = context.self.bbox.width
529+ }
530+ , Testable.lessThanOrEqual "not larger than parent"
531+ context.self.bbox.width
532+ context.parent.bbox.width
533+ ]
674534
675535 Testable.TextColumn _ _ ->
676536 -- The width of the column is the width of the widest child.
@@ -694,19 +554,14 @@ widthHelper maybeMin maybeMax len =
694554 |> List.map childWidth
695555 |> List.append textChildren
696556 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− ]
557+ [ expectRoundedEquality
558+ { expected = Maybe.withDefault 0 (List.maximum allChildren)
559+ , found = context.self.bbox.width
560+ }
561+ , Testable.lessThanOrEqual "not larger than parent"
562+ context.self.bbox.width
563+ context.parent.bbox.width
564+ ]
710565
711566 Testable.Paragraph _ _ ->
712567 -- This should be the size it's text,
@@ -724,19 +579,14 @@ widthHelper maybeMin maybeMax len =
724579 horizontalPadding =
725580 context.self.bbox.padding.left + context.self.bbox.padding.right
726581 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− ]
582+ [ expectRoundedEquality
583+ { expected = totalChildren + horizontalPadding
584+ , found = context.self.bbox.width
585+ }
586+ , Testable.lessThanOrEqual "not larger than parent"
587+ context.self.bbox.width
588+ context.parent.bbox.width
589+ ]
740590
741591 Testable.Text _ ->
742592 []
@@ -890,17 +740,18 @@ heightHelper maybeMin maybeMax len =
890740 childHeight child =
891741 child.bbox.height
892742 in
893− if List.isEmpty context.children then
743+ [ if List.isEmpty context.children then
894744 -- context.self.textMetrics
895745 -- |> List.map Testable.textHeight
896746 -- |> List.sum
897747 -- TODO: apparently the font metrics we have are for the literal characters rendered
898748 -- not for the font itself.
899− [ Testable.todo "calculate height from actual text metrics"
900− ]
749+ -- so for now, we are stubbing this in as 20, which is the default font size.
750+ Testable.true "expected multiple of 20"
751+ ((round context.self.bbox.height |> modBy 20) == 0)
901752
902− else
903− [ expectRoundedEquality
753+ else
754+ expectRoundedEquality
904755 { expected =
905756 context.children
906757 |> List.map childHeight
@@ -908,54 +759,28 @@ heightHelper maybeMin maybeMax len =
908759 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
909760 , found = context.self.bbox.height
910761 }
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− ]
929−
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− ]
762+ , Testable.lessThanOrEqual "not larger than parent"
763+ context.self.bbox.height
764+ context.parent.bbox.height
765+ ]
943766
944767 Testable.Row _ _ ->
945768 let
946769 childHeight child =
947770 child.bbox.height
948771 in
949− if List.isEmpty context.children then
772+ [ if List.isEmpty context.children then
950773 -- context.self.textMetrics
951774 -- |> List.map Testable.textHeight
952775 -- |> List.sum
953776 -- TODO: apparently the font metrics we have are for the literal characters rendered
954777 -- not for the font itself.
955− [ Testable.todo "calculate height from actual text metrics" ]
778+ -- so for now, we are stubbing this in as 20, which is the default font size.
779+ Testable.true "expected multiple of 20"
780+ ((round context.self.bbox.height |> modBy 20) == 0)
956781
957− else
958− [ expectRoundedEquality
782+ else
783+ expectRoundedEquality
959784 { expected =
960785 context.children
961786 |> List.map childHeight
@@ -964,10 +789,10 @@ heightHelper maybeMin maybeMax len =
964789 |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
965790 , found = context.self.bbox.height
966791 }
967− , Testable.lessThanOrEqual "not larger than parent"
968− context.self.bbox.height
969− context.parent.bbox.height
970− ]
792+ , Testable.lessThanOrEqual "not larger than parent"
793+ context.self.bbox.height
794+ context.parent.bbox.height
795+ ]
971796
972797 Testable.Column colAttrs _ ->
973798 let
@@ -999,10 +824,16 @@ heightHelper maybeMin maybeMax len =
999824 ]
1000825
1001826 Testable.TextColumn _ _ ->
1002− []
827+ [ Testable.lessThanOrEqual "not larger than parent"
828+ context.self.bbox.height
829+ context.parent.bbox.height
830+ ]
1003831
1004832 Testable.Paragraph _ _ ->
1005− []
833+ [ Testable.lessThanOrEqual "not larger than parent"
834+ context.self.bbox.height
835+ context.parent.bbox.height
836+ ]
1006837
1007838 Testable.Text _ ->
1008839 []