git.iko.soy/typeable/elm-ui
on master help sign in
capture safari issue
commit9f9f9bbd201abc9f8bb20e5637208a30e2c57348 authorElm UI Automation <automation@elm-ui.com> dateWed 13 May 2020, 23:12 (6 years ago) parentdc6feb8
2 files changed+89−33
tests-rendering/src/Testable.elm+8 tests-rendering/src/Testable/Element.elm+81−33
tests-rendering/src/Testable.elm+8
@@ -21,6 +21,7 @@ module Testable exposing
2121 , getSpacing
2222 , getSpacingFromAttributes
2323 , lessThanOrEqual
24+ , rounded
2425 , runTests
2526 , textHeight
2627 , toElement
@@ -264,6 +265,13 @@ lessThanOrEqual label one two =
264265 }
265266
266267
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+
267275equal : a -> a -> LayoutExpectation
268276equal one two =
269277 Expect
tests-rendering/src/Testable/Element.elm+81−33
@@ -402,36 +402,74 @@ widthHelper maybeMin maybeMax len =
402402 parentAvailableWidth =
403403 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
404404 in
405− [ case context.parentLayout of
406− Testable.IsNearby _ ->
407− Testable.true "Nearby Element has fill width"
408− ((floor context.parent.bbox.width == floor context.self.bbox.width)
409− || minMaxTest (floor context.self.bbox.width)
410− )
411−
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)
405+ List.concat
406+ [ case context.parentLayout of
407+ Testable.IsNearby _ ->
408+ [ Testable.true "Nearby Element has fill width"
409+ ((floor context.parent.bbox.width == floor context.self.bbox.width)
410+ || minMaxTest (floor context.self.bbox.width)
411+ )
412+ ]
422413
423− _ ->
424− let
425− spacePerPortion =
426− parentAvailableWidth / toFloat (List.length context.siblings + 1)
427− in
428− Testable.true "element has fill width" <|
429− (floor spacePerPortion == floor context.self.bbox.width)
430− || minMaxTest (floor context.self.bbox.width)
431− , Testable.lessThanOrEqual "not larger than parent"
432− context.self.bbox.width
433− context.parent.bbox.width
434− ]
414+ Testable.InColumn ->
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
429+ spacePerPortion =
430+ parentAvailableWidth / toFloat (List.length context.siblings + 1)
431+ in
432+ [ Testable.true "element has fill width" <|
433+ (floor spacePerPortion == floor context.self.bbox.width)
434+ || minMaxTest (floor context.self.bbox.width)
435+ ]
436+ , [ Testable.lessThanOrEqual "not larger than parent"
437+ context.self.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+ []
472+ ]
435473 }
436474
437475 Shrink ->
@@ -460,8 +498,16 @@ widthHelper maybeMin maybeMax len =
460498
461499 horizontalPadding =
462500 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+ }
463509 in
464− [ expectRoundedEquality
510+ [ Testable.rounded "equals children"
465511 { expected = totalChildren + horizontalPadding
466512 , found = context.self.bbox.width
467513 }
@@ -746,9 +792,11 @@ heightHelper maybeMin maybeMax len =
746792 -- |> List.sum
747793 -- TODO: apparently the font metrics we have are for the literal characters rendered
748794 -- not for the font itself.
749− -- so for now, we are stubbing this in as 20, which is the default font size.
750− Testable.true "expected multiple of 20"
751− ((round context.self.bbox.height |> modBy 20) == 0)
795+ -- so for now, we are stubbing this in as 20, which is the default font size + line height.
796+ Testable.rounded "expected multiple of 20"
797+ { expected = context.self.bbox.height
798+ , found = toFloat (List.length context.self.textMetrics * 20)
799+ }
752800
753801 else
754802 expectRoundedEquality