adjust tests to be mor sensitive to text wrapping

This commit is contained in:
Elm UI Automation 2020-05-16 10:44:46 -04:00
parent 1ed9f79d94
commit d5c8a943ea
7 changed files with 300 additions and 178 deletions

View File

@ -162,6 +162,9 @@ type LayoutContext
| InRow
| InEl
| InColumn
| InParagraph
| InTextCol
| AtRoot
type alias Surroundings msg =
@ -491,7 +494,7 @@ runTests harvested el =
, parentSpacing = 0
, level = [ 0, 0 ]
, element = el
, location = InEl
, location = AtRoot
}
@ -590,10 +593,10 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
InColumn
TextColumn _ _ ->
InColumn
InTextCol
Paragraph _ _ ->
InRow
InParagraph
Text _ ->
InEl

View File

@ -307,6 +307,11 @@ paddingXY x y =
}
listIf ls =
List.filter Tuple.first ls
|> List.map Tuple.second
widthHelper maybeMin maybeMax len =
let
addMin l =
@ -465,12 +470,31 @@ widthHelper maybeMin maybeMax len =
totalChildren + horizontalPadding
expectedLines =
ceiling (totalCalculatedWidth / context.self.bbox.width)
if boxChildrenHeight > 20 then
ceiling (boxChildrenHeight / 20)
else
ceiling (totalCalculatedWidth / context.self.bbox.width)
boxChildrenHeight =
context.children
|> List.map
(\c ->
c.bbox.height
)
|> List.sum
in
[ Testable.rounded "text wrapping, checking height"
{ expected = toFloat (expectedLines * 22)
, found = context.self.bbox.height
}
[ Testable.true "text wrapping, checking height"
-- all we're doing here is testing if wrapping is occurring
-- not the exact height, which is a little tricky to calculate perfectly without more information.
(if expectedLines > 1 then
context.self.bbox.height >= (20 * 2)
else
-- then it's less than 2 ~ line heights
-- there's some weird variance here which makes it hard to be exact.
context.self.bbox.height < (20 * 2)
)
]
_ ->
@ -504,23 +528,21 @@ widthHelper maybeMin maybeMax len =
horizontalPadding =
context.self.bbox.padding.left + context.self.bbox.padding.right
_ =
Debug.log "widths"
{ children =
context.children
|> List.map childWidth
, text = List.map .width context.self.textMetrics
}
in
[ Testable.rounded "equals children"
{ expected = totalChildren + horizontalPadding
, found = context.self.bbox.width
}
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
]
listIf
[ ( (context.parentLayout /= Testable.InParagraph)
&& (context.parentLayout /= Testable.InTextCol)
, Testable.rounded "equals children"
{ expected = totalChildren + horizontalPadding
, found = context.self.bbox.width
}
)
, ( context.parentLayout /= Testable.AtRoot
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
)
]
Testable.Row rowAttrs _ ->
-- width of row is the sum of all children widths
@ -544,14 +566,19 @@ widthHelper maybeMin maybeMax len =
totalSpacing =
toFloat spacingAmount * (toFloat (List.length context.children) - 1)
in
[ expectRoundedEquality
{ expected = totalChildren + horizontalPadding + totalSpacing
, found = context.self.bbox.width
}
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
]
listIf
[ ( True
, expectRoundedEquality
{ expected = totalChildren + horizontalPadding + totalSpacing
, found = context.self.bbox.width
}
)
, ( context.parentLayout /= Testable.AtRoot
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
)
]
Testable.Column _ _ ->
-- The width of the column is the width of the widest child.
@ -575,14 +602,19 @@ widthHelper maybeMin maybeMax len =
|> List.map childWidth
|> List.append textChildren
in
[ expectRoundedEquality
{ expected = Maybe.withDefault 0 (List.maximum allChildren)
, found = context.self.bbox.width
}
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
]
listIf
[ ( True
, expectRoundedEquality
{ expected = Maybe.withDefault 0 (List.maximum allChildren)
, found = context.self.bbox.width
}
)
, ( context.parentLayout /= Testable.AtRoot
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
)
]
Testable.TextColumn _ _ ->
-- The width of the column is the width of the widest child.
@ -606,14 +638,19 @@ widthHelper maybeMin maybeMax len =
|> List.map childWidth
|> List.append textChildren
in
[ expectRoundedEquality
{ expected = Maybe.withDefault 0 (List.maximum allChildren)
, found = context.self.bbox.width
}
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
]
listIf
[ ( True
, expectRoundedEquality
{ expected = Maybe.withDefault 0 (List.maximum allChildren)
, found = context.self.bbox.width
}
)
, ( context.parentLayout /= Testable.AtRoot
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
)
]
Testable.Paragraph _ _ ->
-- This should be the size it's text,
@ -631,14 +668,19 @@ widthHelper maybeMin maybeMax len =
horizontalPadding =
context.self.bbox.padding.left + context.self.bbox.padding.right
in
[ expectRoundedEquality
{ expected = totalChildren + horizontalPadding
, found = context.self.bbox.width
}
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
]
listIf
[ ( True
, expectRoundedEquality
{ expected = totalChildren + horizontalPadding
, found = context.self.bbox.width
}
)
, ( context.parentLayout /= Testable.AtRoot
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.width
context.parent.bbox.width
)
]
Testable.Text _ ->
[]
@ -792,20 +834,17 @@ heightHelper maybeMin maybeMax len =
childHeight child =
child.bbox.height
in
[ if List.isEmpty context.children then
if List.isEmpty context.children then
-- context.self.textMetrics
-- |> List.map Testable.textHeight
-- |> List.sum
-- TODO: apparently the font metrics we have are for the literal characters rendered
-- not for the font itself.
-- so for now, we are stubbing this in as 20, which is the default font size + line height.
Testable.rounded "expected multiple of 20"
{ expected = context.self.bbox.height
, found = toFloat (List.length context.self.textMetrics * 20)
}
[ Testable.todo "calculate height from actual text metrics"
]
else
expectRoundedEquality
else
[ expectRoundedEquality
{ expected =
context.children
|> List.map childHeight
@ -813,28 +852,26 @@ heightHelper maybeMin maybeMax len =
|> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
, found = context.self.bbox.height
}
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.height
context.parent.bbox.height
]
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.height
context.parent.bbox.height
]
Testable.Row _ _ ->
let
childHeight child =
child.bbox.height
in
[ if List.isEmpty context.children then
if List.isEmpty context.children then
-- context.self.textMetrics
-- |> List.map Testable.textHeight
-- |> List.sum
-- TODO: apparently the font metrics we have are for the literal characters rendered
-- not for the font itself.
-- so for now, we are stubbing this in as 20, which is the default font size.
Testable.true "expected multiple of 20"
((round context.self.bbox.height |> modBy 20) == 0)
[ Testable.todo "calculate height from actual text metrics" ]
else
expectRoundedEquality
else
[ expectRoundedEquality
{ expected =
context.children
|> List.map childHeight
@ -843,10 +880,10 @@ heightHelper maybeMin maybeMax len =
|> (\h -> h + context.self.bbox.padding.top + context.self.bbox.padding.bottom)
, found = context.self.bbox.height
}
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.height
context.parent.bbox.height
]
, Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.height
context.parent.bbox.height
]
Testable.Column colAttrs _ ->
let
@ -878,16 +915,10 @@ heightHelper maybeMin maybeMax len =
]
Testable.TextColumn _ _ ->
[ Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.height
context.parent.bbox.height
]
[]
Testable.Paragraph _ _ ->
[ Testable.lessThanOrEqual "not larger than parent"
context.self.bbox.height
context.parent.bbox.height
]
[]
Testable.Text _ ->
[]

