@@ -10,7 +10,6 @@ module Testable.Element exposing
1010 , below
1111 , centerX
1212 , centerY
13− , clip
1413 , column
1514 , el
1615 , expectRoundedEquality
@@ -21,12 +20,9 @@ module Testable.Element exposing
2120 , isVisible
2221 , label
2322 , layout
24− , link
2523 , maximum
2624 , minimum
2725 , moveDown
28− , moveLeft
29− , moveRight
3026 , moveUp
3127 , none
3228 , onLeft
@@ -38,14 +34,10 @@ module Testable.Element exposing
3834 , rgb
3935 , rgba
4036 , row
41− , scrollbarX
42− , scrollbarY
43− , scrollbars
4437 , shrink
4538 , spacing
4639 , text
4740 , textColumn
48− , toProgram
4941 , transparent
5042 , width
5143 )
@@ -64,21 +56,17 @@ In order to run the test:
6456
6557import Dict
6658import Element
59+import Expect
6760import Html.Attributes
6861import Testable
6962import Testable.Runner
7063
7164
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
65+layout : List (Testable.Attr msg) -> Testable.Element Testable.Runner.Msg -> Testable.Runner.TestableProgram
8066layout attrs elem =
81− Testable.Runner.testable "Test" elem
67+ Testable.Runner.program
68+ [ ( "Open Case", elem )
69+ ]
8270
8371
8472text : String -> Testable.Element msg
@@ -87,18 +75,18 @@ text =
8775
8876
8977el : List (Testable.Attr msg) -> Testable.Element msg -> Testable.Element msg
90−el attrs =
91− Testable.El (implicitWidthHeightShrink attrs)
78+el =
79+ Testable.El
9280
9381
9482row : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
95−row attrs =
96− Testable.Row (implicitWidthHeightShrink attrs)
83+row =
84+ Testable.Row
9785
9886
9987column : List (Testable.Attr msg) -> List (Testable.Element msg) -> Testable.Element msg
100−column attrs =
101− Testable.Column (implicitWidthHeightShrink attrs)
88+column =
89+ Testable.Column
10290
10391
10492none : Testable.Element msg
@@ -107,66 +95,13 @@ none =
10795
10896
10997paragraph : 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)
98+paragraph =
99+ Testable.Paragraph
118100
119101
120102textColumn : 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
164−
165−
166−{-| Old labeling mechanism that i removed to hastily
167−-}
168−label str =
169− Testable.Batch []
103+textColumn =
104+ Testable.TextColumn
170105
171106
172107moveUp x =
@@ -177,14 +112,6 @@ moveDown x =
177112 Testable.Attr (Element.moveDown x)
178113
179114
180−moveRight x =
181− Testable.Attr (Element.moveRight x)
182−
183−
184−moveLeft x =
185− Testable.Attr (Element.moveLeft x)
186−
187−
188115type Length
189116 = Px Int
190117 | Fill Int
@@ -229,6 +156,11 @@ fillPortion =
229156 Fill
230157
231158
159+label : String -> Testable.Attr msg
160+label =
161+ Testable.Label
162+
163+
232164transparent : Bool -> Testable.Attr msg
233165transparent on =
234166 Testable.LabeledTest
@@ -239,9 +171,8 @@ transparent on =
239171 else
240172 "opaque"
241173 , attr = Element.transparent on
242− , id = Testable.NoId
243174 , test =
244− \context ->
175+ \context _ ->
245176 let
246177 selfTransparency =
247178 context.self.style
@@ -255,19 +186,19 @@ transparent on =
255186 else
256187 "1"
257188 in
258− [ Testable.equal value selfTransparency ]
189+ Expect.equal value selfTransparency
259190 }
260191
261192
262193{-| -}
263194isVisible : Testable.Attr msg
264195isVisible =
265− Testable.AttrTest
196+ Testable.LabeledTest
266197 { label = "is-visible"
267− , id = Testable.NoId
198+ , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
268199 , test =
269− \context ->
270− [ Testable.equal context.self.isVisible True ]
200+ \context _ ->
201+ Expect.equal context.self.isVisible True
271202 }
272203
273204
@@ -277,16 +208,15 @@ alpha a =
277208 Testable.LabeledTest
278209 { label = "alpha-" ++ String.fromFloat a
279210 , attr = Element.alpha a
280− , id = Testable.NoId
281211 , test =
282− \context ->
212+ \context _ ->
283213 let
284214 selfTransparency =
285215 context.self.style
286216 |> Dict.get "opacity"
287217 |> Maybe.withDefault "notfound"
288218 in
289− [ Testable.equal (String.fromFloat a) selfTransparency ]
219+ Expect.equal (String.fromFloat a) selfTransparency
290220 }
291221
292222
@@ -296,10 +226,9 @@ padding pad =
296226 Testable.LabeledTest
297227 { label = "padding " ++ String.fromInt pad
298228 , attr = Element.padding pad
299− , id = Testable.NoId
300229 , test =
301− \found ->
302− [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
230+ \found _ ->
231+ Expect.true ("Padding " ++ String.fromInt pad ++ " is present")
303232 (List.all ((==) pad)
304233 [ floor found.self.bbox.padding.left
305234 , floor found.self.bbox.padding.right
@@ -307,7 +236,6 @@ padding pad =
307236 , floor found.self.bbox.padding.bottom
308237 ]
309238 )
310− ]
311239 }
312240
313241
@@ -317,10 +245,9 @@ paddingXY x y =
317245 Testable.LabeledTest
318246 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
319247 , attr = Element.paddingXY x y
320− , id = Testable.NoId
321248 , test =
322− \found ->
323− [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
249+ \found _ ->
250+ Expect.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
324251 (List.all ((==) x)
325252 [ floor found.self.bbox.padding.left
326253 , floor found.self.bbox.padding.right
@@ -330,15 +257,9 @@ paddingXY x y =
330257 , floor found.self.bbox.padding.bottom
331258 ]
332259 )
333− ]
334260 }
335261
336262
337−listIf ls =
338− List.filter Tuple.first ls
339− |> List.map Tuple.second
340−
341−
342263widthHelper maybeMin maybeMax len =
343264 let
344265 addMin l =
@@ -398,7 +319,6 @@ widthHelper maybeMin maybeMax len =
398319 -- Pixel values should ignore min and max?
399320 Testable.LabeledTest
400321 { label = "width " ++ String.fromInt val ++ "px" ++ minLabel ++ maxLabel
401− , id = Testable.IsWidth
402322 , attr =
403323 Element.width
404324 (Element.px val
@@ -406,24 +326,18 @@ widthHelper maybeMin maybeMax len =
406326 |> addMax
407327 )
408328 , test =
409− \found ->
410− [ expectRoundedEquality
411− { expected = toFloat val
412− , found = found.self.bbox.width
413− }
414− , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
415− ]
329+ \found _ ->
330+ Expect.all
331+ [ \_ ->
332+ Expect.true "exact width is exact" (floor found.self.bbox.width == val)
333+ , \_ -> Expect.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
334+ ]
335+ ()
416336 }
417337
418338 Fill portion ->
419339 Testable.LabeledTest
420− { label =
421− if portion == 1 then
422− "width fill" ++ minLabel ++ maxLabel
423−
424− else
425− "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
426− , id = Testable.IsWidth
340+ { label = "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
427341 , attr =
428342 Element.width
429343 (Element.fillPortion portion
@@ -431,102 +345,41 @@ widthHelper maybeMin maybeMax len =
431345 |> addMax
432346 )
433347 , test =
434− \context ->
435− if List.member context.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
436− [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
348+ \context _ ->
349+ if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
350+ Expect.true "width fill doesn't apply to onright/onleft elements" True
437351
438352 else
439353 let
440354 parentAvailableWidth =
441355 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
442356 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− ]
357+ case context.location of
358+ Testable.IsNearby _ ->
359+ Expect.true "Nearby Element has fill width"
360+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
361+ || minMaxTest (floor context.self.bbox.width)
362+ )
363+
364+ Testable.InColumn ->
365+ Expect.true "Element within column has fill width"
366+ ((floor parentAvailableWidth == floor context.self.bbox.width)
367+ || minMaxTest (floor context.self.bbox.width)
368+ )
369+
370+ Testable.InEl ->
371+ Expect.true "Element within element has fill width" <|
372+ (floor parentAvailableWidth == floor context.self.bbox.width)
373+ || minMaxTest (floor context.self.bbox.width)
374+
375+ _ ->
376+ let
377+ spacePerPortion =
378+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
379+ in
380+ Expect.true "element has fill width" <|
381+ (floor spacePerPortion == floor context.self.bbox.width)
382+ || minMaxTest (floor context.self.bbox.width)
530383 }
531384
532385 Shrink ->
@@ -538,211 +391,33 @@ widthHelper maybeMin maybeMax len =
538391 |> addMin
539392 |> addMax
540393 )
541− , id = Testable.IsWidth
542394 , test =
543− \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− ]
395+ \context _ ->
396+ let
397+ childWidth child =
398+ -- TODO: add margin values to widths
399+ child.bbox.width
400+
401+ totalChildren =
402+ context.children
403+ |> List.map childWidth
404+ |> List.sum
405+
406+ horizontalPadding =
407+ context.self.bbox.padding.left + context.self.bbox.padding.right
408+
409+ spacingValue =
410+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
411+ in
412+ if totalChildren == 0 then
413+ -- TODO: The issue is that we have a hard time measuring `text` elements
414+ -- So if a element has a text child, then it's width isn't going to show up in the system.
415+ expectRoundedEquality context.self.bbox.width context.self.bbox.width
573416
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− ]
710−
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− []
417+ else
418+ -- This fails if this element is actually a column
419+ -- So we need to capture what this element is in order to do this calculation.
420+ expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width
746421 }
747422
748423
@@ -811,16 +486,17 @@ heightHelper maybeMin maybeMax len =
811486 |> addMin
812487 |> addMax
813488 )
814− , id = Testable.IsHeight
815489 , test =
816− \found ->
817− [ expectRoundedEquality
818− { expected = toFloat val
819− , found = found.self.bbox.height
820− }
821− , Testable.true "min/max holds true"
822− (minMaxTest (floor found.self.bbox.height))
823− ]
490+ \found _ ->
491+ Expect.all
492+ [ \_ ->
493+ Expect.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
494+ (floor found.self.bbox.height == val)
495+ , \_ ->
496+ Expect.true "min/max holds true"
497+ (minMaxTest (floor found.self.bbox.height))
498+ ]
499+ ()
824500 }
825501
826502 Fill portion ->
@@ -832,32 +508,31 @@ heightHelper maybeMin maybeMax len =
832508 |> addMin
833509 |> addMax
834510 )
835− , id = Testable.IsHeight
836511 , test =
837− \context ->
838− [ if List.member context.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
839− Testable.true "height fill doesn't apply to above/below elements" True
512+ \context _ ->
513+ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
514+ Expect.true "height fill doesn't apply to above/below elements" True
840515
841− else
516+ else
842517 let
843518 parentAvailableHeight =
844519 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
845520 in
846− case context.parentLayout of
521+ case context.location of
847522 Testable.IsNearby _ ->
848− Testable.true "Nearby Element has fill height"
523+ Expect.true "Nearby Element has fill height"
849524 ((floor context.parent.bbox.height == floor context.self.bbox.height)
850525 || minMaxTest (floor context.self.bbox.height)
851526 )
852527
853528 Testable.InColumn ->
854− Testable.true "Element within column has fill height"
529+ Expect.true "Element within column has fill height"
855530 ((floor parentAvailableHeight == floor context.self.bbox.height)
856531 || minMaxTest (floor context.self.bbox.height)
857532 )
858533
859534 Testable.InEl ->
860− Testable.true "Element within el has fill height" <|
535+ Expect.true "Element within el has fill height" <|
861536 (floor parentAvailableHeight == floor context.self.bbox.height)
862537 || minMaxTest (floor context.self.bbox.height)
863538
@@ -866,10 +541,9 @@ heightHelper maybeMin maybeMax len =
866541 spacePerPortion =
867542 parentAvailableHeight / toFloat (List.length context.siblings + 1)
868543 in
869− Testable.true "el has fill height" <|
544+ Expect.true "el has fill height" <|
870545 (floor spacePerPortion == floor context.self.bbox.height)
871546 || minMaxTest (floor context.self.bbox.height)
872− ]
873547 }
874548
875549 Shrink ->
@@ -881,134 +555,33 @@ heightHelper maybeMin maybeMax len =
881555 |> addMin
882556 |> addMax
883557 )
884− , id = Testable.IsHeight
885558 , test =
886− \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− ]
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− ]
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− ]
559+ \context _ ->
560+ let
561+ childWidth child =
562+ -- TODO: add margin values to heights
563+ child.bbox.height
564+
565+ totalChildren =
566+ context.children
567+ |> List.map childWidth
568+ |> List.sum
569+
570+ verticalPadding =
571+ context.self.bbox.padding.top + context.self.bbox.padding.bottom
572+
573+ spacingValue =
574+ toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
575+ in
576+ if totalChildren == 0 then
577+ -- TODO: The issue is that we have a hard time measuring `text` elements
578+ -- So if a element has a text child, then it's height isn't going to show up in the system.
579+ expectRoundedEquality context.self.bbox.height context.self.bbox.height
971580
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− []
581+ else
582+ -- This fails if this element is actually a column
583+ -- So we need to capture what this element is in order to do this calculation.
584+ expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height
1012585 }
1013586
1014587
@@ -1029,9 +602,8 @@ spacing space =
1029602 , Testable.LabeledTest
1030603 { label = "spacing: " ++ String.fromInt space
1031604 , attr = Element.spacing space
1032− , id = Testable.NoId
1033605 , test =
1034− \found ->
606+ \found _ ->
1035607 let
1036608 findDistance child total =
1037609 List.concatMap
@@ -1077,7 +649,7 @@ spacing space =
1077649 []
1078650 distances
1079651 in
1080− [ Testable.true
652+ Expect.true
1081653 ("All children are at least "
1082654 ++ String.fromInt space
1083655 ++ " pixels apart."
@@ -1085,7 +657,6 @@ spacing space =
1085657 ++ " are not though"
1086658 )
1087659 (allAreSpaced == [])
1088− ]
1089660 }
1090661 ]
1091662
@@ -1108,33 +679,30 @@ alignLeft =
1108679 Testable.LabeledTest
1109680 { label = "alignLeft"
1110681 , attr = Element.alignLeft
1111− , id = Testable.NoId
1112682 , test =
1113− \found ->
1114− [ if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1115− Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
683+ \found _ ->
684+ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
685+ Expect.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
1116686
1117− else if
1118− List.member found.parentLayout
687+ else if
688+ List.member found.location
1119689 [ Testable.IsNearby Testable.InFront
1120690 , Testable.IsNearby Testable.Behind
1121691 , Testable.IsNearby Testable.Above
1122692 , Testable.IsNearby Testable.Below
1123693 ]
1124− then
694+ then
1125695 expectRoundedEquality
1126− { found = found.self.bbox.left
1127− , expected = found.parent.bbox.left
1128− }
696+ found.self.bbox.left
697+ found.parent.bbox.left
1129698
1130− else if List.length found.siblings == 0 then
699+ else if List.length found.siblings == 0 then
1131700 expectRoundedEquality
1132− { found = found.self.bbox.left
1133− , expected = found.parent.bbox.left + found.parent.bbox.padding.left
1134− }
701+ found.self.bbox.left
702+ (found.parent.bbox.left + found.parent.bbox.padding.left)
1135703
1136− else
1137− case found.parentLayout of
704+ else
705+ case found.location of
1138706 Testable.InRow ->
1139707 let
1140708 siblingsOnLeft =
@@ -1149,16 +717,13 @@ alignLeft =
1149717 |> List.sum
1150718 in
1151719 expectRoundedEquality
1152− { found = found.self.bbox.left
1153− , expected = found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings)
1154− }
720+ found.self.bbox.left
721+ (found.parent.bbox.left + (found.parent.bbox.padding.left + widthsOnLeft + spacings))
1155722
1156723 _ ->
1157724 expectRoundedEquality
1158− { found = found.self.bbox.left
1159− , expected = found.parent.bbox.left + found.parent.bbox.padding.left
1160− }
1161− ]
725+ found.self.bbox.left
726+ (found.parent.bbox.left + found.parent.bbox.padding.left)
1162727 }
1163728
1164729
@@ -1168,9 +733,8 @@ centerX =
1168733 Testable.LabeledTest
1169734 { label = "centerX"
1170735 , attr = Element.centerX
1171− , id = Testable.NoId
1172736 , test =
1173− \found ->
737+ \found _ ->
1174738 let
1175739 selfCenter : Float
1176740 selfCenter =
@@ -1180,18 +744,16 @@ centerX =
1180744 parentCenter =
1181745 found.parent.bbox.left + (found.parent.bbox.width / 2)
1182746 in
1183− if List.member found.parentLayout [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
1184− [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
747+ if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
748+ Expect.true "centerX doesn't apply to elements that are onLeft or onRight" True
1185749
1186750 else if List.length found.siblings == 0 then
1187− [ expectRoundedEquality
1188− { found = selfCenter
1189− , expected = parentCenter
1190− }
1191− ]
751+ expectRoundedEquality
752+ selfCenter
753+ parentCenter
1192754
1193755 else
1194− case found.parentLayout of
756+ case found.location of
1195757 Testable.InRow ->
1196758 let
1197759 siblingsOnLeft =
@@ -1221,18 +783,12 @@ centerX =
1221783 / 2
1222784 )
1223785 in
1224− [ expectRoundedEquality
1225− { found = selfCenter
1226− , expected = expectedCenter
1227− }
1228− ]
786+ expectRoundedEquality
787+ selfCenter
788+ expectedCenter
1229789
1230790 _ ->
1231− [ expectRoundedEquality
1232− { found = selfCenter
1233− , expected = parentCenter
1234− }
1235− ]
791+ expectRoundedEquality selfCenter parentCenter
1236792 }
1237793
1238794
@@ -1242,35 +798,30 @@ alignRight =
1242798 Testable.LabeledTest
1243799 { label = "alignRight"
1244800 , attr = Element.alignRight
1245− , id = Testable.NoId
1246801 , test =
1247− \found ->
1248− if List.member found.parentLayout [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
1249− [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
802+ \found _ ->
803+ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
804+ Expect.true "alignRight doesn't apply to elements that are onLeft or onRight" True
1250805
1251806 else if
1252− List.member found.parentLayout
807+ List.member found.location
1253808 [ Testable.IsNearby Testable.InFront
1254809 , Testable.IsNearby Testable.Behind
1255810 , Testable.IsNearby Testable.Above
1256811 , Testable.IsNearby Testable.Below
1257812 ]
1258813 then
1259− [ expectRoundedEquality
1260− { found = found.self.bbox.right
1261− , expected = found.parent.bbox.right
1262− }
1263− ]
814+ expectRoundedEquality
815+ found.self.bbox.right
816+ found.parent.bbox.right
1264817
1265818 else if List.length found.siblings == 0 then
1266− [ expectRoundedEquality
1267− { found = found.self.bbox.right
1268− , expected = found.parent.bbox.right + found.parent.bbox.padding.right
1269− }
1270− ]
819+ expectRoundedEquality
820+ found.self.bbox.right
821+ (found.parent.bbox.right + found.parent.bbox.padding.right)
1271822
1272823 else
1273− case found.parentLayout of
824+ case found.location of
1274825 Testable.InRow ->
1275826 let
1276827 siblingsOnRight =
@@ -1284,18 +835,14 @@ alignRight =
1284835 |> List.map (.width << .bbox)
1285836 |> List.sum
1286837 in
1287− [ expectRoundedEquality
1288− { found = found.self.bbox.right
1289− , expected = found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings)
1290− }
1291− ]
838+ expectRoundedEquality
839+ found.self.bbox.right
840+ (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
1292841
1293842 _ ->
1294− [ expectRoundedEquality
1295− { found = found.self.bbox.right
1296− , expected = found.parent.bbox.right + found.parent.bbox.padding.right
1297− }
1298− ]
843+ expectRoundedEquality
844+ found.self.bbox.right
845+ (found.parent.bbox.right + found.parent.bbox.padding.right)
1299846 }
1300847
1301848
@@ -1305,35 +852,30 @@ alignTop =
1305852 Testable.LabeledTest
1306853 { label = "alignTop"
1307854 , attr = Element.alignTop
1308− , id = Testable.NoId
1309855 , test =
1310− \found ->
1311− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1312− [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
856+ \found _ ->
857+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
858+ Expect.true "alignTop doesn't apply to elements that are above or below" True
1313859
1314860 else if
1315− List.member found.parentLayout
861+ List.member found.location
1316862 [ Testable.IsNearby Testable.InFront
1317863 , Testable.IsNearby Testable.Behind
1318864 , Testable.IsNearby Testable.OnRight
1319865 , Testable.IsNearby Testable.OnLeft
1320866 ]
1321867 then
1322− [ expectRoundedEquality
1323− { found = found.self.bbox.top
1324− , expected = found.parent.bbox.top
1325− }
1326− ]
868+ expectRoundedEquality
869+ found.self.bbox.top
870+ found.parent.bbox.top
1327871
1328872 else if List.length found.siblings == 0 then
1329− [ expectRoundedEquality
1330− { found = found.self.bbox.top
1331− , expected = found.parent.bbox.top + found.parent.bbox.padding.top
1332− }
1333− ]
873+ expectRoundedEquality
874+ found.self.bbox.top
875+ (found.parent.bbox.top + found.parent.bbox.padding.top)
1334876
1335877 else
1336− case found.parentLayout of
878+ case found.location of
1337879 Testable.InColumn ->
1338880 let
1339881 siblingsAbove =
@@ -1347,18 +889,14 @@ alignTop =
1347889 |> List.map (.height << .bbox)
1348890 |> List.sum
1349891 in
1350− [ expectRoundedEquality
1351− { found = found.self.bbox.top
1352− , expected = found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings)
1353− }
1354− ]
892+ expectRoundedEquality
893+ found.self.bbox.top
894+ (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
1355895
1356896 _ ->
1357− [ expectRoundedEquality
1358− { found = found.self.bbox.top
1359− , expected = found.parent.bbox.top
1360− }
1361− ]
897+ expectRoundedEquality
898+ found.self.bbox.top
899+ found.parent.bbox.top
1362900 }
1363901
1364902
@@ -1368,35 +906,30 @@ alignBottom =
1368906 Testable.LabeledTest
1369907 { label = "alignBottom"
1370908 , attr = Element.alignBottom
1371− , id = Testable.NoId
1372909 , test =
1373− \found ->
1374− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1375− [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
910+ \found _ ->
911+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
912+ Expect.true "alignBottom doesn't apply to elements that are above or below" True
1376913
1377914 else if
1378− List.member found.parentLayout
915+ List.member found.location
1379916 [ Testable.IsNearby Testable.InFront
1380917 , Testable.IsNearby Testable.Behind
1381918 , Testable.IsNearby Testable.OnRight
1382919 , Testable.IsNearby Testable.OnLeft
1383920 ]
1384921 then
1385− [ expectRoundedEquality
1386− { found = found.self.bbox.bottom
1387− , expected = found.parent.bbox.bottom
1388− }
1389− ]
922+ expectRoundedEquality
923+ found.self.bbox.bottom
924+ found.parent.bbox.bottom
1390925
1391926 else if List.length found.siblings == 0 then
1392− [ expectRoundedEquality
1393− { found = found.self.bbox.bottom
1394− , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
1395− }
1396− ]
927+ expectRoundedEquality
928+ found.self.bbox.bottom
929+ (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1397930
1398931 else
1399− case found.parentLayout of
932+ case found.location of
1400933 Testable.InColumn ->
1401934 let
1402935 siblingsBelow =
@@ -1410,31 +943,20 @@ alignBottom =
1410943 |> List.map (.height << .bbox)
1411944 |> List.sum
1412945 in
1413− [ expectRoundedEquality
1414− { found = found.self.bbox.bottom
1415− , expected = found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings)
1416− }
1417− ]
946+ expectRoundedEquality
947+ found.self.bbox.bottom
948+ (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
1418949
1419950 _ ->
1420− [ expectRoundedEquality
1421− { found = found.self.bbox.bottom
1422− , expected = found.parent.bbox.bottom + found.parent.bbox.padding.bottom
1423− }
1424− ]
951+ expectRoundedEquality
952+ found.self.bbox.bottom
953+ (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
1425954 }
1426955
1427956
1428−expectRoundedEquality : { expected : Float, found : Float } -> Testable.LayoutExpectation
1429−expectRoundedEquality { expected, found } =
1430− Testable.true
1431− ("expected " ++ floatToString expected ++ ", found " ++ floatToString found)
1432− (abs (expected - found) < 1)
1433−
1434−
1435−floatToString : Float -> String
1436−floatToString x =
1437− String.fromFloat (toFloat (round (x * 100)) / 100)
957+expectRoundedEquality x y =
958+ Expect.true ("within 1 of each other " ++ String.fromFloat x ++ ":" ++ String.fromFloat y)
959+ (abs (x - y) < 1)
1438960
1439961
1440962{-| -}
@@ -1443,9 +965,8 @@ centerY =
1443965 Testable.LabeledTest
1444966 { label = "centerY"
1445967 , attr = Element.centerY
1446− , id = Testable.NoId
1447968 , test =
1448− \found ->
969+ \found _ ->
1449970 let
1450971 selfCenter =
1451972 found.self.bbox.top + (found.self.bbox.height / 2)
@@ -1453,18 +974,16 @@ centerY =
1453974 parentCenter =
1454975 found.parent.bbox.top + (found.parent.bbox.height / 2)
1455976 in
1456− if List.member found.parentLayout [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1457− [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
977+ if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
978+ Expect.true "centerY doesn't apply to elements that are above or below" True
1458979
1459980 else if List.length found.siblings == 0 then
1460− [ expectRoundedEquality
1461− { found = selfCenter
1462− , expected = parentCenter
1463− }
1464− ]
981+ expectRoundedEquality
982+ selfCenter
983+ parentCenter
1465984
1466985 else
1467− case found.parentLayout of
986+ case found.location of
1468987 Testable.InColumn ->
1469988 let
1470989 siblingsOnTop =
@@ -1494,18 +1013,12 @@ centerY =
14941013 / 2
14951014 )
14961015 in
1497− [ expectRoundedEquality
1498− { found = selfCenter
1499− , expected = expectedCenter
1500− }
1501− ]
1016+ expectRoundedEquality
1017+ selfCenter
1018+ expectedCenter
15021019
15031020 _ ->
1504− [ expectRoundedEquality
1505− { found = selfCenter
1506− , expected = parentCenter
1507− }
1508− ]
1021+ expectRoundedEquality selfCenter parentCenter
15091022 }
15101023
15111024
@@ -1517,12 +1030,8 @@ above element =
15171030 , element = element
15181031 , label = "above"
15191032 , test =
1520− \found ->
1521− [ expectRoundedEquality
1522− { found = found.self.bbox.bottom
1523− , expected = found.parent.bbox.top
1524− }
1525− ]
1033+ \found _ ->
1034+ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top
15261035 }
15271036
15281037
@@ -1534,12 +1043,8 @@ below element =
15341043 , element = element
15351044 , label = "below"
15361045 , test =
1537− \found ->
1538− [ expectRoundedEquality
1539− { found = found.self.bbox.top
1540− , expected = found.parent.bbox.bottom
1541− }
1542− ]
1046+ \found _ ->
1047+ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom
15431048 }
15441049
15451050
@@ -1551,12 +1056,8 @@ onRight element =
15511056 , element = element
15521057 , label = "onRight"
15531058 , test =
1554− \found ->
1555− [ expectRoundedEquality
1556− { found = found.self.bbox.left
1557− , expected = found.parent.bbox.right
1558− }
1559− ]
1059+ \found _ ->
1060+ expectRoundedEquality found.self.bbox.left found.parent.bbox.right
15601061 }
15611062
15621063
@@ -1568,12 +1069,8 @@ onLeft element =
15681069 , element = element
15691070 , label = "onLeft"
15701071 , test =
1571− \found ->
1572− [ expectRoundedEquality
1573− { found = found.self.bbox.right
1574− , expected = found.parent.bbox.left
1575− }
1576− ]
1072+ \found _ ->
1073+ expectRoundedEquality found.self.bbox.right found.parent.bbox.left
15771074 }
15781075
15791076
@@ -1589,12 +1086,11 @@ inFront element =
15891086 , element = element
15901087 , label = "inFront"
15911088 , test =
1592− \found ->
1593− [ withinHelper found ]
1089+ withinHelper
15941090 }
15951091
15961092
1597−withinHelper found =
1093+withinHelper found _ =
15981094 let
15991095 horizontalCheck =
16001096 if found.self.bbox.width > found.parent.bbox.width then
@@ -1618,7 +1114,7 @@ withinHelper found =
16181114 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
16191115 ]
16201116 in
1621− Testable.true "within the confines of the parent"
1117+ Expect.true "within the confines of the parent"
16221118 (List.all ((==) True)
16231119 (List.concat
16241120 [ horizontalCheck
@@ -1636,88 +1132,5 @@ behindContent element =
16361132 , element = element
16371133 , label = "behindContent"
16381134 , test =
1639− \found ->
1640− [ withinHelper found ]
1135+ withinHelper
16411136 }
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