mirror of
https://github.com/mdgriffith/elm-ui.git
synced 2024-11-29 15:24:07 +03:00
fix spacing calculation for width
This commit is contained in:
parent
c40b207654
commit
d188db23a7
@ -10,6 +10,7 @@ const http = require("http");
|
|||||||
var filepath = null;
|
var filepath = null;
|
||||||
program
|
program
|
||||||
.option("--run", "run all the tests")
|
.option("--run", "run all the tests")
|
||||||
|
.option("--debug", "run with debug on")
|
||||||
.arguments("<filepath>")
|
.arguments("<filepath>")
|
||||||
.action(function (p) {
|
.action(function (p) {
|
||||||
filepath = path.join("./cases/open", p);
|
filepath = path.join("./cases/open", p);
|
||||||
@ -17,7 +18,7 @@ program
|
|||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
if (filepath == null) {
|
if (filepath == null && !program.run) {
|
||||||
console.log("Open Cases");
|
console.log("Open Cases");
|
||||||
console.log("");
|
console.log("");
|
||||||
fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
|
fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
|
||||||
@ -29,13 +30,13 @@ program
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (program.run) {
|
if (program.run) {
|
||||||
filepath = "src/";
|
filepath = "./src/Tests/Run.elm";
|
||||||
}
|
}
|
||||||
console.log("Compiling tests");
|
console.log("Compiling tests");
|
||||||
let content = await build.compile_to_string({
|
let content = await build.compile_to_string({
|
||||||
template: "./tests-rendering/automation/templates/gather-styles.html",
|
template: "./tests-rendering/automation/templates/gather-styles.html",
|
||||||
elm: filepath,
|
elm: filepath,
|
||||||
elmOptions: { cwd: "./tests-rendering" },
|
elmOptions: { cwd: "./tests-rendering", debug: program.debug },
|
||||||
});
|
});
|
||||||
console.log("Finished compiling");
|
console.log("Finished compiling");
|
||||||
// console.log(content);
|
// console.log(content);
|
||||||
@ -45,7 +46,7 @@ program
|
|||||||
content = build.compile_to_string({
|
content = build.compile_to_string({
|
||||||
template: "./tests-rendering/automation/templates/gather-styles.html",
|
template: "./tests-rendering/automation/templates/gather-styles.html",
|
||||||
elm: filepath,
|
elm: filepath,
|
||||||
elmOptions: { cwd: "./tests-rendering" },
|
elmOptions: { cwd: "./tests-rendering", debug: program.debug },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.log("Serving on http://localhost:8080");
|
console.log("Serving on http://localhost:8080");
|
||||||
|
@ -19,6 +19,7 @@ module Testable exposing
|
|||||||
, formatColorWithAlpha
|
, formatColorWithAlpha
|
||||||
, getIds
|
, getIds
|
||||||
, getSpacing
|
, getSpacing
|
||||||
|
, getSpacingFromAttributes
|
||||||
, runTests
|
, runTests
|
||||||
, textHeight
|
, textHeight
|
||||||
, toElement
|
, toElement
|
||||||
@ -481,6 +482,10 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
|
|||||||
|
|
||||||
id =
|
id =
|
||||||
levelToString level
|
levelToString level
|
||||||
|
|> Debug.log "id"
|
||||||
|
|
||||||
|
_ =
|
||||||
|
Debug.log "element" element
|
||||||
|
|
||||||
testChildren : Found -> List (Element msg) -> List LayoutTest
|
testChildren : Found -> List (Element msg) -> List LayoutTest
|
||||||
testChildren found children =
|
testChildren found children =
|
||||||
@ -620,6 +625,7 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
|
|||||||
|
|
||||||
attributeTests =
|
attributeTests =
|
||||||
attributes
|
attributes
|
||||||
|
|> Debug.log "attributes"
|
||||||
|> List.indexedMap
|
|> List.indexedMap
|
||||||
-- Found -> Dict String Found -> List Int -> Int -> Surroundings -> Attr msg -> List Test
|
-- Found -> Dict String Found -> List Int -> Int -> Surroundings -> Attr msg -> List Test
|
||||||
(\i attr ->
|
(\i attr ->
|
||||||
@ -698,8 +704,13 @@ createAttributeTest :
|
|||||||
-> List LayoutTest
|
-> List LayoutTest
|
||||||
createAttributeTest parent cache level attrIndex surroundings attr =
|
createAttributeTest parent cache level attrIndex surroundings attr =
|
||||||
let
|
let
|
||||||
|
_ =
|
||||||
|
Debug.log "attribute test" attr
|
||||||
|
|
||||||
domId =
|
domId =
|
||||||
"#" ++ levelToString level
|
"#"
|
||||||
|
++ levelToString level
|
||||||
|
|> Debug.log "domid"
|
||||||
in
|
in
|
||||||
case attr of
|
case attr of
|
||||||
Attr _ ->
|
Attr _ ->
|
||||||
@ -739,7 +750,7 @@ createAttributeTest parent cache level attrIndex surroundings attr =
|
|||||||
|
|
||||||
Batch batch ->
|
Batch batch ->
|
||||||
batch
|
batch
|
||||||
|> List.indexedMap (\i attribute -> createAttributeTest parent cache (attrIndex :: level) i surroundings attribute)
|
|> List.indexedMap (\i attribute -> createAttributeTest parent cache level i surroundings attribute)
|
||||||
|> List.concat
|
|> List.concat
|
||||||
|
|
||||||
LabeledTest { label, test } ->
|
LabeledTest { label, test } ->
|
||||||
@ -812,6 +823,21 @@ formatColor (Internal.Rgba red green blue alpha) =
|
|||||||
++ ")"
|
++ ")"
|
||||||
|
|
||||||
|
|
||||||
|
getSpacingFromAttributes attrs =
|
||||||
|
case attrs of
|
||||||
|
[] ->
|
||||||
|
0
|
||||||
|
|
||||||
|
(Spacing i) :: remain ->
|
||||||
|
i
|
||||||
|
|
||||||
|
(Batch batched) :: remain ->
|
||||||
|
getSpacingFromAttributes (batched ++ remain)
|
||||||
|
|
||||||
|
_ :: remain ->
|
||||||
|
getSpacingFromAttributes remain
|
||||||
|
|
||||||
|
|
||||||
getSpacing : Element msg -> Maybe Int
|
getSpacing : Element msg -> Maybe Int
|
||||||
getSpacing el =
|
getSpacing el =
|
||||||
let
|
let
|
||||||
|
@ -436,7 +436,7 @@ widthHelper maybeMin maybeMax len =
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
Testable.Row _ _ ->
|
Testable.Row rowAttrs _ ->
|
||||||
-- width of row is the sum of all children widths
|
-- width of row is the sum of all children widths
|
||||||
-- both text elements and others.
|
-- both text elements and others.
|
||||||
let
|
let
|
||||||
@ -452,11 +452,14 @@ widthHelper maybeMin maybeMax len =
|
|||||||
horizontalPadding =
|
horizontalPadding =
|
||||||
context.self.bbox.padding.left + context.self.bbox.padding.right
|
context.self.bbox.padding.left + context.self.bbox.padding.right
|
||||||
|
|
||||||
spacingValue =
|
spacingAmount =
|
||||||
toFloat context.parentSpacing * (toFloat (List.length context.children) - 1)
|
Testable.getSpacingFromAttributes rowAttrs
|
||||||
|
|
||||||
|
totalSpacing =
|
||||||
|
toFloat spacingAmount * (toFloat (List.length context.children) - 1)
|
||||||
in
|
in
|
||||||
[ expectRoundedEquality
|
[ expectRoundedEquality
|
||||||
{ expected = totalChildren + horizontalPadding + spacingValue
|
{ expected = totalChildren + horizontalPadding + totalSpacing
|
||||||
, found = context.self.bbox.width
|
, found = context.self.bbox.width
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -246,11 +246,17 @@ view model =
|
|||||||
Element.layout
|
Element.layout
|
||||||
[ Font.size 16
|
[ Font.size 16
|
||||||
, Element.inFront (Element.html (viewElementHighlight model))
|
, Element.inFront (Element.html (viewElementHighlight model))
|
||||||
|
, Element.height Element.fill
|
||||||
]
|
]
|
||||||
<|
|
<|
|
||||||
Element.row [ Element.width Element.fill ]
|
Element.row [ Element.width Element.fill, Element.height Element.fill ]
|
||||||
[ Element.el
|
[ Element.el
|
||||||
[ Element.width Element.fill
|
[ Element.width
|
||||||
|
(Element.fill
|
||||||
|
|> Element.maximum 900)
|
||||||
|
, Element.alignTop
|
||||||
|
, Element.height Element.fill
|
||||||
|
, Element.scrollbars
|
||||||
]
|
]
|
||||||
(Element.el
|
(Element.el
|
||||||
[ Element.centerX
|
[ Element.centerX
|
||||||
@ -273,6 +279,8 @@ view model =
|
|||||||
[ Element.spacing 20
|
[ Element.spacing 20
|
||||||
, Element.padding 20
|
, Element.padding 20
|
||||||
, Element.width Element.fill
|
, Element.width Element.fill
|
||||||
|
, Element.height Element.fill
|
||||||
|
, Element.scrollbarY
|
||||||
]
|
]
|
||||||
(List.map viewResult (finished :: remaining))
|
(List.map viewResult (finished :: remaining))
|
||||||
]
|
]
|
||||||
@ -292,7 +300,7 @@ viewElementHighlight model =
|
|||||||
Just highlightDomId ->
|
Just highlightDomId ->
|
||||||
let
|
let
|
||||||
elementHighlight =
|
elementHighlight =
|
||||||
highlightDomId ++ " { outline: solid; }"
|
highlightDomId ++ " { outline: solid black; }"
|
||||||
|
|
||||||
testId =
|
testId =
|
||||||
highlightDomId
|
highlightDomId
|
||||||
@ -300,7 +308,7 @@ viewElementHighlight model =
|
|||||||
|> String.append "#tests-"
|
|> String.append "#tests-"
|
||||||
|
|
||||||
testHighlight =
|
testHighlight =
|
||||||
testId ++ " { outline: dashed; }"
|
testId ++ " { outline: dashed black; }"
|
||||||
|
|
||||||
styleSheet =
|
styleSheet =
|
||||||
String.join "\n"
|
String.join "\n"
|
||||||
|
@ -5,7 +5,7 @@ module Tests.Basic exposing (view)
|
|||||||
import Element as Actual
|
import Element as Actual
|
||||||
import Html
|
import Html
|
||||||
import Testable
|
import Testable
|
||||||
import Testable.Element as Element exposing (..)
|
import Testable.Element exposing (..)
|
||||||
import Testable.Element.Background as Background
|
import Testable.Element.Background as Background
|
||||||
import Testable.Element.Font as Font
|
import Testable.Element.Font as Font
|
||||||
import Testable.Runner
|
import Testable.Runner
|
||||||
|
Loading…
Reference in New Issue
Block a user