View File

@ -20,37 +20,38 @@ element : String -> List (Testable.Attr msg) -> List ( String, Testable.Element
element label attrs =
-- [ ( label, paragraph attrs [ short ] )
-- ]
mapEveryCombo
(\makeLayout child ->
( label, makeLayout attrs child )
mapEveryCombo3
(\( layoutLabel, makeLayout ) ( selfLabel, makeSelf ) ( childLabel, child ) ->
( label ++ " - " ++ layoutLabel ++ " > " ++ selfLabel ++ " > " ++ childLabel
, makeLayout [] (makeSelf attrs child)
)
)
layouts
layouts
contents
mapEveryCombo fn listOne listTwo =
List.concatMap
(\one ->
List.map
(\two ->
fn one two
)
listTwo
)
listOne
layouts =
[ \attrs child ->
el attrs child
, \attrs child ->
row attrs [ child ]
, \attrs child ->
column attrs [ child ]
, \attrs child ->
paragraph attrs [ child ]
, \attrs child ->
textColumn attrs [ child ]
[ ( "el"
, \attrs child ->
el attrs child
)
, ( "row"
, \attrs child ->
row attrs [ child ]
)
, ( "col"
, \attrs child ->
column attrs [ child ]
)
, ( "para"
, \attrs child ->
paragraph attrs [ child ]
)
, ( "txtCol"
, \attrs child ->
textColumn attrs [ child ]
)
]
@ -65,17 +66,23 @@ nearbys =
contents =
[ none
, text short
, text lorem
, el
[ ( "none", none )
, ( "short text", text short )
, ( "long text", text lorem )
, ( "box"
, box
)
]
box =
el
[ width (px 50)
, height (px 50)
, Background.color (rgb (240 / 255) 0 (245 / 255))
, Font.color (rgb 1 1 1)
]
none
]
short =
@ -84,3 +91,75 @@ short =
lorem =
"There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc."
mapEveryCombo fn listOne listTwo =
List.concatMap
(\one ->
List.map
(\two ->
fn one two
)
listTwo
)
listOne
mapEveryCombo3 fn listOne listTwo listThree =
List.concatMap
(\one ->
List.concatMap
(\two ->
List.map
(\three ->
fn one two three
)
listThree
)
listTwo
)
listOne
sizes render =
List.concatMap
(\( widthLen, heightLen ) ->
[ text (Debug.toString ( widthLen, heightLen ))
, render
(\attrs children ->
el
(width widthLen
:: height heightLen
:: attrs
)
children
)
]
)
allLengthPairs
allLengthPairs : List ( Length, Length )
allLengthPairs =
let
crossProduct len =
List.map (Tuple.pair len) lengths
in
List.concatMap crossProduct lengths
lengths =
[ px 50
, fill
, shrink
, fill
|> maximum 100
, fill
|> maximum 100
|> minimum 50
, shrink
|> maximum 100
, shrink
|> maximum 100
|> minimum 50
]

View File

@ -3,9 +3,9 @@ port module Testable.Runner exposing
, Testable
, TestableProgram
, program
, rename
, show
, testable
, rename
)
{-| -}
@ -108,7 +108,8 @@ type alias Model msg =
type alias WithResults thing =
{ element : thing
{ index : Int
, element : thing
, label : String
, results :
List Testable.LayoutTest
@ -170,13 +171,14 @@ type Msg
)
runTest : Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
runTest boxes label element =
runTest : Int -> Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
runTest index boxes label element =
let
results =
Testable.runTests boxes element
in
{ element = element
{ index = index
, element = element
, label = label
, results = results
}
@ -222,7 +224,7 @@ update msg model =
|> Dict.fromList
currentResults =
runTest foundData label current
runTest (List.length model.finished) foundData label current
in
case model.upcoming of
[] ->
@ -267,8 +269,6 @@ view model =
let
selected =
getByIndex model.selected model.finished
-- |> Debug.log "selected"
in
Element.layout
[ Font.size 16
@ -316,7 +316,10 @@ view model =
, Element.height Element.fill
, Element.scrollbarY
]
(List.indexedMap (viewResult model.selected) model.finished)
(model.finished
|> List.sortBy hasFailure
|> List.map (viewResult model.selected)
)
]
else
@ -370,9 +373,35 @@ viewElementHighlight model =
]
viewResult : Int -> Int -> WithResults (Testable.Element Msg) -> Element.Element Msg
viewResult selectedIndex index myTest =
if index == selectedIndex then
hasFailure : WithResults (Testable.Element Msg) -> Int
hasFailure myTest =
if
List.any
(not << isPassing)
myTest.results
then
0
else
1
isExpectationPassing result =
case result of
Testable.Todo label ->
True
Testable.Expect details ->
details.result
isPassing layoutTest =
List.all isExpectationPassing layoutTest.expectations
viewResult : Int -> WithResults (Testable.Element Msg) -> Element.Element Msg
viewResult selectedIndex myTest =
if myTest.index == selectedIndex then
Element.column
[ Element.alignLeft
, Element.spacing 16
@ -388,17 +417,6 @@ viewResult selectedIndex index myTest =
else
let
isExpectationPassing result =
case result of
Testable.Todo label ->
True
Testable.Expect details ->
details.result
isPassing layoutTest =
List.all isExpectationPassing layoutTest.expectations
( passing, failing ) =
List.partition isPassing myTest.results
in
@ -406,10 +424,10 @@ viewResult selectedIndex index myTest =
[ Element.alignLeft
, Element.spacing 16
, Element.pointer
, Events.onClick (Select index)
, Events.onClick (Select myTest.index)
]
[ Element.row [ Element.spacing 16 ]
[ Element.el [ Font.size 24 ] (Element.text myTest.label)
[ Element.el [ Font.size 16 ] (Element.text myTest.label)
, Element.text (String.fromInt (List.length passing) ++ " passing")
, let
failingCount =

View File

@ -18,7 +18,9 @@ import Tests.Transparency
main : Testable.Runner.TestableProgram
main =
(Testable.Runner.program << List.concat)
[ -- Testable.Generator.element "Basics" []
[ --Testable.Generator.element "Basics"
--[]
-- , Testable.Generator.element "Align " []
-- Tuple.pair "Basic Element" Tests.Basic.view
-- , Tuple.pair "Nearby" Tests.Nearby.view
-- , Tuple.pair "Element Alignment" Tests.ElementAlignment.view

View File

@ -1,32 +1,14 @@
module Tests.Run exposing (main)
{-| -}
{-| _NOTE_ this is auto-generated! Notouchy!
-}
import Testable.Generator
import ElInFixedHeightColumn
import Testable.Runner
import Tests.Basic
import Tests.ColumnAlignment
import Tests.ColumnSpacing
import Tests.ElementAlignment
import Tests.Nearby
import Tests.RowAlignment
import Tests.RowSpacing
import Tests.TextWrapping
import Tests.Transparency
main : Testable.Runner.TestableProgram
main =
(Testable.Runner.program << List.concat)
[ -- Testable.Generator.element "Basics" []
-- Tuple.pair "Basic Element" Tests.Basic.view
-- , Tuple.pair "Nearby" Tests.Nearby.view
-- , Tuple.pair "Element Alignment" Tests.ElementAlignment.view
-- , Tuple.pair "Transparency" Tests.Transparency.view
-- , Tuple.pair "Column Alignment" Tests.ColumnAlignment.view
-- -- This has 12k cases, so it runs slow and sometimes crashes IE
-- , Tuple.pair "Row Alignment" Tests.RowAlignment.view
-- , Tuple.pair "Column Spacing" Tests.ColumnSpacing.view
-- , Tuple.pair "Row Spacing" Tests.RowSpacing.view
[ Tuple.pair "Paragraph wrapping" Tests.TextWrapping.view ]
Testable.Runner.program
[ Testable.Runner.rename " El In Fixed Height Column" ElInFixedHeightColumn.view
]

View File

@ -28,17 +28,24 @@ main =
view =
column [ paddingXY 0 100, spacing 16 ]
[ paragraph []
[ text Testable.Generator.lorem
el [] <|
paragraph []
[ Testable.Generator.box
]
, paragraph []
[ text Testable.Generator.lorem
, text Testable.Generator.lorem
]
, paragraph []
[ text Testable.Generator.lorem
, paragraph []
[ text Testable.Generator.lorem ]
]
]
-- column [ spacing 16 ]
-- [ paragraph []
-- [ el [] (text Testable.Generator.short)
-- ]
-- -- , paragraph []
-- -- [ text Testable.Generator.lorem
-- -- , text Testable.Generator.lorem
-- -- ]
-- -- , paragraph []
-- -- [ text Testable.Generator.lorem
-- -- , paragraph []
-- -- [ text Testable.Generator.lorem ]
-- -- ]
-- ]