@@ -10,7 +10,6 @@ module Testable.Element exposing
16 , expectRoundedEquality
15 , expectRoundedEquality
@@ -21,12 +20,9 @@ module Testable.Element exposing
21 , isVisible
20 , isVisible
27 , moveDown
25 , moveDown
@@ -38,14 +34,10 @@ module Testable.Element exposing
47 , textColumn
40 , textColumn
49 , transparent
41 , transparent
@@ -64,21 +56,17 @@ In order to run the test:
65import Dict
57import Dict
66import Element
58import Element
67import Html.Attributes
60import Html.Attributes
68import Testable
61import Testable
69import Testable.Runner
62import Testable.Runner
72−{-| This is used when we want to run all tests in a test suite instead of one at a time.
74−toProgram : Testable.Runner.Testable -> Testable.Runner.TestableProgram
76− Testable.Runner.program [ testable ]
79−layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.Testable
65+layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
80layout attrs elem =
66layout attrs elem =
81− Testable.Runner.testable "Test" elem
67+ Testable.Runner.program
68+ [ ( "Open Case", elem )
84text : String -> Testable.Element msg
72text : String -> Testable.Element msg
@@ -87,18 +75,18 @@ text =
89el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
77el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
91− Testable.El (implicitWidthHeightShrink attrs)
79+ Testable.El
94row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
82row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
96− Testable.Row (implicitWidthHeightShrink attrs)
84+ Testable.Row
99column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
87column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
100−column attrs =
88+column =
101− Testable.Column (implicitWidthHeightShrink attrs)
89+ Testable.Column
104none : Testable.Element msg
92none : Testable.Element msg
@@ -107,66 +95,13 @@ none =
109paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
97paragraph : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
110−paragraph attrs =
98+paragraph =
113− implicitTest (widthHelper Nothing Nothing (Fill 1))
114− :: implicitTest (heightHelper Nothing Nothing Shrink)
117− Testable.Paragraph (skipOverridden withImplicits)
99+ Testable.Paragraph
120textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
102textColumn : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
121−textColumn attrs =
103+textColumn =
124− implicitTest (widthHelper (Just 500) (Just 750) (Fill 1))
125− :: implicitTest (heightHelper Nothing Nothing Shrink)
128− Testable.TextColumn (skipOverridden withImplicits)
104+ Testable.TextColumn
132− List (Testable.Attr msg)
135− , label : Testable.Element msg
137− -> Testable.Element msg
139− Testable.Link details.url
140− (implicitWidthHeightShrink attrs)
145− Testable.Attr Element.clip
149−scrollbars : Testable.Attr msg
151− Testable.Attr Element.scrollbars
155−scrollbarY : Testable.Attr msg
157− Testable.Attr Element.scrollbarY
161−scrollbarX : Testable.Attr msg
163− Testable.Attr Element.scrollbarX
166−{-| Old labeling mechanism that i removed to hastily
172moveUp x =
107moveUp x =
@@ -177,14 +112,6 @@ moveDown x =
177 Testable.Attr (Element.moveDown x)
112 Testable.Attr (Element.moveDown x)
181− Testable.Attr (Element.moveRight x)
185− Testable.Attr (Element.moveLeft x)
188type Length
115type Length
190 | Fill Int
117 | Fill Int
@@ -229,6 +156,11 @@ fillPortion =
159+label : String -> Testable.Attr msg
232transparent : Bool -> Testable.Attr msg
164transparent : Bool -> Testable.Attr msg
233transparent on =
165transparent on =
234 Testable.LabeledTest
166 Testable.LabeledTest
@@ -239,9 +171,8 @@ transparent on =
241 , attr = Element.transparent on
173 , attr = Element.transparent on
242− , id = Testable.NoId
244− \context ->
175+ \context _ ->
246 selfTransparency =
177 selfTransparency =
247 context.self.style
178 context.self.style
@@ -255,19 +186,19 @@ transparent on =
258− [ Testable.equal value selfTransparency ]
189+ Expect.equal value selfTransparency
263isVisible : Testable.Attr msg
194isVisible : Testable.Attr msg
264isVisible =
195isVisible =
265− Testable.AttrTest
196+ Testable.LabeledTest
266 { label = "is-visible"
197 { label = "is-visible"
267− , id = Testable.NoId
198+ , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
269− \context ->
200+ \context _ ->
270− [ Testable.equal context.self.isVisible True ]
201+ Expect.equal context.self.isVisible True
@@ -277,16 +208,15 @@ alpha a =
277 Testable.LabeledTest
208 Testable.LabeledTest
278 { label = "alpha-" ++ String.fromFloat a
209 { label = "alpha-" ++ String.fromFloat a
279 , attr = Element.alpha a
210 , attr = Element.alpha a
280− , id = Testable.NoId
282− \context ->
212+ \context _ ->
284 selfTransparency =
214 selfTransparency =
285 context.self.style
215 context.self.style
286 |> Dict.get "opacity"
216 |> Dict.get "opacity"
287 |> Maybe.withDefault "notfound"
217 |> Maybe.withDefault "notfound"
289− [ Testable.equal (String.fromFloat a) selfTransparency ]
219+ Expect.equal (String.fromFloat a) selfTransparency
@@ -296,10 +226,9 @@ padding pad =
296 Testable.LabeledTest
226 Testable.LabeledTest
297 { label = "padding " ++ String.fromInt pad
227 { label = "padding " ++ String.fromInt pad
298 , attr = Element.padding pad
228 , attr = Element.padding pad
299− , id = Testable.NoId
301− \found ->
230+ \found _ ->
302− [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
231+ Expect.true ("Padding " ++ String.fromInt pad ++ " is present")
303 (List.all ((==) pad)
232 (List.all ((==) pad)
304 [ floor found.self.bbox.padding.left
233 [ floor found.self.bbox.padding.left
305 , floor found.self.bbox.padding.right
234 , floor found.self.bbox.padding.right
@@ -307,7 +236,6 @@ padding pad =
307 , floor found.self.bbox.padding.bottom
236 , floor found.self.bbox.padding.bottom
@@ -317,10 +245,9 @@ paddingXY x y =
317 Testable.LabeledTest
245 Testable.LabeledTest
318 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
246 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
319 , attr = Element.paddingXY x y
247 , attr = Element.paddingXY x y
320− , id = Testable.NoId
322− \found ->
249+ \found _ ->
323− [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
250+ Expect.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
324 (List.all ((==) x)
251 (List.all ((==) x)
325 [ floor found.self.bbox.padding.left
252 [ floor found.self.bbox.padding.left
326 , floor found.self.bbox.padding.right
253 , floor found.self.bbox.padding.right
@@ -330,15 +257,9 @@ paddingXY x y =
330 , floor found.self.bbox.padding.bottom
257 , floor found.self.bbox.padding.bottom
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
342widthHelper maybeMin maybeMax len =
263widthHelper maybeMin maybeMax len =
344 addMin l =
265 addMin l =
@@ -398,7 +319,6 @@ widthHelper maybeMin maybeMax len =
398 -- Pixel values should ignore min and max?
319 -- Pixel values should ignore min and max?
399 Testable.LabeledTest
320 Testable.LabeledTest
400 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
321 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
401− , id = Testable.IsWidth
403 Element.width
323 Element.width
404 (Element.px val
324 (Element.px val
@@ -406,24 +326,18 @@ widthHelper maybeMin maybeMax len =
406 |> addMax
326 |> addMax
409− \found ->
329+ \found _ ->
410− [ expectRoundedEquality
330+ Expect.all
411− { expected = toFloat val
331+ [ \_ ->
412− , found = found.self.bbox.width
332+ Expect.true "exact width is exact" (floor found.self.bbox.width == val)
414− , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
333+ , \_ -> Expect.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
418 Fill portion ->
338 Fill portion ->
419 Testable.LabeledTest
339 Testable.LabeledTest
421− if portion == 1 then
422− "width fill" ++ minLabel ++ maxLabel
425− "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
340+ { label = "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
426− , id = Testable.IsWidth
428 Element.width
342 Element.width
429 (Element.fillPortion portion
343 (Element.fillPortion portion
@@ -431,102 +345,41 @@ widthHelper maybeMin maybeMax len =
431 |> addMax
345 |> addMax
434− \context ->
348+ \context _ ->
435− if List.member context.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
349+ if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
436− [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
350+ Expect.true "width fill doesn't apply to onright/onleft elements" True
440 parentAvailableWidth =
354 parentAvailableWidth =
441 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
355 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
444− [ case context.parentLayout of
357+ case context.location of
445− Testable.IsNearby _ ->
358+ Testable.IsNearby _ ->
446− [ Testable.true "Nearby Element has fill width"
359+ Expect.true "Nearby Element has fill width"
447− ((floor context.parent.bbox.width == floor context.self.bbox.width)
360+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
448− || minMaxTest (floor context.self.bbox.width)
361+ || minMaxTest (floor context.self.bbox.width)
452− Testable.InColumn ->
364+ Testable.InColumn ->
453− [ Testable.true "Element within column has fill width"
365+ Expect.true "Element within column has fill width"
454− ((floor parentAvailableWidth == floor context.self.bbox.width)
366+ ((floor parentAvailableWidth == floor context.self.bbox.width)
455− || minMaxTest (floor context.self.bbox.width)
367+ || minMaxTest (floor context.self.bbox.width)
459− Testable.InEl ->
370+ Testable.InEl ->
460− [ Testable.true "Element within element has fill width" <|
371+ Expect.true "Element within element has fill width" <|
461− (floor parentAvailableWidth == floor context.self.bbox.width)
372+ (floor parentAvailableWidth == floor context.self.bbox.width)
462− || minMaxTest (floor context.self.bbox.width)
373+ || minMaxTest (floor context.self.bbox.width)
467− spacePerPortion =
377+ spacePerPortion =
468− parentAvailableWidth / toFloat (List.length context.siblings + 1)
378+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
470− [ Testable.true "element has fill width" <|
380+ Expect.true "element has fill width" <|
471− (floor spacePerPortion == floor context.self.bbox.width)
381+ (floor spacePerPortion == floor context.self.bbox.width)
472− || minMaxTest (floor context.self.bbox.width)
382+ || minMaxTest (floor context.self.bbox.width)
474− , [ Testable.lessThanOrEqual "not larger than parent"
475− context.self.bbox.width
476− context.parent.bbox.width
478− , case context.selfElement of
479− Testable.Paragraph _ _ ->
480− -- A paragraph with width fill
481− -- we want to test for correct text wrapping here.
489− |> List.map childWidth
490− |> List.append (List.map .width context.self.textMetrics)
494− context.self.bbox.padding.left + context.self.bbox.padding.right
496− totalCalculatedWidth =
497− totalChildren + horizontalPadding
500− if boxChildrenHeight > 20 then
501− ceiling (boxChildrenHeight / 20)
504− ceiling (totalCalculatedWidth / context.self.bbox.width)
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)
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)
532 Shrink ->
385 Shrink ->
@@ -538,211 +391,33 @@ widthHelper maybeMin maybeMax len =
538 |> addMin
391 |> addMin
539 |> addMax
392 |> addMax
541− , id = Testable.IsWidth
543− \context ->
395+ \context _ ->
544− case context.selfElement of
547− childWidth child =
397+ childWidth child =
398+ -- TODO: add margin values to widths
548− child.bbox.width
399+ child.bbox.width
550− totalChildren =
401+ totalChildren =
551− context.children
402+ context.children
552− |> List.map childWidth
403+ |> List.map childWidth
553− |> List.append (List.map .width context.self.textMetrics)
554− |> List.sum
404+ |> List.sum
556− horizontalPadding =
406+ horizontalPadding =
557− context.self.bbox.padding.left + context.self.bbox.padding.right
407+ context.self.bbox.padding.left + context.self.bbox.padding.right
559− listIf
409+ spacingValue =
560− [ ( (context.parentLayout /= Testable.InParagraph)
410+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
561− && (context.parentLayout /= Testable.InTextCol)
411+ in
562− , Testable.rounded "equals children"
412+ if totalChildren == 0 then
563− { expected = totalChildren + horizontalPadding
413+ -- TODO: The issue is that we have a hard time measuring `text` elements
564− , found = context.self.bbox.width
414+ -- So if a element has a text child, then it's width isn't going to show up in the system.
567− , ( context.parentLayout /= Testable.AtRoot
568− , Testable.lessThanOrEqual "not larger than parent"
569− context.self.bbox.width
415+ expectRoundedEquality context.self.bbox.width context.self.bbox.width
570− context.parent.bbox.width
574− Testable.Link _ _ _ ->
417+ else
575− let
418+ -- This fails if this element is actually a column
576− childWidth child =
419+ -- So we need to capture what this element is in order to do this calculation.
577− child.bbox.width
420+ expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width
581− |> List.map childWidth
582− |> List.append (List.map .width context.self.textMetrics)
586− context.self.bbox.padding.left + context.self.bbox.padding.right
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
596− , ( context.parentLayout /= Testable.AtRoot
597− , Testable.lessThanOrEqual "not larger than parent"
598− context.self.bbox.width
599− context.parent.bbox.width
603− Testable.Row rowAttrs _ ->
604− -- width of row is the sum of all children widths
605− -- both text elements and others.
612− |> List.map childWidth
613− |> List.append (List.map .width context.self.textMetrics)
617− context.self.bbox.padding.left + context.self.bbox.padding.right
620− Testable.getSpacingFromAttributes rowAttrs
623− toFloat spacingAmount * (toFloat (List.length context.children) - 1)
627− , expectRoundedEquality
628− { expected = totalChildren + horizontalPadding + totalSpacing
629− , found = context.self.bbox.width
632− , ( context.parentLayout /= Testable.AtRoot
633− , Testable.lessThanOrEqual "not larger than parent"
634− context.self.bbox.width
635− context.parent.bbox.width
639− Testable.Column _ _ ->
640− -- The width of the column is the width of the widest child.
644− + context.self.bbox.padding.left
645− + context.self.bbox.padding.right
651− + context.self.bbox.padding.left
652− + context.self.bbox.padding.right
654− context.self.textMetrics
658− |> List.map childWidth
659− |> List.append textChildren
663− , expectRoundedEquality
664− { expected = Maybe.withDefault 0 (List.maximum allChildren)
665− , found = context.self.bbox.width
668− , ( context.parentLayout /= Testable.AtRoot
669− , Testable.lessThanOrEqual "not larger than parent"
670− context.self.bbox.width
671− context.parent.bbox.width
675− Testable.TextColumn _ _ ->
676− -- The width of the column is the width of the widest child.
680− + context.self.bbox.padding.left
681− + context.self.bbox.padding.right
687− + context.self.bbox.padding.left
688− + context.self.bbox.padding.right
690− context.self.textMetrics
694− |> List.map childWidth
695− |> List.append textChildren
699− , expectRoundedEquality
700− { expected = Maybe.withDefault 0 (List.maximum allChildren)
701− , found = context.self.bbox.width
704− , ( context.parentLayout /= Testable.AtRoot
705− , Testable.lessThanOrEqual "not larger than parent"
706− context.self.bbox.width
707− context.parent.bbox.width
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.
720− |> List.map childWidth
721− |> List.append (List.map .width context.self.textMetrics)
725− context.self.bbox.padding.left + context.self.bbox.padding.right
729− , expectRoundedEquality
730− { expected = totalChildren + horizontalPadding
731− , found = context.self.bbox.width
734− , ( context.parentLayout /= Testable.AtRoot
735− , Testable.lessThanOrEqual "not larger than parent"
736− context.self.bbox.width
737− context.parent.bbox.width
@@ -811,16 +486,17 @@ heightHelper maybeMin maybeMax len =
811 |> addMin
486 |> addMin
812 |> addMax
487 |> addMax
814− , id = Testable.IsHeight
816− \found ->
490+ \found _ ->
817− [ expectRoundedEquality
491+ Expect.all
818− { expected = toFloat val
492+ [ \_ ->
819− , found = found.self.bbox.height
493+ Expect.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
820− }
494+ (floor found.self.bbox.height == val)
821− , Testable.true "min/max holds true"
495+ , \_ ->
822− (minMaxTest (floor found.self.bbox.height))
496+ Expect.true "min/max holds true"
823− ]
497+ (minMaxTest (floor found.self.bbox.height))
826 Fill portion ->
502 Fill portion ->
@@ -832,32 +508,31 @@ heightHelper maybeMin maybeMax len =
832 |> addMin
508 |> addMin
833 |> addMax
509 |> addMax
835− , id = Testable.IsHeight
837− \context ->
512+ \context _ ->
838− [ if List.member context.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
513+ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
839− Testable.true "height fill doesn't apply to above/below elements" True
514+ Expect.true "height fill doesn't apply to above/below elements" True
843 parentAvailableHeight =
518 parentAvailableHeight =
844 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
519 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
846− case context.parentLayout of
521+ case context.location of
847 Testable.IsNearby _ ->
522 Testable.IsNearby _ ->
848− Testable.true "Nearby Element has fill height"
523+ Expect.true "Nearby Element has fill height"
849 ((floor context.parent.bbox.height == floor context.self.bbox.height)
524 ((floor context.parent.bbox.height == floor context.self.bbox.height)
850 || minMaxTest (floor context.self.bbox.height)
525 || minMaxTest (floor context.self.bbox.height)
853 Testable.InColumn ->
528 Testable.InColumn ->
854− Testable.true "Element within column has fill height"
529+ Expect.true "Element within column has fill height"
855 ((floor parentAvailableHeight == floor context.self.bbox.height)
530 ((floor parentAvailableHeight == floor context.self.bbox.height)
856 || minMaxTest (floor context.self.bbox.height)
531 || minMaxTest (floor context.self.bbox.height)
859 Testable.InEl ->
534 Testable.InEl ->
860− Testable.true "Element within el has fill height" <|
535+ Expect.true "Element within el has fill height" <|
861 (floor parentAvailableHeight == floor context.self.bbox.height)
536 (floor parentAvailableHeight == floor context.self.bbox.height)
862 || minMaxTest (floor context.self.bbox.height)
537 || minMaxTest (floor context.self.bbox.height)
@@ -866,10 +541,9 @@ heightHelper maybeMin maybeMax len =
866 spacePerPortion =
541 spacePerPortion =
867 parentAvailableHeight / toFloat (List.length context.siblings + 1)
542 parentAvailableHeight / toFloat (List.length context.siblings + 1)
869− Testable.true "el has fill height" <|
544+ Expect.true "el has fill height" <|
870 (floor spacePerPortion == floor context.self.bbox.height)
545 (floor spacePerPortion == floor context.self.bbox.height)
871 || minMaxTest (floor context.self.bbox.height)
546 || minMaxTest (floor context.self.bbox.height)
875 Shrink ->
549 Shrink ->
@@ -881,134 +555,33 @@ heightHelper maybeMin maybeMax len =
881 |> addMin
555 |> addMin
882 |> addMax
556 |> addMax
884− , id = Testable.IsHeight
886− \context ->
559+ \context _ ->
887− case context.selfElement of
560+ let
888− Testable.El _ _ ->
561+ childWidth child =
889− let
562+ -- TODO: add margin values to heights
890− childHeight child =
563+ child.bbox.height
891− child.bbox.height
564+
892− in
565+ totalChildren =
893− if List.isEmpty context.children then
566+ context.children
894− -- context.self.textMetrics
567+ |> List.map childWidth
895− -- |> List.map Testable.textHeight
568+ |> List.sum
897− -- TODO: apparently the font metrics we have are for the literal characters rendered
570+ verticalPadding =
898− -- not for the font itself.
571+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
899− [ Testable.todo "calculate height from actual text metrics"
572+
900− ]
573+ spacingValue =
901−
574+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
903− [ expectRoundedEquality
576+ if totalChildren == 0 then
904− { expected =
577+ -- TODO: The issue is that we have a hard time measuring `text` elements
905− context.children
578+ -- So if a element has a text child, then it's height isn't going to show up in the system.
906− |> List.map childHeight
579+ expectRoundedEquality context.self.bbox.height context.self.bbox.height
908− |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
909− , found = context.self.bbox.height
911− , Testable.lessThanOrEqual "not larger than parent"
912− context.self.bbox.height
913− context.parent.bbox.height
916− Testable.Link _ _ _ ->
921− if List.isEmpty context.children then
922− -- context.self.textMetrics
923− -- |> List.map Testable.textHeight
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"
931− [ expectRoundedEquality
934− |> List.map childHeight
936− |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
937− , found = context.self.bbox.height
939− , Testable.lessThanOrEqual "not larger than parent"
940− context.self.bbox.height
941− context.parent.bbox.height
949− if List.isEmpty context.children then
950− -- context.self.textMetrics
951− -- |> List.map Testable.textHeight
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" ]
958− [ expectRoundedEquality
961− |> List.map childHeight
963− |> Maybe.withDefault 0
964− |> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
965− , found = context.self.bbox.height
967− , Testable.lessThanOrEqual "not larger than parent"
968− context.self.bbox.height
969− context.parent.bbox.height
972− Testable.Column colAttrs _ ->
581+ else
973− let
582+ -- This fails if this element is actually a column
974− childHeight child =
583+ -- So we need to capture what this element is in order to do this calculation.
975− child.bbox.height
584+ expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height
979− |> List.map childHeight
980− |> List.append (List.map Testable.textHeight context.self.textMetrics)
984− context.self.bbox.padding.top + context.self.bbox.padding.bottom
987− Testable.getSpacingFromAttributes colAttrs
990− toFloat spacingAmount * (toFloat (List.length context.children) - 1)
992− [ expectRoundedEquality
993− { expected = totalChildren + verticalPadding + totalSpacing
994− , found = context.self.bbox.height
996− , Testable.lessThanOrEqual "not larger than parent"
997− context.self.bbox.height
998− context.parent.bbox.height
1001− Testable.TextColumn _ _ ->
1004− Testable.Paragraph _ _ ->
@@ -1029,9 +602,8 @@ spacing space =
1029 , Testable.LabeledTest
602 , Testable.LabeledTest
1030 { label = "spacing: " ++ String.fromInt space
603 { label = "spacing: " ++ String.fromInt space
1031 , attr = Element.spacing space
604 , attr = Element.spacing space
1032− , id = Testable.NoId
1033 , test =
605 , test =
1034− \found ->
606+ \found _ ->
1036 findDistance child total =
608 findDistance child total =
1037 List.concatMap
609 List.concatMap
@@ -1077,7 +649,7 @@ spacing space =
1078 distances
650 distances
1080− [ Testable.true
652+ Expect.true
1081 ("All children are at least "
653 ("All children are at least "
1082 ++ String.fromInt space
654 ++ String.fromInt space
1083 ++ " pixels apart."
655 ++ " pixels apart."
@@ -1085,7 +657,6 @@ spacing space =
1085 ++ " are not though"
657 ++ " are not though"
1087 (allAreSpaced == [])
659 (allAreSpaced == [])
@@ -1108,33 +679,30 @@ alignLeft =
1108 Testable.LabeledTest
679 Testable.LabeledTest
1109 { label = "alignLeft"
680 { label = "alignLeft"
1110 , attr = Element.alignLeft
681 , attr = Element.alignLeft
1111− , id = Testable.NoId
1112 , test =
682 , test =
1113− \found ->
683+ \found _ ->
1114− [ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
684+ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1115− Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
685+ Expect.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
1117− else if
687+ else if
1118− List.member found.parentLayout
688+ List.member found.location
1119 [ Testable.IsNearby Testable.InFront
689 [ Testable.IsNearby Testable.InFront
1120 , Testable.IsNearby Testable.Behind
690 , Testable.IsNearby Testable.Behind
1121 , Testable.IsNearby Testable.Above
691 , Testable.IsNearby Testable.Above
1122 , Testable.IsNearby Testable.Below
692 , Testable.IsNearby Testable.Below
1125 expectRoundedEquality
695 expectRoundedEquality
1126− { found = found.self.bbox.left
696+ found.self.bbox.left
1127− , expected = found.parent.bbox.left
697+ found.parent.bbox.left
1130− else if List.length found.siblings == 0 then
699+ else if List.length found.siblings == 0 then
1131 expectRoundedEquality
700 expectRoundedEquality
1132− { found = found.self.bbox.left
701+ found.self.bbox.left
1133− , expected = found.parent.bbox.left + found.parent.bbox.padding.left
702+ (found.parent.bbox.left + found.parent.bbox.padding.left)
1137− case found.parentLayout of
705+ case found.location of
1138 Testable.InRow ->
706 Testable.InRow ->
1140 siblingsOnLeft =
708 siblingsOnLeft =
@@ -1149,16 +717,13 @@ alignLeft =
1149 |> List.sum
717 |> List.sum
1151 expectRoundedEquality
719 expectRoundedEquality
1152− { found = found.self.bbox.left
720+ found.self.bbox.left
1153− , expected = found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings)
721+ (found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings))
1157 expectRoundedEquality
724 expectRoundedEquality
1158− { found = found.self.bbox.left
725+ found.self.bbox.left
1159− , expected = found.parent.bbox.left + found.parent.bbox.padding.left
726+ (found.parent.bbox.left + found.parent.bbox.padding.left)
@@ -1168,9 +733,8 @@ centerX =
1168 Testable.LabeledTest
733 Testable.LabeledTest
1169 { label = "centerX"
734 { label = "centerX"
1170 , attr = Element.centerX
735 , attr = Element.centerX
1171− , id = Testable.NoId
1172 , test =
736 , test =
1173− \found ->
737+ \found _ ->
1175 selfCenter : Float
739 selfCenter : Float
1176 selfCenter =
740 selfCenter =
@@ -1180,18 +744,16 @@ centerX =
1180 parentCenter =
744 parentCenter =
1181 found.parent.bbox.left + (found.parent.bbox.width / 2)
745 found.parent.bbox.left + (found.parent.bbox.width / 2)
1183− if List.member found.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
747+ if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
1184− [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
748+ Expect.true "centerX doesn't apply to elements that are onLeft or onRight" True
1186 else if List.length found.siblings == 0 then
750 else if List.length found.siblings == 0 then
1187− [ expectRoundedEquality
751+ expectRoundedEquality
1188− { found = selfCenter
752+ selfCenter
1189− , expected = parentCenter
753+ parentCenter
1194− case found.parentLayout of
756+ case found.location of
1195 Testable.InRow ->
757 Testable.InRow ->
1197 siblingsOnLeft =
759 siblingsOnLeft =
@@ -1221,18 +783,12 @@ centerX =
1224− [ expectRoundedEquality
786+ expectRoundedEquality
1225− { found = selfCenter
787+ selfCenter
1226− , expected = expectedCenter
788+ expectedCenter
1231− [ expectRoundedEquality
791+ expectRoundedEquality selfCenter parentCenter
1232− { found = selfCenter
1233− , expected = parentCenter
@@ -1242,35 +798,30 @@ alignRight =
1242 Testable.LabeledTest
798 Testable.LabeledTest
1243 { label = "alignRight"
799 { label = "alignRight"
1244 , attr = Element.alignRight
800 , attr = Element.alignRight
1245− , id = Testable.NoId
1246 , test =
801 , test =
1247− \found ->
802+ \found _ ->
1248− if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
803+ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1249− [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
804+ Expect.true "alignRight doesn't apply to elements that are onLeft or onRight" True
1252− List.member found.parentLayout
807+ List.member found.location
1253 [ Testable.IsNearby Testable.InFront
808 [ Testable.IsNearby Testable.InFront
1254 , Testable.IsNearby Testable.Behind
809 , Testable.IsNearby Testable.Behind
1255 , Testable.IsNearby Testable.Above
810 , Testable.IsNearby Testable.Above
1256 , Testable.IsNearby Testable.Below
811 , Testable.IsNearby Testable.Below
1259− [ expectRoundedEquality
814+ expectRoundedEquality
1260− { found = found.self.bbox.right
815+ found.self.bbox.right
1261− , expected = found.parent.bbox.right
816+ found.parent.bbox.right
1265 else if List.length found.siblings == 0 then
818 else if List.length found.siblings == 0 then
1266− [ expectRoundedEquality
819+ expectRoundedEquality
1267− { found = found.self.bbox.right
820+ found.self.bbox.right
1268− , expected = found.parent.bbox.right + found.parent.bbox.padding.right
821+ (found.parent.bbox.right + found.parent.bbox.padding.right)
1273− case found.parentLayout of
824+ case found.location of
1274 Testable.InRow ->
825 Testable.InRow ->
1276 siblingsOnRight =
827 siblingsOnRight =
@@ -1284,18 +835,14 @@ alignRight =
1284 |> List.map (.width << .bbox)
835 |> List.map (.width << .bbox)
1285 |> List.sum
836 |> List.sum
1287− [ expectRoundedEquality
838+ expectRoundedEquality
1288− { found = found.self.bbox.right
839+ found.self.bbox.right
1289− , expected = found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings)
840+ (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
1294− [ expectRoundedEquality
843+ expectRoundedEquality
1295− { found = found.self.bbox.right
844+ found.self.bbox.right
1296− , expected = found.parent.bbox.right + found.parent.bbox.padding.right
845+ (found.parent.bbox.right + found.parent.bbox.padding.right)
@@ -1305,35 +852,30 @@ alignTop =
1305 Testable.LabeledTest
852 Testable.LabeledTest
1306 { label = "alignTop"
853 { label = "alignTop"
1307 , attr = Element.alignTop
854 , attr = Element.alignTop
1308− , id = Testable.NoId
1309 , test =
855 , test =
1310− \found ->
856+ \found _ ->
1311− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
857+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1312− [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
858+ Expect.true "alignTop doesn't apply to elements that are above or below" True
1315− List.member found.parentLayout
861+ List.member found.location
1316 [ Testable.IsNearby Testable.InFront
862 [ Testable.IsNearby Testable.InFront
1317 , Testable.IsNearby Testable.Behind
863 , Testable.IsNearby Testable.Behind
1318 , Testable.IsNearby Testable.OnRight
864 , Testable.IsNearby Testable.OnRight
1319 , Testable.IsNearby Testable.OnLeft
865 , Testable.IsNearby Testable.OnLeft
1322− [ expectRoundedEquality
868+ expectRoundedEquality
1323− { found = found.self.bbox.top
869+ found.self.bbox.top
1324− , expected = found.parent.bbox.top
870+ found.parent.bbox.top
1328 else if List.length found.siblings == 0 then
872 else if List.length found.siblings == 0 then
1329− [ expectRoundedEquality
873+ expectRoundedEquality
1330− { found = found.self.bbox.top
874+ found.self.bbox.top
1331− , expected = found.parent.bbox.top + found.parent.bbox.padding.top
875+ (found.parent.bbox.top + found.parent.bbox.padding.top)
1336− case found.parentLayout of
878+ case found.location of
1337 Testable.InColumn ->
879 Testable.InColumn ->
1339 siblingsAbove =
881 siblingsAbove =
@@ -1347,18 +889,14 @@ alignTop =
1347 |> List.map (.height << .bbox)
889 |> List.map (.height << .bbox)
1348 |> List.sum
890 |> List.sum
1350− [ expectRoundedEquality
892+ expectRoundedEquality
1351− { found = found.self.bbox.top
893+ found.self.bbox.top
1352− , expected = found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings)
894+ (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
1357− [ expectRoundedEquality
897+ expectRoundedEquality
1358− { found = found.self.bbox.top
898+ found.self.bbox.top
1359− , expected = found.parent.bbox.top
899+ found.parent.bbox.top
@@ -1368,35 +906,30 @@ alignBottom =
1368 Testable.LabeledTest
906 Testable.LabeledTest
1369 { label = "alignBottom"
907 { label = "alignBottom"
1370 , attr = Element.alignBottom
908 , attr = Element.alignBottom
1371− , id = Testable.NoId
1372 , test =
909 , test =
1373− \found ->
910+ \found _ ->
1374− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
911+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1375− [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
912+ Expect.true "alignBottom doesn't apply to elements that are above or below" True
1378− List.member found.parentLayout
915+ List.member found.location
1379 [ Testable.IsNearby Testable.InFront
916 [ Testable.IsNearby Testable.InFront
1380 , Testable.IsNearby Testable.Behind
917 , Testable.IsNearby Testable.Behind
1381 , Testable.IsNearby Testable.OnRight
918 , Testable.IsNearby Testable.OnRight
1382 , Testable.IsNearby Testable.OnLeft
919 , Testable.IsNearby Testable.OnLeft
1385− [ expectRoundedEquality
922+ expectRoundedEquality
1386− { found = found.self.bbox.bottom
923+ found.self.bbox.bottom
1387− , expected = found.parent.bbox.bottom
924+ found.parent.bbox.bottom
1391 else if List.length found.siblings == 0 then
926 else if List.length found.siblings == 0 then
1392− [ expectRoundedEquality
927+ expectRoundedEquality
1393− { found = found.self.bbox.bottom
928+ found.self.bbox.bottom
1394− , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
929+ (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1399− case found.parentLayout of
932+ case found.location of
1400 Testable.InColumn ->
933 Testable.InColumn ->
1402 siblingsBelow =
935 siblingsBelow =
@@ -1410,31 +943,20 @@ alignBottom =
1410 |> List.map (.height << .bbox)
943 |> List.map (.height << .bbox)
1411 |> List.sum
944 |> List.sum
1413− [ expectRoundedEquality
946+ expectRoundedEquality
1414− { found = found.self.bbox.bottom
947+ found.self.bbox.bottom
1415− , expected = found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings)
948+ (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
1420− [ expectRoundedEquality
951+ expectRoundedEquality
1421− { found = found.self.bbox.bottom
952+ found.self.bbox.bottom
1422− , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
953+ (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1428−expectRoundedEquality : { expected : Float, found : Float } -> Testable.LayoutExpectation
957+expectRoundedEquality x y =
1429−expectRoundedEquality { expected, found } =
958+ Expect.true ("within 1 of each other " ++ String.fromFloat x ++ ":" ++ String.fromFloat y)
1430− Testable.true
959+ (abs (x - y) < 1)
1431− ("expected " ++ floatToString expected ++ ", found " ++ floatToString found)
1432− (abs (expected - found) < 1)
1435−floatToString : Float -> String
1437− String.fromFloat (toFloat (round (x * 100)) / 100)
@@ -1443,9 +965,8 @@ centerY =
1443 Testable.LabeledTest
965 Testable.LabeledTest
1444 { label = "centerY"
966 { label = "centerY"
1445 , attr = Element.centerY
967 , attr = Element.centerY
1446− , id = Testable.NoId
1447 , test =
968 , test =
1448− \found ->
969+ \found _ ->
1450 selfCenter =
971 selfCenter =
1451 found.self.bbox.top + (found.self.bbox.height / 2)
972 found.self.bbox.top + (found.self.bbox.height / 2)
@@ -1453,18 +974,16 @@ centerY =
1453 parentCenter =
974 parentCenter =
1454 found.parent.bbox.top + (found.parent.bbox.height / 2)
975 found.parent.bbox.top + (found.parent.bbox.height / 2)
1456− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
977+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1457− [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
978+ Expect.true "centerY doesn't apply to elements that are above or below" True
1459 else if List.length found.siblings == 0 then
980 else if List.length found.siblings == 0 then
1460− [ expectRoundedEquality
981+ expectRoundedEquality
1461− { found = selfCenter
982+ selfCenter
1462− , expected = parentCenter
983+ parentCenter
1467− case found.parentLayout of
986+ case found.location of
1468 Testable.InColumn ->
987 Testable.InColumn ->
1470 siblingsOnTop =
989 siblingsOnTop =
@@ -1494,18 +1013,12 @@ centerY =
1497− [ expectRoundedEquality
1016+ expectRoundedEquality
1498− { found = selfCenter
1017+ selfCenter
1499− , expected = expectedCenter
1018+ expectedCenter
1504− [ expectRoundedEquality
1021+ expectRoundedEquality selfCenter parentCenter
1505− { found = selfCenter
1506− , expected = parentCenter
@@ -1517,12 +1030,8 @@ above element =
1517 , element = element
1030 , element = element
1518 , label = "above"
1031 , label = "above"
1519 , test =
1032 , test =
1520− \found ->
1033+ \found _ ->
1521− [ expectRoundedEquality
1034+ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top
1522− { found = found.self.bbox.bottom
1523− , expected = found.parent.bbox.top
@@ -1534,12 +1043,8 @@ below element =
1534 , element = element
1043 , element = element
1535 , label = "below"
1044 , label = "below"
1536 , test =
1045 , test =
1537− \found ->
1046+ \found _ ->
1538− [ expectRoundedEquality
1047+ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom
1539− { found = found.self.bbox.top
1540− , expected = found.parent.bbox.bottom
@@ -1551,12 +1056,8 @@ onRight element =
1551 , element = element
1056 , element = element
1552 , label = "onRight"
1057 , label = "onRight"
1553 , test =
1058 , test =
1554− \found ->
1059+ \found _ ->
1555− [ expectRoundedEquality
1060+ expectRoundedEquality found.self.bbox.left found.parent.bbox.right
1556− { found = found.self.bbox.left
1557− , expected = found.parent.bbox.right
@@ -1568,12 +1069,8 @@ onLeft element =
1568 , element = element
1069 , element = element
1569 , label = "onLeft"
1070 , label = "onLeft"
1570 , test =
1071 , test =
1571− \found ->
1072+ \found _ ->
1572− [ expectRoundedEquality
1073+ expectRoundedEquality found.self.bbox.right found.parent.bbox.left
1573− { found = found.self.bbox.right
1574− , expected = found.parent.bbox.left
@@ -1589,12 +1086,11 @@ inFront element =
1589 , element = element
1086 , element = element
1590 , label = "inFront"
1087 , label = "inFront"
1591 , test =
1088 , test =
1592− \found ->
1089+ withinHelper
1593− [ withinHelper found ]
1597−withinHelper found =
1093+withinHelper found _ =
1599 horizontalCheck =
1095 horizontalCheck =
1600 if found.self.bbox.width > found.parent.bbox.width then
1096 if found.self.bbox.width > found.parent.bbox.width then
@@ -1618,7 +1114,7 @@ withinHelper found =
1618 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
1114 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
1621− Testable.true "within the confines of the parent"
1117+ Expect.true "within the confines of the parent"
1622 (List.all ((==) True)
1118 (List.all ((==) True)
1623 (List.concat
1119 (List.concat
1624 [ horizontalCheck
1120 [ horizontalCheck
@@ -1636,88 +1132,5 @@ behindContent element =
1636 , element = element
1132 , element = element
1637 , label = "behindContent"
1133 , label = "behindContent"
1638 , test =
1134 , test =
1639− \found ->
1135+ withinHelper
1640− [ withinHelper found ]
1645−{- Implicit width/height calcualtions -}
1648−implicitWidthHeightShrink attrs =
1651− implicitTest (widthHelper Nothing Nothing Shrink)
1652− :: implicitTest (heightHelper Nothing Nothing Shrink)
1655− skipOverridden withImplicits
1660− Testable.LabeledTest details ->
1663− Testable.AttrTest details ->
1672− (\attr ( found, caught ) ->
1675− case attrId attr of
1679− Testable.IsWidth ->
1681− , { hasWidth = True
1682− , hasHeight = found.hasHeight
1686− Testable.IsHeight ->
1688− , { hasWidth = found.hasWidth
1701− ( { hasWidth = False
1702− , hasHeight = False
1711−{-| This is taking a normal test and rmoving its ability to attach a real `Element` attribute.
1715− Testable.LabeledTest details ->
1717− { test = details.test
1718− , label = "Implicit -> " ++ details.label