git.iko.soy/typeable/elm-ui
on master help sign in
capture safari issue
9f9f9bbElm UI Automation
tests-rendering/src/Testable.elm+8
@@ -21,6 +21,7 @@ module Testable exposing
21 , getSpacing
21 , getSpacing
22 , getSpacingFromAttributes
22 , getSpacingFromAttributes
23 , lessThanOrEqual
23 , lessThanOrEqual
24+ , rounded
24 , runTests
25 , runTests
25 , textHeight
26 , textHeight
26 , toElement
27 , toElement
@@ -264,6 +265,13 @@ lessThanOrEqual label one two =
264 }
265 }
265
266
266
267
268+rounded : String -> { expected : Float, found : Float } -> LayoutExpectation
269+rounded label { expected, found } =
270+ true
271+ (label ++ "| expected " ++ floatToString expected ++ ", found " ++ floatToString found)
272+ (abs (expected - found) < 1)
273+
274+
267equal : a -> a -> LayoutExpectation
275equal : a -> a -> LayoutExpectation
268equal one two =
276equal one two =
269 Expect
277 Expect
tests-rendering/src/Testable/Element.elm+81−33
@@ -402,36 +402,74 @@ widthHelper maybeMin maybeMax len =
402 parentAvailableWidth =
402 parentAvailableWidth =
403 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
403 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
404 in
404 in
405+ List.concat
405− [ case context.parentLayout of
406+ [ case context.parentLayout of
406− Testable.IsNearby _ ->
407+ Testable.IsNearby _ ->
407− Testable.true "Nearby Element has fill width"
408+ [ Testable.true "Nearby Element has fill width"
408− ((floor context.parent.bbox.width == floor context.self.bbox.width)
409+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
409− || minMaxTest (floor context.self.bbox.width)
410+ || minMaxTest (floor context.self.bbox.width)
410− )
411+ )
411−
412+ ]
412− Testable.InColumn ->
413− Testable.true "Element within column has fill width"
414− ((floor parentAvailableWidth == floor context.self.bbox.width)
415− || minMaxTest (floor context.self.bbox.width)
416− )
417−
418− Testable.InEl ->
419− Testable.true "Element within element has fill width" <|
420− (floor parentAvailableWidth == floor context.self.bbox.width)
421− || minMaxTest (floor context.self.bbox.width)
422
413
423− _ ->
414+ Testable.InColumn ->
424− let
415+ [ Testable.true "Element within column has fill width"
416+ ((floor parentAvailableWidth == floor context.self.bbox.width)
417+ || minMaxTest (floor context.self.bbox.width)
418+ )
419+ ]
420+
421+ Testable.InEl ->
422+ [ Testable.true "Element within element has fill width" <|
423+ (floor parentAvailableWidth == floor context.self.bbox.width)
424+ || minMaxTest (floor context.self.bbox.width)
425+ ]
426+
427+ _ ->
428+ let
425− spacePerPortion =
429+ spacePerPortion =
426− parentAvailableWidth / toFloat (List.length context.siblings + 1)
430+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
427− in
431+ in
428− Testable.true "element has fill width" <|
432+ [ Testable.true "element has fill width" <|
429− (floor spacePerPortion == floor context.self.bbox.width)
433+ (floor spacePerPortion == floor context.self.bbox.width)
430− || minMaxTest (floor context.self.bbox.width)
434+ || minMaxTest (floor context.self.bbox.width)
435+ ]
431− , Testable.lessThanOrEqual "not larger than parent"
436+ , [ Testable.lessThanOrEqual "not larger than parent"
432− context.self.bbox.width
437+ context.self.bbox.width
433− context.parent.bbox.width
438+ context.parent.bbox.width
439+ ]
440+ , case context.selfElement of
441+ Testable.Paragraph _ _ ->
442+ -- A paragraph with width fill
443+ -- we want to test for correct text wrapping here.
444+ --
445+ let
446+ childWidth child =
447+ child.bbox.width
448+
449+ totalChildren =
450+ context.children
451+ |> List.map childWidth
452+ |> List.append (List.map .width context.self.textMetrics)
453+ |> List.sum
454+
455+ horizontalPadding =
456+ context.self.bbox.padding.left + context.self.bbox.padding.right
457+
458+ totalCalculatedWidth =
459+ totalChildren + horizontalPadding
460+
461+ expectedLines =
462+ ceiling (totalCalculatedWidth / context.self.bbox.width)
463+ in
464+ [ Testable.rounded "text wrapping, checking height"
465+ { expected = toFloat (expectedLines * 22)
466+ , found = context.self.bbox.height
467+ }
468+ ]
469+
470+ _ ->
471+ []
434− ]
472+ ]
435 }
473 }
436
474
437 Shrink ->
475 Shrink ->
@@ -460,8 +498,16 @@ widthHelper maybeMin maybeMax len =
460
498
461 horizontalPadding =
499 horizontalPadding =
462 context.self.bbox.padding.left + context.self.bbox.padding.right
500 context.self.bbox.padding.left + context.self.bbox.padding.right
501+
502+ _ =
503+ Debug.log "widths"
504+ { children =
505+ context.children
506+ |> List.map childWidth
507+ , text = List.map .width context.self.textMetrics
508+ }
463 in
509 in
464− [ expectRoundedEquality
510+ [ Testable.rounded "equals children"
465 { expected = totalChildren + horizontalPadding
511 { expected = totalChildren + horizontalPadding
466 , found = context.self.bbox.width
512 , found = context.self.bbox.width
467 }
513 }
@@ -746,9 +792,11 @@ heightHelper maybeMin maybeMax len =
746 -- |> List.sum
792 -- |> List.sum
747 -- TODO: apparently the font metrics we have are for the literal characters rendered
793 -- TODO: apparently the font metrics we have are for the literal characters rendered
748 -- not for the font itself.
794 -- not for the font itself.
749− -- so for now, we are stubbing this in as 20, which is the default font size.
795+ -- so for now, we are stubbing this in as 20, which is the default font size + line height.
750− Testable.true "expected multiple of 20"
796+ Testable.rounded "expected multiple of 20"
751− ((round context.self.bbox.height |> modBy 20) == 0)
797+ { expected = context.self.bbox.height
798+ , found = toFloat (List.length context.self.textMetrics * 20)
799+ }
752
800
753 else
801 else
754 expectRoundedEquality
802 expectRoundedEquality