@@ -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 )
@@ -64,21 +58,17 @@ In order to run the test:
6458
6559import Dict
6660import Element
61+import Expect
6762import Html.Attributes
6863import 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+ [ ( "Open Case", elem )
71+ ]
8272
8373
8474text : String -> Testable.Element msg
@@ -87,18 +77,18 @@ text =
8777
8878
8979el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
90−el attrs =
91− Testable.El (implicitWidthHeightShrink attrs)
80+el =
81+ Testable.El
9282
9383
9484row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
95−row attrs =
96− Testable.Row (implicitWidthHeightShrink attrs)
85+row =
86+ Testable.Row
9787
9888
9989column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
100−column attrs =
101− Testable.Column (implicitWidthHeightShrink attrs)
90+column =
91+ Testable.Column
10292
10393
10494none : Testable.Element msg
@@ -107,60 +97,13 @@ none =
10797
10898
10999paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
110−paragraph 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+paragraph =
101+ Testable.Paragraph
118102
119103
120104textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
121−textColumn 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+textColumn =
106+ Testable.TextColumn
164107
165108
166109{-| Old labeling mechanism that i removed to hastily
@@ -239,7 +182,6 @@ transparent on =
239182 else
240183 "opaque"
241184 , attr = Element.transparent on
242− , id = Testable.NoId
243185 , test =
244186 \context ->
245187 let
@@ -262,9 +204,9 @@ transparent on =
262204{-| -}
263205isVisible : Testable.Attr msg
264206isVisible =
265− Testable.AttrTest
207+ Testable.LabeledTest
266208 { label = "is-visible"
267− , id = Testable.NoId
209+ , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
268210 , test =
269211 \context ->
270212 [ Testable.equal context.self.isVisible True ]
@@ -277,7 +219,6 @@ alpha a =
277219 Testable.LabeledTest
278220 { label = "alpha-" ++ String.fromFloat a
279221 , attr = Element.alpha a
280− , id = Testable.NoId
281222 , test =
282223 \context ->
283224 let
@@ -296,7 +237,6 @@ padding pad =
296237 Testable.LabeledTest
297238 { label = "padding " ++ String.fromInt pad
298239 , attr = Element.padding pad
299− , id = Testable.NoId
300240 , test =
301241 \found ->
302242 [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
@@ -317,7 +257,6 @@ paddingXY x y =
317257 Testable.LabeledTest
318258 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
319259 , attr = Element.paddingXY x y
320− , id = Testable.NoId
321260 , test =
322261 \found ->
323262 [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
@@ -334,11 +273,6 @@ paddingXY x y =
334273 }
335274
336275
337−listIf ls =
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
340−
341−
342276widthHelper maybeMin maybeMax len =
343277 let
344278 addMin l =
@@ -398,7 +332,6 @@ widthHelper maybeMin maybeMax len =
398332 -- Pixel values should ignore min and max?
399333 Testable.LabeledTest
400334 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
401− , id = Testable.IsWidth
402335 , attr =
403336 Element.width
404337 (Element.px val
@@ -407,10 +340,7 @@ widthHelper maybeMin maybeMax len =
407340 )
408341 , test =
409342 \found ->
410− [ expectRoundedEquality
411− { expected = toFloat val
412− , found = found.self.bbox.width
413− }
343+ [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
414344 , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
415345 ]
416346 }
@@ -423,7 +353,6 @@ widthHelper maybeMin maybeMax len =
423353
424354 else
425355 "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
426− , id = Testable.IsWidth
427356 , attr =
428357 Element.width
429358 (Element.fillPortion portion
@@ -432,7 +361,7 @@ widthHelper maybeMin maybeMax len =
432361 )
433362 , test =
434363 \context ->
435− if List.member context.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
364+ if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
436365 [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
437366
438367 else
@@ -440,93 +369,33 @@ widthHelper maybeMin maybeMax len =
440369 parentAvailableWidth =
441370 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
442371 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− ]
451−
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− ]
526−
527− _ ->
528− []
529− ]
372+ [ case context.location of
373+ Testable.IsNearby _ ->
374+ Testable.true "Nearby Element has fill width"
375+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
376+ || minMaxTest (floor context.self.bbox.width)
377+ )
378+
379+ Testable.InColumn ->
380+ Testable.true "Element within column has fill width"
381+ ((floor parentAvailableWidth == floor context.self.bbox.width)
382+ || minMaxTest (floor context.self.bbox.width)
383+ )
384+
385+ Testable.InEl ->
386+ Testable.true "Element within element has fill width" <|
387+ (floor parentAvailableWidth == floor context.self.bbox.width)
388+ || minMaxTest (floor context.self.bbox.width)
389+
390+ _ ->
391+ let
392+ spacePerPortion =
393+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
394+ in
395+ Testable.true "element has fill width" <|
396+ (floor spacePerPortion == floor context.self.bbox.width)
397+ || minMaxTest (floor context.self.bbox.width)
398+ ]
530399 }
531400
532401 Shrink ->
@@ -538,211 +407,33 @@ widthHelper maybeMin maybeMax len =
538407 |> addMin
539408 |> addMax
540409 )
541− , id = Testable.IsWidth
542410 , test =
543411 \context ->
544− case context.selfElement of
545− Testable.El _ _ ->
546− let
547− childWidth child =
548− child.bbox.width
549−
550− totalChildren =
551− context.children
552− |> List.map childWidth
553− |> List.append (List.map .width context.self.textMetrics)
554− |> List.sum
555−
556− horizontalPadding =
557− context.self.bbox.padding.left + context.self.bbox.padding.right
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
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− ]
602−
603− Testable.Row rowAttrs _ ->
604− -- width of row is the sum of all children widths
605− -- both text elements and others.
606− let
607− childWidth child =
608− child.bbox.width
609−
610− totalChildren =
611− context.children
612− |> List.map childWidth
613− |> List.append (List.map .width context.self.textMetrics)
614− |> List.sum
615−
616− horizontalPadding =
617− context.self.bbox.padding.left + context.self.bbox.padding.right
618−
619− spacingAmount =
620− Testable.getSpacingFromAttributes rowAttrs
621−
622− totalSpacing =
623− toFloat spacingAmount * (toFloat (List.length context.children) - 1)
624− 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− ]
638−
639− Testable.Column _ _ ->
640− -- The width of the column is the width of the widest child.
641− let
642− childWidth child =
643− child.bbox.width
644− + context.self.bbox.padding.left
645− + context.self.bbox.padding.right
646−
647− textChildren =
648− List.map
649− (\txt ->
650− txt.width
651− + context.self.bbox.padding.left
652− + context.self.bbox.padding.right
653− )
654− context.self.textMetrics
655−
656− allChildren =
657− context.children
658− |> List.map childWidth
659− |> List.append textChildren
660− 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− ]
674−
675− 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− ]
412+ let
413+ childWidth child =
414+ -- TODO: add margin values to widths
415+ child.bbox.width
416+
417+ totalChildren =
418+ context.children
419+ |> List.map childWidth
420+ |> List.sum
421+
422+ horizontalPadding =
423+ context.self.bbox.padding.left + context.self.bbox.padding.right
424+
425+ spacingValue =
426+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
427+ in
428+ if totalChildren == 0 then
429+ -- 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.
431+ [ expectRoundedEquality context.self.bbox.width context.self.bbox.width ]
710432
711− Testable.Paragraph _ _ ->
712− -- This should be the size it's text,
713− -- unless it takes up all available space, in which case it should wrap.
714− let
715− childWidth child =
716− child.bbox.width
717−
718− totalChildren =
719− context.children
720− |> List.map childWidth
721− |> List.append (List.map .width context.self.textMetrics)
722− |> List.sum
723−
724− horizontalPadding =
725− context.self.bbox.padding.left + context.self.bbox.padding.right
726− 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− ]
740−
741− Testable.Text _ ->
742− []
743−
744− Testable.Empty ->
745− []
433+ else
434+ -- 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.
436+ [ expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width ]
746437 }
747438
748439
@@ -811,13 +502,10 @@ heightHelper maybeMin maybeMax len =
811502 |> addMin
812503 |> addMax
813504 )
814− , id = Testable.IsHeight
815505 , test =
816506 \found ->
817− [ expectRoundedEquality
818− { expected = toFloat val
819− , found = found.self.bbox.height
820− }
507+ [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
508+ (floor found.self.bbox.height == val)
821509 , Testable.true "min/max holds true"
822510 (minMaxTest (floor found.self.bbox.height))
823511 ]
@@ -832,10 +520,9 @@ heightHelper maybeMin maybeMax len =
832520 |> addMin
833521 |> addMax
834522 )
835− , id = Testable.IsHeight
836523 , test =
837524 \context ->
838− [ if List.member context.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
525+ [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
839526 Testable.true "height fill doesn't apply to above/below elements" True
840527
841528 else
@@ -843,7 +530,7 @@ heightHelper maybeMin maybeMax len =
843530 parentAvailableHeight =
844531 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
845532 in
846− case context.parentLayout of
533+ case context.location of
847534 Testable.IsNearby _ ->
848535 Testable.true "Nearby Element has fill height"
849536 ((floor context.parent.bbox.height == floor context.self.bbox.height)
@@ -881,134 +568,33 @@ heightHelper maybeMin maybeMax len =
881568 |> addMin
882569 |> addMax
883570 )
884− , id = Testable.IsHeight
885571 , test =
886572 \context ->
887− case context.selfElement of
888− Testable.El _ _ ->
889− let
890− childHeight child =
891− 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− ]
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
910− }
911− , Testable.lessThanOrEqual "not larger than parent"
912− context.self.bbox.height
913− context.parent.bbox.height
914− ]
573+ let
574+ childWidth child =
575+ -- TODO: add margin values to heights
576+ child.bbox.height
577+
578+ totalChildren =
579+ context.children
580+ |> List.map childWidth
581+ |> List.sum
582+
583+ verticalPadding =
584+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
585+
586+ spacingValue =
587+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
588+ in
589+ if totalChildren == 0 then
590+ -- 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.
592+ [ expectRoundedEquality context.self.bbox.height context.self.bbox.height ]
915593
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− ]
943−
944− Testable.Row _ _ ->
945− let
946− childHeight child =
947− child.bbox.height
948− 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− ]
971−
972− Testable.Column colAttrs _ ->
973− let
974− childHeight child =
975− child.bbox.height
976−
977− totalChildren =
978− context.children
979− |> List.map childHeight
980− |> List.append (List.map Testable.textHeight context.self.textMetrics)
981− |> List.sum
982−
983− verticalPadding =
984− context.self.bbox.padding.top + context.self.bbox.padding.bottom
985−
986− spacingAmount =
987− Testable.getSpacingFromAttributes colAttrs
988−
989− totalSpacing =
990− toFloat spacingAmount * (toFloat (List.length context.children) - 1)
991− in
992− [ expectRoundedEquality
993− { expected = totalChildren + verticalPadding + totalSpacing
994− , found = context.self.bbox.height
995− }
996− , Testable.lessThanOrEqual "not larger than parent"
997− context.self.bbox.height
998− context.parent.bbox.height
999− ]
1000−
1001− Testable.TextColumn _ _ ->
1002− []
1003−
1004− Testable.Paragraph _ _ ->
1005− []
1006−
1007− Testable.Text _ ->
1008− []
1009−
1010− Testable.Empty ->
1011− []
594+ else
595+ -- 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.
597+ [ expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height ]
1012598 }
1013599
1014600
@@ -1029,7 +615,6 @@ spacing space =
1029615 , Testable.LabeledTest
1030616 { label = "spacing: " ++ String.fromInt space
1031617 , attr = Element.spacing space
1032− , id = Testable.NoId
1033618 , test =
1034619 \found ->
1035620 let
@@ -1108,14 +693,13 @@ alignLeft =
1108693 Testable.LabeledTest
1109694 { label = "alignLeft"
1110695 , attr = Element.alignLeft
1111− , id = Testable.NoId
1112696 , test =
1113697 \found ->
1114− [ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
698+ [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1115699 Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
1116700
1117701 else if
1118− List.member found.parentLayout
702+ List.member found.location
1119703 [ Testable.IsNearby Testable.InFront
1120704 , Testable.IsNearby Testable.Behind
1121705 , Testable.IsNearby Testable.Above
@@ -1123,18 +707,16 @@ alignLeft =
1123707 ]
1124708 then
1125709 expectRoundedEquality
1126− { found = found.self.bbox.left
1127− , expected = found.parent.bbox.left
1128− }
710+ found.self.bbox.left
711+ found.parent.bbox.left
1129712
1130713 else if List.length found.siblings == 0 then
1131714 expectRoundedEquality
1132− { found = found.self.bbox.left
1133− , expected = found.parent.bbox.left + found.parent.bbox.padding.left
1134− }
715+ found.self.bbox.left
716+ (found.parent.bbox.left + found.parent.bbox.padding.left)
1135717
1136718 else
1137− case found.parentLayout of
719+ case found.location of
1138720 Testable.InRow ->
1139721 let
1140722 siblingsOnLeft =
@@ -1149,15 +731,13 @@ alignLeft =
1149731 |> List.sum
1150732 in
1151733 expectRoundedEquality
1152− { found = found.self.bbox.left
1153− , expected = found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings)
1154− }
734+ found.self.bbox.left
735+ (found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings))
1155736
1156737 _ ->
1157738 expectRoundedEquality
1158− { found = found.self.bbox.left
1159− , expected = found.parent.bbox.left + found.parent.bbox.padding.left
1160− }
739+ found.self.bbox.left
740+ (found.parent.bbox.left + found.parent.bbox.padding.left)
1161741 ]
1162742 }
1163743
@@ -1168,7 +748,6 @@ centerX =
1168748 Testable.LabeledTest
1169749 { label = "centerX"
1170750 , attr = Element.centerX
1171− , id = Testable.NoId
1172751 , test =
1173752 \found ->
1174753 let
@@ -1180,18 +759,17 @@ centerX =
1180759 parentCenter =
1181760 found.parent.bbox.left + (found.parent.bbox.width / 2)
1182761 in
1183− if List.member found.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
762+ if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
1184763 [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
1185764
1186765 else if List.length found.siblings == 0 then
1187766 [ expectRoundedEquality
1188− { found = selfCenter
1189− , expected = parentCenter
1190− }
767+ selfCenter
768+ parentCenter
1191769 ]
1192770
1193771 else
1194− case found.parentLayout of
772+ case found.location of
1195773 Testable.InRow ->
1196774 let
1197775 siblingsOnLeft =
@@ -1222,17 +800,12 @@ centerX =
1222800 )
1223801 in
1224802 [ expectRoundedEquality
1225− { found = selfCenter
1226− , expected = expectedCenter
1227− }
803+ selfCenter
804+ expectedCenter
1228805 ]
1229806
1230807 _ ->
1231− [ expectRoundedEquality
1232− { found = selfCenter
1233− , expected = parentCenter
1234− }
1235− ]
808+ [ expectRoundedEquality selfCenter parentCenter ]
1236809 }
1237810
1238811
@@ -1242,14 +815,13 @@ alignRight =
1242815 Testable.LabeledTest
1243816 { label = "alignRight"
1244817 , attr = Element.alignRight
1245− , id = Testable.NoId
1246818 , test =
1247819 \found ->
1248− if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
820+ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1249821 [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
1250822
1251823 else if
1252− List.member found.parentLayout
824+ List.member found.location
1253825 [ Testable.IsNearby Testable.InFront
1254826 , Testable.IsNearby Testable.Behind
1255827 , Testable.IsNearby Testable.Above
@@ -1257,20 +829,18 @@ alignRight =
1257829 ]
1258830 then
1259831 [ expectRoundedEquality
1260− { found = found.self.bbox.right
1261− , expected = found.parent.bbox.right
1262− }
832+ found.self.bbox.right
833+ found.parent.bbox.right
1263834 ]
1264835
1265836 else if List.length found.siblings == 0 then
1266837 [ expectRoundedEquality
1267− { found = found.self.bbox.right
1268− , expected = found.parent.bbox.right + found.parent.bbox.padding.right
1269− }
838+ found.self.bbox.right
839+ (found.parent.bbox.right + found.parent.bbox.padding.right)
1270840 ]
1271841
1272842 else
1273− case found.parentLayout of
843+ case found.location of
1274844 Testable.InRow ->
1275845 let
1276846 siblingsOnRight =
@@ -1285,16 +855,14 @@ alignRight =
1285855 |> List.sum
1286856 in
1287857 [ expectRoundedEquality
1288− { found = found.self.bbox.right
1289− , expected = found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings)
1290− }
858+ found.self.bbox.right
859+ (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
1291860 ]
1292861
1293862 _ ->
1294863 [ expectRoundedEquality
1295− { found = found.self.bbox.right
1296− , expected = found.parent.bbox.right + found.parent.bbox.padding.right
1297− }
864+ found.self.bbox.right
865+ (found.parent.bbox.right + found.parent.bbox.padding.right)
1298866 ]
1299867 }
1300868
@@ -1305,14 +873,13 @@ alignTop =
1305873 Testable.LabeledTest
1306874 { label = "alignTop"
1307875 , attr = Element.alignTop
1308− , id = Testable.NoId
1309876 , test =
1310877 \found ->
1311− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
878+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1312879 [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
1313880
1314881 else if
1315− List.member found.parentLayout
882+ List.member found.location
1316883 [ Testable.IsNearby Testable.InFront
1317884 , Testable.IsNearby Testable.Behind
1318885 , Testable.IsNearby Testable.OnRight
@@ -1320,20 +887,18 @@ alignTop =
1320887 ]
1321888 then
1322889 [ expectRoundedEquality
1323− { found = found.self.bbox.top
1324− , expected = found.parent.bbox.top
1325− }
890+ found.self.bbox.top
891+ found.parent.bbox.top
1326892 ]
1327893
1328894 else if List.length found.siblings == 0 then
1329895 [ expectRoundedEquality
1330− { found = found.self.bbox.top
1331− , expected = found.parent.bbox.top + found.parent.bbox.padding.top
1332− }
896+ found.self.bbox.top
897+ (found.parent.bbox.top + found.parent.bbox.padding.top)
1333898 ]
1334899
1335900 else
1336− case found.parentLayout of
901+ case found.location of
1337902 Testable.InColumn ->
1338903 let
1339904 siblingsAbove =
@@ -1348,16 +913,14 @@ alignTop =
1348913 |> List.sum
1349914 in
1350915 [ expectRoundedEquality
1351− { found = found.self.bbox.top
1352− , expected = found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings)
1353− }
916+ found.self.bbox.top
917+ (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
1354918 ]
1355919
1356920 _ ->
1357921 [ expectRoundedEquality
1358− { found = found.self.bbox.top
1359− , expected = found.parent.bbox.top
1360− }
922+ found.self.bbox.top
923+ found.parent.bbox.top
1361924 ]
1362925 }
1363926
@@ -1368,14 +931,13 @@ alignBottom =
1368931 Testable.LabeledTest
1369932 { label = "alignBottom"
1370933 , attr = Element.alignBottom
1371− , id = Testable.NoId
1372934 , test =
1373935 \found ->
1374− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
936+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1375937 [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
1376938
1377939 else if
1378− List.member found.parentLayout
940+ List.member found.location
1379941 [ Testable.IsNearby Testable.InFront
1380942 , Testable.IsNearby Testable.Behind
1381943 , Testable.IsNearby Testable.OnRight
@@ -1383,20 +945,18 @@ alignBottom =
1383945 ]
1384946 then
1385947 [ expectRoundedEquality
1386− { found = found.self.bbox.bottom
1387− , expected = found.parent.bbox.bottom
1388− }
948+ found.self.bbox.bottom
949+ found.parent.bbox.bottom
1389950 ]
1390951
1391952 else if List.length found.siblings == 0 then
1392953 [ expectRoundedEquality
1393− { found = found.self.bbox.bottom
1394− , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
1395− }
954+ found.self.bbox.bottom
955+ (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1396956 ]
1397957
1398958 else
1399− case found.parentLayout of
959+ case found.location of
1400960 Testable.InColumn ->
1401961 let
1402962 siblingsBelow =
@@ -1411,25 +971,22 @@ alignBottom =
1411971 |> List.sum
1412972 in
1413973 [ expectRoundedEquality
1414− { found = found.self.bbox.bottom
1415− , expected = found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings)
1416− }
974+ found.self.bbox.bottom
975+ (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
1417976 ]
1418977
1419978 _ ->
1420979 [ expectRoundedEquality
1421− { found = found.self.bbox.bottom
1422− , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
1423− }
980+ found.self.bbox.bottom
981+ (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1424982 ]
1425983 }
1426984
1427985
1428−expectRoundedEquality : { expected : Float, found : Float } -> Testable.LayoutExpectation
1429−expectRoundedEquality { expected, found } =
986+expectRoundedEquality x y =
1430987 Testable.true
1431− ("expected " ++ floatToString expected ++ ", found " ++ floatToString found)
1432− (abs (expected - found) < 1)
988+ ("within 1 of each other " ++ floatToString x ++ ", " ++ floatToString y)
989+ (abs (x - y) < 1)
1433990
1434991
1435992floatToString : Float -> String
@@ -1443,7 +1000,6 @@ centerY =
14431000 Testable.LabeledTest
14441001 { label = "centerY"
14451002 , attr = Element.centerY
1446− , id = Testable.NoId
14471003 , test =
14481004 \found ->
14491005 let
@@ -1453,18 +1009,17 @@ centerY =
14531009 parentCenter =
14541010 found.parent.bbox.top + (found.parent.bbox.height / 2)
14551011 in
1456− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1012+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
14571013 [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
14581014
14591015 else if List.length found.siblings == 0 then
14601016 [ expectRoundedEquality
1461− { found = selfCenter
1462− , expected = parentCenter
1463− }
1017+ selfCenter
1018+ parentCenter
14641019 ]
14651020
14661021 else
1467− case found.parentLayout of
1022+ case found.location of
14681023 Testable.InColumn ->
14691024 let
14701025 siblingsOnTop =
@@ -1495,17 +1050,12 @@ centerY =
14951050 )
14961051 in
14971052 [ expectRoundedEquality
1498− { found = selfCenter
1499− , expected = expectedCenter
1500− }
1053+ selfCenter
1054+ expectedCenter
15011055 ]
15021056
15031057 _ ->
1504− [ expectRoundedEquality
1505− { found = selfCenter
1506− , expected = parentCenter
1507− }
1508− ]
1058+ [ expectRoundedEquality selfCenter parentCenter ]
15091059 }
15101060
15111061
@@ -1518,11 +1068,7 @@ above element =
15181068 , label = "above"
15191069 , test =
15201070 \found ->
1521− [ expectRoundedEquality
1522− { found = found.self.bbox.bottom
1523− , expected = found.parent.bbox.top
1524− }
1525− ]
1071+ [ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top ]
15261072 }
15271073
15281074
@@ -1535,11 +1081,7 @@ below element =
15351081 , label = "below"
15361082 , test =
15371083 \found ->
1538− [ expectRoundedEquality
1539− { found = found.self.bbox.top
1540− , expected = found.parent.bbox.bottom
1541− }
1542− ]
1084+ [ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom ]
15431085 }
15441086
15451087
@@ -1552,11 +1094,7 @@ onRight element =
15521094 , label = "onRight"
15531095 , test =
15541096 \found ->
1555− [ expectRoundedEquality
1556− { found = found.self.bbox.left
1557− , expected = found.parent.bbox.right
1558− }
1559− ]
1097+ [ expectRoundedEquality found.self.bbox.left found.parent.bbox.right ]
15601098 }
15611099
15621100
@@ -1569,11 +1107,7 @@ onLeft element =
15691107 , label = "onLeft"
15701108 , test =
15711109 \found ->
1572− [ expectRoundedEquality
1573− { found = found.self.bbox.right
1574− , expected = found.parent.bbox.left
1575− }
1576− ]
1110+ [ expectRoundedEquality found.self.bbox.right found.parent.bbox.left ]
15771111 }
15781112
15791113
@@ -1639,85 +1173,3 @@ behindContent element =
16391173 \found ->
16401174 [ withinHelper found ]
16411175 }
1642−
1643−
1644−
1645−{- Implicit width/height calcualtions -}
1646−
1647−
1648−implicitWidthHeightShrink attrs =
1649− let
1650− withImplicits =
1651− implicitTest (widthHelper Nothing Nothing Shrink)
1652− :: implicitTest (heightHelper Nothing Nothing Shrink)
1653− :: attrs
1654− in
1655− skipOverridden withImplicits
1656−
1657−
1658−attrId attr =
1659− case attr of
1660− Testable.LabeledTest details ->
1661− details.id
1662−
1663− Testable.AttrTest details ->
1664− details.id
1665−
1666− _ ->
1667− Testable.NoId
1668−
1669−
1670−skipOverridden ls =
1671− List.foldr
1672− (\attr ( found, caught ) ->
1673− let
1674− ( skip, has ) =
1675− case attrId attr of
1676− Testable.NoId ->
1677− ( False, found )
1678−
1679− Testable.IsWidth ->
1680− ( found.hasWidth
1681− , { hasWidth = True
1682− , hasHeight = found.hasHeight
1683− }
1684− )
1685−
1686− Testable.IsHeight ->
1687− ( found.hasHeight
1688− , { hasWidth = found.hasWidth
1689− , hasHeight = True
1690− }
1691− )
1692− in
1693− ( has
1694− , if skip then
1695− caught
1696−
1697− else
1698− attr :: caught
1699− )
1700− )
1701− ( { hasWidth = False
1702− , hasHeight = False
1703− }
1704− , []
1705− )
1706− ls
1707− |> Tuple.second
1708− |> List.reverse
1709−
1710−
1711−{-| This is taking a normal test and rmoving its ability to attach a real `Element` attribute.
1712−-}
1713−implicitTest attr =
1714− case attr of
1715− Testable.LabeledTest details ->
1716− Testable.AttrTest
1717− { test = details.test
1718− , label = "Implicit -> " ++ details.label
1719− , id = details.id
1720− }
1721−
1722− otherwise ->
1723− otherwise