git.iko.soy/typeable/elm-ui
on master help sign in
redo testing interface so it's actually readable by a human.
commit639efbb5ab9e776a13dd4370307fe97424eeb3dd authorElm UI Automation <automation@elm-ui.com> dateSat 2 May 2020, 14:38 (6 years ago) parent510b32a
9 files changed+638−539
tests-rendering/automation/run.js+8−10 tests-rendering/automation/templates/gather-styles.html+105−103 tests-rendering/make.sh+1−1 tests-rendering/src/Testable.elm+160−131 tests-rendering/src/Testable/Element.elm+143−104 tests-rendering/src/Testable/Element/Background.elm+4−4 tests-rendering/src/Testable/Element/Font.elm+6−4 tests-rendering/src/Testable/Runner.elm+210−181 tests-rendering/view/view.html+1−1
tests-rendering/automation/run.js+8−10
@@ -265,31 +265,29 @@ function renderEnvName(env) {
265265 return `${env.platform}, ${env.browser} ${env.browserVersion}`;
266266}
267267
268−function print_results(label, results) {
268+function print_results(label, tests) {
269269 var total_passed = 0;
270270 var total_failed = 0;
271271 var i;
272272 if (program.verbose) {
273273 console.log(label);
274274 }
275− for (i = 0; i < results.length; i++) {
275+ for (i = 0; i < tests.length; i++) {
276276 var passed = 0;
277277 var failed = 0;
278− for (j = 0; j < results[i].results.length; j++) {
279− if (results[i].results[j][1] == null) {
278+ for (j = 0; j < tests[i].results.length; j++) {
279+ if (tests[i].results[j].passing) {
280280 passed = passed + 1;
281281 } else {
282282 if (failed == 0) {
283283 if (!program.verbose) {
284284 console.log(label);
285285 }
286− console.log(results[i].label);
286+ console.log(tests[i].label);
287287 }
288288 failed = failed + 1;
289− console.log(
290− " " + chalk.red("fail") + " -> " + results[i].results[j][0]
291− );
292− console.log(" " + results[i].results[j][1].description);
289+ console.log(" " + chalk.red("fail") + " ->");
290+ console.log(" " + tests[i].results[j][1].description);
293291 }
294292 }
295293 total_passed = total_passed + passed;
@@ -300,7 +298,7 @@ function print_results(label, results) {
300298 console.log(chalk.red(` ${failed} tests failed`));
301299 console.log();
302300 } else if (program.verbose) {
303− console.log(results[i].label + chalk.green(` ${passed} tests passed`));
301+ console.log(tests[i].label + chalk.green(` ${passed} tests passed`));
304302 }
305303 }
306304 if (total_failed == 0) {
tests-rendering/automation/templates/gather-styles.html+105−103
@@ -1,105 +1,107 @@
1−<!DOCTYPE HTML>
1+<!DOCTYPE html>
22<html>
3− <head>
4− <meta charset="UTF-8">
5− <title>Rendering Benchmark Viewer</title>
6− <script>
7− ${compiled_elm_code}
8− </script>
9− </head>
10− <style>
11− </style>
12− <body id="root"></body>
13−
14− <script type="text/javascript">
15−
16− var app = Elm.Tests.Run.init();
17−
18− var test_results = "waiting.."
19−
20− app.ports.report.subscribe(function (results) {
21− test_results = results;
22− })
23−
24− app.ports.analyze.subscribe(function (ids) {
25− // ids : List String
26− var idsLength = ids.length;
27− var results = [];
28− for (var i = 0; i < idsLength; i++) {
29− var id = ids[i];
30− var element = document.getElementById(id);
31− if (element == null) {
32− console.log("id " + id + " not found");
33− }
34− var style = getStyle(element);
35− var bbox = getBoundingBox(element);
36−
37− var visible = isVisible(id, bbox);
38−
39−
40− var result = { "bbox": bbox, "style": style, "id": id, "isVisible": visible };
41− results.push(result);
42−
43− }
44− app.ports.styles.send(results);
45− });
46−
47− function isVisible(id, bbox) {
48− var current = document.getElementById(id);
49− var result = 0;
50− if (current == document.elementFromPoint(bbox['left'], bbox['top'])) {
51− result++;
52− }
53− if (current == document.elementFromPoint(bbox['left'], bbox['bottom'] - 1)) {
54− result++;
55− }
56− if (current == document.elementFromPoint(bbox['right'] - 1, bbox['top'])) {
57− result++;
58− }
59− if (current == document.elementFromPoint(bbox['right'] - 1, bbox['bottom'] - 1)) {
60− result++;
61− }
62−
63−
64− if (result == 4) {
65− return true;
66− } else {
67− return false
68− }
69− }
70−
71− function getStyle(element) {
72− var props = []
73− var style = window.getComputedStyle(element);
74− for (var i = style.length; i--;) {
75− var name = style.item(i);
76− var value = style.getPropertyValue(name);
77− props.push([name, value]);
78− }
79− return props;
80− }
81−
82− function getBoundingBox(element) {
83− var bbox = element.getBoundingClientRect();
84− var style = window.getComputedStyle(element, null);
85−
86− var padding = {
87− 'top': parseFloat(style.getPropertyValue('padding-top'))
88− , 'bottom': parseFloat(style.getPropertyValue('padding-bottom'))
89− , 'left': parseFloat(style.getPropertyValue('padding-left'))
90− , 'right': parseFloat(style.getPropertyValue('padding-right'))
91− };
92−
93− return {
94− 'top': bbox.top
95− , 'bottom': bbox.bottom
96− , 'left': bbox.left
97− , 'right': bbox.right
98− , 'width': bbox.width
99− , 'height': bbox.height
100− , 'padding': padding
101− }
102− }
103−
3+ <head>
4+ <meta charset="UTF-8" />
5+ <title>Rendering Benchmark Viewer</title>
6+ <script>
7+ ${compiled_elm_code}
1048 </script>
105−</html>
9+ </head>
10+ <style></style>
11+ <body id="root"></body>
12+
13+ <script type="text/javascript">
14+ var app = Elm.Tests.Run.init();
15+
16+ var test_results = "waiting..";
17+
18+ app.ports.report.subscribe(function (results) {
19+ // these are extracted by the script that runs the browser automation.
20+ test_results = results;
21+ });
22+
23+ app.ports.analyze.subscribe(function (ids) {
24+ // ids : List String
25+ var idsLength = ids.length;
26+ var results = [];
27+ for (var i = 0; i < idsLength; i++) {
28+ var id = ids[i];
29+ var element = document.getElementById(id);
30+ if (element == null) {
31+ console.log("id " + id + " not found");
32+ }
33+ var style = getStyle(element);
34+ var bbox = getBoundingBox(element);
35+
36+ var visible = isVisible(id, bbox);
37+
38+ var result = { bbox: bbox, style: style, id: id, isVisible: visible };
39+ results.push(result);
40+ }
41+ app.ports.styles.send(results);
42+ });
43+
44+ function isVisible(id, bbox) {
45+ var current = document.getElementById(id);
46+ var result = 0;
47+ if (current == document.elementFromPoint(bbox["left"], bbox["top"])) {
48+ result++;
49+ }
50+ if (
51+ current == document.elementFromPoint(bbox["left"], bbox["bottom"] - 1)
52+ ) {
53+ result++;
54+ }
55+ if (
56+ current == document.elementFromPoint(bbox["right"] - 1, bbox["top"])
57+ ) {
58+ result++;
59+ }
60+ if (
61+ current ==
62+ document.elementFromPoint(bbox["right"] - 1, bbox["bottom"] - 1)
63+ ) {
64+ result++;
65+ }
66+
67+ if (result == 4) {
68+ return true;
69+ } else {
70+ return false;
71+ }
72+ }
73+
74+ function getStyle(element) {
75+ var props = [];
76+ var style = window.getComputedStyle(element);
77+ for (var i = style.length; i--; ) {
78+ var name = style.item(i);
79+ var value = style.getPropertyValue(name);
80+ props.push([name, value]);
81+ }
82+ return props;
83+ }
84+
85+ function getBoundingBox(element) {
86+ var bbox = element.getBoundingClientRect();
87+ var style = window.getComputedStyle(element, null);
88+
89+ var padding = {
90+ top: parseFloat(style.getPropertyValue("padding-top")),
91+ bottom: parseFloat(style.getPropertyValue("padding-bottom")),
92+ left: parseFloat(style.getPropertyValue("padding-left")),
93+ right: parseFloat(style.getPropertyValue("padding-right")),
94+ };
95+
96+ return {
97+ top: bbox.top,
98+ bottom: bbox.bottom,
99+ left: bbox.left,
100+ right: bbox.right,
101+ width: bbox.width,
102+ height: bbox.height,
103+ padding: padding,
104+ };
105+ }
106+ </script>
107+</html>
tests-rendering/make.sh+1−1
@@ -1,2 +1,2 @@
11
2−elm-live cases/open/InFrontSize.elm --open --dir=view -- --output=view/elm.js --debug
2+elm-live cases/open/WeirdCentering.elm --dir=view -- --output=view/elm.js --debug
tests-rendering/src/Testable.elm+160−131
@@ -4,40 +4,32 @@ module Testable exposing
44 , Element(..)
55 , Found
66 , LayoutContext(..)
7+ , LayoutExpectation(..)
8+ , LayoutTest
79 , Location(..)
810 , Style
911 , Surroundings
10− , addAttribute
11− , applyLabels
1212 , compareFormattedColor
13− , createAttributeTest
14− , createTest
13+ , equal
1514 , formatColor
1615 , formatColorWithAlpha
17− , getElementId
1816 , getIds
1917 , getSpacing
20− , idAttr
21− , levelToString
22− , render
23− , renderAttribute
24− , renderElement
2518 , runTests
26− , toTest
19+ , toElement
20+ , toHtml
21+ , todo
22+ , true
2723 )
2824
2925{-| -}
3026
3127import Dict exposing (Dict)
3228import Element exposing (Color)
33−import Expect
3429import Html exposing (Html)
3530import Html.Attributes
3631import Internal.Model as Internal
37−import Random
3832import Test exposing (Test)
39−import Test.Runner
40−import Test.Runner.Failure
4133
4234
4335type Element msg
@@ -52,18 +44,20 @@ type Element msg
5244
5345type Attr msg
5446 = Attr (Element.Attribute msg)
55− | AttrTest (Surroundings -> Test)
47+ | AttrTest
48+ { test : Surroundings -> List LayoutExpectation
49+ , label : String
50+ }
5651 | Batch (List (Attr msg))
5752 | Spacing Int
5853 | Nearby
5954 { location : Location
6055 , element : Element msg
61− , test : Surroundings -> () -> Expect.Expectation
56+ , test : Surroundings -> List LayoutExpectation
6257 , label : String
6358 }
64− | Label String
6559 | LabeledTest
66− { test : Surroundings -> () -> Expect.Expectation
60+ { test : Surroundings -> List LayoutExpectation
6761 , label : String
6862 , attr : Element.Attribute msg
6963 }
@@ -125,6 +119,46 @@ type alias BoundingBox =
125119 }
126120
127121
122+type LayoutExpectation
123+ = Expect
124+ { description : String
125+ , result : Bool
126+ }
127+ | Todo String
128+
129+
130+type alias LayoutTest =
131+ { elementDomId : String
132+ , label : String
133+ , expectations : List LayoutExpectation
134+ }
135+
136+
137+
138+{- Expectations -}
139+
140+
141+equal : a -> a -> LayoutExpectation
142+equal one two =
143+ Expect
144+ { description = "Are equal"
145+ , result = one == two
146+ }
147+
148+
149+true : String -> Bool -> LayoutExpectation
150+true label passing =
151+ Expect
152+ { description = label
153+ , result = passing
154+ }
155+
156+
157+todo : String -> LayoutExpectation
158+todo =
159+ Todo
160+
161+
128162
129163{- Retrieve Ids -}
130164
@@ -183,8 +217,13 @@ getElementId level el =
183217{- Render as Html -}
184218
185219
186−render : Element msg -> Html msg
187−render el =
220+toElement : Element msg -> Element.Element msg
221+toElement el =
222+ renderElement [ 0, 0 ] el
223+
224+
225+toHtml : Element msg -> Html msg
226+toHtml el =
188227 Element.layout [ idAttr "0" ] <|
189228 renderElement [ 0, 0 ] el
190229
@@ -253,9 +292,6 @@ renderAttribute level attrIndex attr =
253292 Spacing _ ->
254293 []
255294
256− Label _ ->
257− []
258−
259295 Nearby { location, element } ->
260296 case location of
261297 Above ->
@@ -288,30 +324,35 @@ renderAttribute level attrIndex attr =
288324{- Convert to Test -}
289325
290326
291−toTest : String -> Dict String Found -> Element msg -> Test
292−toTest label harvested el =
327+runTests : Dict String Found -> Element msg -> List LayoutTest
328+runTests harvested el =
293329 let
294330 maybeFound =
295331 Dict.get "se-0" harvested
296332 in
297333 case maybeFound of
298334 Nothing ->
299− Test.describe label
300− [ Test.test "Find Root" <|
301− \_ -> Expect.fail "unable to find root"
302− ]
335+ [ { elementDomId = "se-0"
336+ , label = "Finding root element"
337+ , expectations =
338+ [ Expect
339+ { description = "Locating root element for rendering tests"
340+ , result = False
341+ }
342+ ]
343+ }
344+ ]
303345
304346 Just root ->
305− Test.describe label <|
306− createTest
307− { siblings = []
308− , parent = root
309− , cache = harvested
310− , parentSpacing = 0
311− , level = [ 0, 0 ]
312− , element = el
313− , location = InEl
314− }
347+ createTest
348+ { siblings = []
349+ , parent = root
350+ , cache = harvested
351+ , parentSpacing = 0
352+ , level = [ 0, 0 ]
353+ , element = el
354+ , location = InEl
355+ }
315356
316357
317358levelToString : List Int -> String
@@ -331,7 +372,7 @@ createTest :
331372 , location : LayoutContext
332373 , parentSpacing : Int
333374 }
334− -> List Test
375+ -> List LayoutTest
335376createTest { siblings, parent, cache, level, element, location, parentSpacing } =
336377 let
337378 spacing =
@@ -341,7 +382,7 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
341382 id =
342383 levelToString level
343384
344− testChildren : Found -> List (Element msg) -> List Test
385+ testChildren : Found -> List (Element msg) -> List LayoutTest
345386 testChildren found children =
346387 let
347388 childrenFound =
@@ -369,13 +410,13 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
369410 { a
370411 | index : Int
371412 , previous : List Found
372− , tests : List Test
413+ , tests : List LayoutTest
373414 , upcoming : List Found
374415 }
375416 ->
376417 { index : Int
377418 , previous : List Found
378− , tests : List Test
419+ , tests : List LayoutTest
379420 , upcoming : List Found
380421 }
381422 applyChildTest found child childTest =
@@ -439,7 +480,7 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
439480 rest
440481 }
441482
442− tests : Found -> List (Attr msg) -> List (Element msg) -> List Test
483+ tests : Found -> List (Attr msg) -> List (Element msg) -> List LayoutTest
443484 tests self attributes children =
444485 let
445486 findBBox elem ( i, gathered ) =
@@ -479,7 +520,6 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
479520
480521 attributeTests =
481522 attributes
482− |> applyLabels
483523 |> List.indexedMap
484524 -- Found -> Dict String Found -> List Int -> Int -> Surroundings -> Attr msg -> List Test
485525 (\i attr ->
@@ -511,7 +551,16 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
511551 []
512552
513553 _ ->
514− [ Test.test ("Unable to find " ++ id) (always <| Expect.fail "failed id lookup") ]
554+ [ { elementDomId = id
555+ , label = "Finding element in DOM"
556+ , expectations =
557+ [ Expect
558+ { description = "Locating element for rendering test"
559+ , result = False
560+ }
561+ ]
562+ }
563+ ]
515564
516565 Just self ->
517566 case element of
@@ -537,59 +586,31 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
537586 []
538587
539588
540−applyLabels : List (Attr msg) -> List (Attr msg)
541−applyLabels attrs =
542− let
543− toLabel attr =
544− case attr of
545− Label label ->
546− Just label
547−
548− _ ->
549− Nothing
550−
551− newLabels =
552− attrs
553− |> List.filterMap toLabel
554− |> String.join ", "
555−
556− applyLabel newLabel attr =
557− case attr of
558− LabeledTest labeled ->
559− LabeledTest
560− { labeled
561− | label =
562− if newLabel == "" then
563− labeled.label
564−
565− else
566− newLabel ++ ", " ++ labeled.label
567− }
568−
569− x ->
570− x
571− in
572− List.map (applyLabel newLabels) attrs
573−
574−
575−createAttributeTest : Found -> Dict String Found -> List Int -> Int -> Surroundings -> Attr msg -> List Test
589+createAttributeTest :
590+ Found
591+ -> Dict String Found
592+ -> List Int
593+ -> Int
594+ -> Surroundings
595+ -> Attr msg
596+ -> List LayoutTest
576597createAttributeTest parent cache level attrIndex surroundings attr =
577598 let
578− indexLabel =
579− levelToString (attrIndex :: level)
599+ domId =
600+ "#" ++ levelToString level
580601 in
581602 case attr of
582603 Attr _ ->
583604 []
584605
585− Label _ ->
586− []
587−
588606 Spacing _ ->
589607 []
590608
591− AttrTest test ->
592− [ test surroundings
609+ AttrTest details ->
610+ [ { elementDomId = domId
611+ , label = details.label
612+ , expectations = details.test surroundings
613+ }
593614 ]
594615
595616 Nearby nearby ->
@@ -600,7 +621,15 @@ createAttributeTest parent cache level attrIndex surroundings attr =
600621 , parentSpacing = 0
601622 , level = attrIndex :: -1 :: level
602623 , location = IsNearby nearby.location
603− , element = addAttribute (AttrTest (\context -> Test.test (nearby.label ++ " #" ++ indexLabel) (nearby.test context))) nearby.element
624+ , element =
625+ addAttribute
626+ (AttrTest
627+ { label = nearby.label
628+ , test =
629+ nearby.test
630+ }
631+ )
632+ nearby.element
604633 }
605634
606635 Batch batch ->
@@ -609,7 +638,10 @@ createAttributeTest parent cache level attrIndex surroundings attr =
609638 |> List.concat
610639
611640 LabeledTest { label, test } ->
612− [ Test.test (label ++ " #" ++ indexLabel) (test surroundings)
641+ [ { elementDomId = domId
642+ , label = label
643+ , expectations = test surroundings
644+ }
613645 ]
614646
615647
@@ -638,46 +670,43 @@ addAttribute attr el =
638670 Text str
639671
640672
641−runTests :
642− Random.Seed
643− -> Test
644− ->
645− List
646− ( String
647− , Maybe
648− { given : Maybe String
649− , description : String
650− , reason : Test.Runner.Failure.Reason
651− }
652− )
653−runTests seed tests =
654− let
655− run runner =
656− let
657− ran =
658− List.map Test.Runner.getFailureReason (runner.run ())
659− in
660− List.map2 Tuple.pair runner.labels ran
661−
662− results =
663− case Test.Runner.fromTest 100 seed tests of
664− Test.Runner.Plain rnrs ->
665− List.map run rnrs
666−
667− Test.Runner.Only rnrs ->
668− List.map run rnrs
669673
670− Test.Runner.Skipping rnrs ->
671− List.map run rnrs
672−
673− Test.Runner.Invalid invalid ->
674− let
675− _ =
676− Debug.log "Invalid tests" invalid
677− in
678− []
679− in
680− List.concat results
674+-- runTests :
675+-- Random.Seed
676+-- -> Test
677+-- ->
678+-- List
679+-- ( String
680+-- , Maybe
681+-- { given : Maybe String
682+-- , description : String
683+-- , reason : Test.Runner.Failure.Reason
684+-- }
685+-- )
686+-- runTests seed tests =
687+-- let
688+-- run runner =
689+-- let
690+-- ran =
691+-- List.map Test.Runner.getFailureReason (runner.run ())
692+-- in
693+-- List.map2 Tuple.pair runner.labels ran
694+-- results =
695+-- case Test.Runner.fromTest 100 seed tests of
696+-- Test.Runner.Plain rnrs ->
697+-- List.map run rnrs
698+-- Test.Runner.Only rnrs ->
699+-- List.map run rnrs
700+-- Test.Runner.Skipping rnrs ->
701+-- List.map run rnrs
702+-- Test.Runner.Invalid invalid ->
703+-- let
704+-- _ =
705+-- Debug.log "Invalid tests" invalid
706+-- in
707+-- []
708+-- in
709+-- List.concat results
681710
682711
683712compareFormattedColor : Color -> String -> Bool
tests-rendering/src/Testable/Element.elm+143−104
@@ -23,6 +23,8 @@ module Testable.Element exposing
2323 , maximum
2424 , minimum
2525 , moveDown
26+ , moveLeft
27+ , moveRight
2628 , moveUp
2729 , none
2830 , onLeft
@@ -104,6 +106,12 @@ textColumn =
104106 Testable.TextColumn
105107
106108
109+{-| Old labeling mechanism that i removed to hastily
110+-}
111+label str =
112+ Testable.Batch []
113+
114+
107115moveUp x =
108116 Testable.Attr (Element.moveUp x)
109117
@@ -112,6 +120,14 @@ moveDown x =
112120 Testable.Attr (Element.moveDown x)
113121
114122
123+moveRight x =
124+ Testable.Attr (Element.moveRight x)
125+
126+
127+moveLeft x =
128+ Testable.Attr (Element.moveLeft x)
129+
130+
115131type Length
116132 = Px Int
117133 | Fill Int
@@ -156,11 +172,6 @@ fillPortion =
156172 Fill
157173
158174
159−label : String -> Testable.Attr msg
160−label =
161− Testable.Label
162−
163−
164175transparent : Bool -> Testable.Attr msg
165176transparent on =
166177 Testable.LabeledTest
@@ -172,7 +183,7 @@ transparent on =
172183 "opaque"
173184 , attr = Element.transparent on
174185 , test =
175− \context _ ->
186+ \context ->
176187 let
177188 selfTransparency =
178189 context.self.style
@@ -186,7 +197,7 @@ transparent on =
186197 else
187198 "1"
188199 in
189− Expect.equal value selfTransparency
200+ [ Testable.equal value selfTransparency ]
190201 }
191202
192203
@@ -197,8 +208,8 @@ isVisible =
197208 { label = "is-visible"
198209 , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
199210 , test =
200− \context _ ->
201− Expect.equal context.self.isVisible True
211+ \context ->
212+ [ Testable.equal context.self.isVisible True ]
202213 }
203214
204215
@@ -209,14 +220,14 @@ alpha a =
209220 { label = "alpha-" ++ String.fromFloat a
210221 , attr = Element.alpha a
211222 , test =
212− \context _ ->
223+ \context ->
213224 let
214225 selfTransparency =
215226 context.self.style
216227 |> Dict.get "opacity"
217228 |> Maybe.withDefault "notfound"
218229 in
219− Expect.equal (String.fromFloat a) selfTransparency
230+ [ Testable.equal (String.fromFloat a) selfTransparency ]
220231 }
221232
222233
@@ -227,8 +238,8 @@ padding pad =
227238 { label = "padding " ++ String.fromInt pad
228239 , attr = Element.padding pad
229240 , test =
230− \found _ ->
231− Expect.true ("Padding " ++ String.fromInt pad ++ " is present")
241+ \found ->
242+ [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
232243 (List.all ((==) pad)
233244 [ floor found.self.bbox.padding.left
234245 , floor found.self.bbox.padding.right
@@ -236,6 +247,7 @@ padding pad =
236247 , floor found.self.bbox.padding.bottom
237248 ]
238249 )
250+ ]
239251 }
240252
241253
@@ -246,8 +258,8 @@ paddingXY x y =
246258 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
247259 , attr = Element.paddingXY x y
248260 , test =
249− \found _ ->
250− Expect.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
261+ \found ->
262+ [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
251263 (List.all ((==) x)
252264 [ floor found.self.bbox.padding.left
253265 , floor found.self.bbox.padding.right
@@ -257,6 +269,7 @@ paddingXY x y =
257269 , floor found.self.bbox.padding.bottom
258270 ]
259271 )
272+ ]
260273 }
261274
262275
@@ -326,18 +339,20 @@ widthHelper maybeMin maybeMax len =
326339 |> addMax
327340 )
328341 , test =
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− ()
342+ \found ->
343+ [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
344+ , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
345+ ]
336346 }
337347
338348 Fill portion ->
339349 Testable.LabeledTest
340− { label = "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
350+ { label =
351+ if portion == 1 then
352+ "width fill" ++ minLabel ++ maxLabel
353+
354+ else
355+ "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
341356 , attr =
342357 Element.width
343358 (Element.fillPortion portion
@@ -345,30 +360,30 @@ widthHelper maybeMin maybeMax len =
345360 |> addMax
346361 )
347362 , test =
348− \context _ ->
363+ \context ->
349364 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
365+ [ Testable.true "width fill doesn't apply to onright/onleft elements" True ]
351366
352367 else
353368 let
354369 parentAvailableWidth =
355370 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
356371 in
357− case context.location of
372+ [ case context.location of
358373 Testable.IsNearby _ ->
359− Expect.true "Nearby Element has fill width"
374+ Testable.true "Nearby Element has fill width"
360375 ((floor context.parent.bbox.width == floor context.self.bbox.width)
361376 || minMaxTest (floor context.self.bbox.width)
362377 )
363378
364379 Testable.InColumn ->
365− Expect.true "Element within column has fill width"
380+ Testable.true "Element within column has fill width"
366381 ((floor parentAvailableWidth == floor context.self.bbox.width)
367382 || minMaxTest (floor context.self.bbox.width)
368383 )
369384
370385 Testable.InEl ->
371− Expect.true "Element within element has fill width" <|
386+ Testable.true "Element within element has fill width" <|
372387 (floor parentAvailableWidth == floor context.self.bbox.width)
373388 || minMaxTest (floor context.self.bbox.width)
374389
@@ -377,9 +392,10 @@ widthHelper maybeMin maybeMax len =
377392 spacePerPortion =
378393 parentAvailableWidth / toFloat (List.length context.siblings + 1)
379394 in
380− Expect.true "element has fill width" <|
395+ Testable.true "element has fill width" <|
381396 (floor spacePerPortion == floor context.self.bbox.width)
382397 || minMaxTest (floor context.self.bbox.width)
398+ ]
383399 }
384400
385401 Shrink ->
@@ -392,7 +408,7 @@ widthHelper maybeMin maybeMax len =
392408 |> addMax
393409 )
394410 , test =
395− \context _ ->
411+ \context ->
396412 let
397413 childWidth child =
398414 -- TODO: add margin values to widths
@@ -412,12 +428,12 @@ widthHelper maybeMin maybeMax len =
412428 if totalChildren == 0 then
413429 -- TODO: The issue is that we have a hard time measuring `text` elements
414430 -- 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
431+ [ expectRoundedEquality context.self.bbox.width context.self.bbox.width ]
416432
417433 else
418434 -- This fails if this element is actually a column
419435 -- So we need to capture what this element is in order to do this calculation.
420− expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width
436+ [ expectRoundedEquality (totalChildren + horizontalPadding + spacingValue) context.self.bbox.width ]
421437 }
422438
423439
@@ -487,16 +503,12 @@ heightHelper maybeMin maybeMax len =
487503 |> addMax
488504 )
489505 , test =
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− ()
506+ \found ->
507+ [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
508+ (floor found.self.bbox.height == val)
509+ , Testable.true "min/max holds true"
510+ (minMaxTest (floor found.self.bbox.height))
511+ ]
500512 }
501513
502514 Fill portion ->
@@ -509,30 +521,30 @@ heightHelper maybeMin maybeMax len =
509521 |> addMax
510522 )
511523 , test =
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
524+ \context ->
525+ [ if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
526+ Testable.true "height fill doesn't apply to above/below elements" True
515527
516− else
528+ else
517529 let
518530 parentAvailableHeight =
519531 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
520532 in
521533 case context.location of
522534 Testable.IsNearby _ ->
523− Expect.true "Nearby Element has fill height"
535+ Testable.true "Nearby Element has fill height"
524536 ((floor context.parent.bbox.height == floor context.self.bbox.height)
525537 || minMaxTest (floor context.self.bbox.height)
526538 )
527539
528540 Testable.InColumn ->
529− Expect.true "Element within column has fill height"
541+ Testable.true "Element within column has fill height"
530542 ((floor parentAvailableHeight == floor context.self.bbox.height)
531543 || minMaxTest (floor context.self.bbox.height)
532544 )
533545
534546 Testable.InEl ->
535− Expect.true "Element within el has fill height" <|
547+ Testable.true "Element within el has fill height" <|
536548 (floor parentAvailableHeight == floor context.self.bbox.height)
537549 || minMaxTest (floor context.self.bbox.height)
538550
@@ -541,9 +553,10 @@ heightHelper maybeMin maybeMax len =
541553 spacePerPortion =
542554 parentAvailableHeight / toFloat (List.length context.siblings + 1)
543555 in
544− Expect.true "el has fill height" <|
556+ Testable.true "el has fill height" <|
545557 (floor spacePerPortion == floor context.self.bbox.height)
546558 || minMaxTest (floor context.self.bbox.height)
559+ ]
547560 }
548561
549562 Shrink ->
@@ -556,7 +569,7 @@ heightHelper maybeMin maybeMax len =
556569 |> addMax
557570 )
558571 , test =
559− \context _ ->
572+ \context ->
560573 let
561574 childWidth child =
562575 -- TODO: add margin values to heights
@@ -576,12 +589,12 @@ heightHelper maybeMin maybeMax len =
576589 if totalChildren == 0 then
577590 -- TODO: The issue is that we have a hard time measuring `text` elements
578591 -- 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
592+ [ expectRoundedEquality context.self.bbox.height context.self.bbox.height ]
580593
581594 else
582595 -- This fails if this element is actually a column
583596 -- So we need to capture what this element is in order to do this calculation.
584− expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height
597+ [ expectRoundedEquality (totalChildren + verticalPadding + spacingValue) context.self.bbox.height ]
585598 }
586599
587600
@@ -603,7 +616,7 @@ spacing space =
603616 { label = "spacing: " ++ String.fromInt space
604617 , attr = Element.spacing space
605618 , test =
606− \found _ ->
619+ \found ->
607620 let
608621 findDistance child total =
609622 List.concatMap
@@ -649,7 +662,7 @@ spacing space =
649662 []
650663 distances
651664 in
652− Expect.true
665+ [ Testable.true
653666 ("All children are at least "
654667 ++ String.fromInt space
655668 ++ " pixels apart."
@@ -657,6 +670,7 @@ spacing space =
657670 ++ " are not though"
658671 )
659672 (allAreSpaced == [])
673+ ]
660674 }
661675 ]
662676
@@ -680,28 +694,28 @@ alignLeft =
680694 { label = "alignLeft"
681695 , attr = Element.alignLeft
682696 , test =
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
697+ \found ->
698+ [ if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
699+ Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
686700
687− else if
701+ else if
688702 List.member found.location
689703 [ Testable.IsNearby Testable.InFront
690704 , Testable.IsNearby Testable.Behind
691705 , Testable.IsNearby Testable.Above
692706 , Testable.IsNearby Testable.Below
693707 ]
694− then
708+ then
695709 expectRoundedEquality
696710 found.self.bbox.left
697711 found.parent.bbox.left
698712
699− else if List.length found.siblings == 0 then
713+ else if List.length found.siblings == 0 then
700714 expectRoundedEquality
701715 found.self.bbox.left
702716 (found.parent.bbox.left + found.parent.bbox.padding.left)
703717
704− else
718+ else
705719 case found.location of
706720 Testable.InRow ->
707721 let
@@ -724,6 +738,7 @@ alignLeft =
724738 expectRoundedEquality
725739 found.self.bbox.left
726740 (found.parent.bbox.left + found.parent.bbox.padding.left)
741+ ]
727742 }
728743
729744
@@ -734,7 +749,7 @@ centerX =
734749 { label = "centerX"
735750 , attr = Element.centerX
736751 , test =
737− \found _ ->
752+ \found ->
738753 let
739754 selfCenter : Float
740755 selfCenter =
@@ -745,12 +760,13 @@ centerX =
745760 found.parent.bbox.left + (found.parent.bbox.width / 2)
746761 in
747762 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
763+ [ Testable.true "centerX doesn't apply to elements that are onLeft or onRight" True ]
749764
750765 else if List.length found.siblings == 0 then
751− expectRoundedEquality
766+ [ expectRoundedEquality
752767 selfCenter
753768 parentCenter
769+ ]
754770
755771 else
756772 case found.location of
@@ -783,12 +799,13 @@ centerX =
783799 / 2
784800 )
785801 in
786− expectRoundedEquality
802+ [ expectRoundedEquality
787803 selfCenter
788804 expectedCenter
805+ ]
789806
790807 _ ->
791− expectRoundedEquality selfCenter parentCenter
808+ [ expectRoundedEquality selfCenter parentCenter ]
792809 }
793810
794811
@@ -799,9 +816,9 @@ alignRight =
799816 { label = "alignRight"
800817 , attr = Element.alignRight
801818 , test =
802− \found _ ->
819+ \found ->
803820 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
821+ [ Testable.true "alignRight doesn't apply to elements that are onLeft or onRight" True ]
805822
806823 else if
807824 List.member found.location
@@ -811,14 +828,16 @@ alignRight =
811828 , Testable.IsNearby Testable.Below
812829 ]
813830 then
814− expectRoundedEquality
831+ [ expectRoundedEquality
815832 found.self.bbox.right
816833 found.parent.bbox.right
834+ ]
817835
818836 else if List.length found.siblings == 0 then
819− expectRoundedEquality
837+ [ expectRoundedEquality
820838 found.self.bbox.right
821839 (found.parent.bbox.right + found.parent.bbox.padding.right)
840+ ]
822841
823842 else
824843 case found.location of
@@ -835,14 +854,16 @@ alignRight =
835854 |> List.map (.width << .bbox)
836855 |> List.sum
837856 in
838− expectRoundedEquality
857+ [ expectRoundedEquality
839858 found.self.bbox.right
840859 (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
860+ ]
841861
842862 _ ->
843− expectRoundedEquality
863+ [ expectRoundedEquality
844864 found.self.bbox.right
845865 (found.parent.bbox.right + found.parent.bbox.padding.right)
866+ ]
846867 }
847868
848869
@@ -853,9 +874,9 @@ alignTop =
853874 { label = "alignTop"
854875 , attr = Element.alignTop
855876 , test =
856− \found _ ->
877+ \found ->
857878 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
879+ [ Testable.true "alignTop doesn't apply to elements that are above or below" True ]
859880
860881 else if
861882 List.member found.location
@@ -865,14 +886,16 @@ alignTop =
865886 , Testable.IsNearby Testable.OnLeft
866887 ]
867888 then
868− expectRoundedEquality
889+ [ expectRoundedEquality
869890 found.self.bbox.top
870891 found.parent.bbox.top
892+ ]
871893
872894 else if List.length found.siblings == 0 then
873− expectRoundedEquality
895+ [ expectRoundedEquality
874896 found.self.bbox.top
875897 (found.parent.bbox.top + found.parent.bbox.padding.top)
898+ ]
876899
877900 else
878901 case found.location of
@@ -889,14 +912,16 @@ alignTop =
889912 |> List.map (.height << .bbox)
890913 |> List.sum
891914 in
892− expectRoundedEquality
915+ [ expectRoundedEquality
893916 found.self.bbox.top
894917 (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
918+ ]
895919
896920 _ ->
897− expectRoundedEquality
921+ [ expectRoundedEquality
898922 found.self.bbox.top
899923 found.parent.bbox.top
924+ ]
900925 }
901926
902927
@@ -907,9 +932,9 @@ alignBottom =
907932 { label = "alignBottom"
908933 , attr = Element.alignBottom
909934 , test =
910− \found _ ->
935+ \found ->
911936 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
937+ [ Testable.true "alignBottom doesn't apply to elements that are above or below" True ]
913938
914939 else if
915940 List.member found.location
@@ -919,14 +944,16 @@ alignBottom =
919944 , Testable.IsNearby Testable.OnLeft
920945 ]
921946 then
922− expectRoundedEquality
947+ [ expectRoundedEquality
923948 found.self.bbox.bottom
924949 found.parent.bbox.bottom
950+ ]
925951
926952 else if List.length found.siblings == 0 then
927− expectRoundedEquality
953+ [ expectRoundedEquality
928954 found.self.bbox.bottom
929955 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
956+ ]
930957
931958 else
932959 case found.location of
@@ -943,22 +970,30 @@ alignBottom =
943970 |> List.map (.height << .bbox)
944971 |> List.sum
945972 in
946− expectRoundedEquality
973+ [ expectRoundedEquality
947974 found.self.bbox.bottom
948975 (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
976+ ]
949977
950978 _ ->
951− expectRoundedEquality
979+ [ expectRoundedEquality
952980 found.self.bbox.bottom
953981 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
982+ ]
954983 }
955984
956985
957986expectRoundedEquality x y =
958− Expect.true ("within 1 of each other " ++ String.fromFloat x ++ ":" ++ String.fromFloat y)
987+ Testable.true
988+ ("within 1 of each other " ++ floatToString x ++ ", " ++ floatToString y)
959989 (abs (x - y) < 1)
960990
961991
992+floatToString : Float -> String
993+floatToString x =
994+ String.fromFloat (toFloat (round (x * 100)) / 100)
995+
996+
962997{-| -}
963998centerY : Testable.Attr msg
964999centerY =
@@ -966,7 +1001,7 @@ centerY =
9661001 { label = "centerY"
9671002 , attr = Element.centerY
9681003 , test =
969− \found _ ->
1004+ \found ->
9701005 let
9711006 selfCenter =
9721007 found.self.bbox.top + (found.self.bbox.height / 2)
@@ -975,12 +1010,13 @@ centerY =
9751010 found.parent.bbox.top + (found.parent.bbox.height / 2)
9761011 in
9771012 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
1013+ [ Testable.true "centerY doesn't apply to elements that are above or below" True ]
9791014
9801015 else if List.length found.siblings == 0 then
981− expectRoundedEquality
1016+ [ expectRoundedEquality
9821017 selfCenter
9831018 parentCenter
1019+ ]
9841020
9851021 else
9861022 case found.location of
@@ -1013,12 +1049,13 @@ centerY =
10131049 / 2
10141050 )
10151051 in
1016− expectRoundedEquality
1052+ [ expectRoundedEquality
10171053 selfCenter
10181054 expectedCenter
1055+ ]
10191056
10201057 _ ->
1021− expectRoundedEquality selfCenter parentCenter
1058+ [ expectRoundedEquality selfCenter parentCenter ]
10221059 }
10231060
10241061
@@ -1030,8 +1067,8 @@ above element =
10301067 , element = element
10311068 , label = "above"
10321069 , test =
1033− \found _ ->
1034− expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top
1070+ \found ->
1071+ [ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top ]
10351072 }
10361073
10371074
@@ -1043,8 +1080,8 @@ below element =
10431080 , element = element
10441081 , label = "below"
10451082 , test =
1046− \found _ ->
1047− expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom
1083+ \found ->
1084+ [ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom ]
10481085 }
10491086
10501087
@@ -1056,8 +1093,8 @@ onRight element =
10561093 , element = element
10571094 , label = "onRight"
10581095 , test =
1059− \found _ ->
1060− expectRoundedEquality found.self.bbox.left found.parent.bbox.right
1096+ \found ->
1097+ [ expectRoundedEquality found.self.bbox.left found.parent.bbox.right ]
10611098 }
10621099
10631100
@@ -1069,8 +1106,8 @@ onLeft element =
10691106 , element = element
10701107 , label = "onLeft"
10711108 , test =
1072− \found _ ->
1073− expectRoundedEquality found.self.bbox.right found.parent.bbox.left
1109+ \found ->
1110+ [ expectRoundedEquality found.self.bbox.right found.parent.bbox.left ]
10741111 }
10751112
10761113
@@ -1086,11 +1123,12 @@ inFront element =
10861123 , element = element
10871124 , label = "inFront"
10881125 , test =
1089− withinHelper
1126+ \found ->
1127+ [ withinHelper found ]
10901128 }
10911129
10921130
1093−withinHelper found _ =
1131+withinHelper found =
10941132 let
10951133 horizontalCheck =
10961134 if found.self.bbox.width > found.parent.bbox.width then
@@ -1114,7 +1152,7 @@ withinHelper found _ =
11141152 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
11151153 ]
11161154 in
1117− Expect.true "within the confines of the parent"
1155+ Testable.true "within the confines of the parent"
11181156 (List.all ((==) True)
11191157 (List.concat
11201158 [ horizontalCheck
@@ -1132,5 +1170,6 @@ behindContent element =
11321170 , element = element
11331171 , label = "behindContent"
11341172 , test =
1135− withinHelper
1173+ \found ->
1174+ [ withinHelper found ]
11361175 }
tests-rendering/src/Testable/Element/Background.elm+4−4
@@ -5,23 +5,23 @@ module Testable.Element.Background exposing (color)
55import Dict
66import Element exposing (Color)
77import Element.Background as Background
8−import Expect
98import Testable
109
1110
1211color : Color -> Testable.Attr msg
1312color clr =
1413 Testable.LabeledTest
15− { label = "background color-" ++ Testable.formatColor clr
14+ { label = "background color"
1615 , attr = Background.color clr
1716 , test =
18− \context _ ->
17+ \context ->
1918 let
2019 selfBackgroundColor =
2120 context.self.style
2221 |> Dict.get "background-color"
2322 |> Maybe.withDefault "notfound"
2423 in
25− Expect.true ("Expected color: " ++ (Testable.formatColor clr ++ " vs found:" ++ selfBackgroundColor))
24+ [ Testable.true ("expected: " ++ (Testable.formatColor clr ++ ", found:" ++ selfBackgroundColor))
2625 (Testable.compareFormattedColor clr selfBackgroundColor)
26+ ]
2727 }
tests-rendering/src/Testable/Element/Font.elm+6−4
@@ -15,15 +15,16 @@ color clr =
1515 { label = "font color-" ++ Testable.formatColor clr
1616 , attr = Font.color clr
1717 , test =
18− \context _ ->
18+ \context ->
1919 let
2020 selfFontColor =
2121 context.self.style
2222 |> Dict.get "color"
2323 |> Maybe.withDefault "notfound"
2424 in
25− Expect.true ("Color Match - " ++ (Testable.formatColor clr ++ " vs " ++ selfFontColor))
25+ [ Testable.true ("Color Match - " ++ (Testable.formatColor clr ++ " vs " ++ selfFontColor))
2626 (Testable.compareFormattedColor clr selfFontColor)
27+ ]
2728 }
2829
2930
@@ -33,7 +34,7 @@ size i =
3334 { label = "font size-" ++ String.fromInt i
3435 , attr = Font.size i
3536 , test =
36− \context _ ->
37+ \context ->
3738 let
3839 selfFontSize =
3940 context.self.style
@@ -43,6 +44,7 @@ size i =
4344 formattedInt =
4445 String.fromInt i
4546 in
46− Expect.true ("Size Match - " ++ (formattedInt ++ " vs " ++ selfFontSize))
47+ [ Testable.true ("Size Match - " ++ (formattedInt ++ " vs " ++ selfFontSize))
4748 (formattedInt == selfFontSize)
49+ ]
4850 }
tests-rendering/src/Testable/Runner.elm+210−181
@@ -3,27 +3,23 @@ port module Testable.Runner exposing (Msg, TestableProgram, program, show)
33{-| -}
44
55import Browser
6−import Char
76import Dict exposing (Dict)
87import Element
98import Element.Background as Background
109import Element.Border as Border
10+import Element.Events as Events
1111import Element.Font as Font
1212import Html exposing (Html)
13−import Parser exposing ((|.), (|=))
13+import Html.Attributes
1414import Process
15−import Random
16−import Set
1715import Task
18−import Test.Runner
19−import Test.Runner.Failure as Failure
2016import Testable
2117import Time
2218
2319
2420show : Testable.Element msg -> Html msg
2521show =
26− Testable.render
22+ Testable.toHtml
2723
2824
2925type alias TestableProgram =
@@ -56,6 +52,7 @@ program tests =
5652 ( { current = current
5753 , upcoming = upcoming
5854 , finished = []
55+ , highlightDomId = Nothing
5956 }
6057 , Task.perform (always Analyze)
6158 (Process.sleep 32
@@ -80,6 +77,7 @@ type alias Model msg =
8077 { current : Maybe ( String, Testable.Element msg )
8178 , upcoming : List ( String, Testable.Element msg )
8279 , finished : List (WithResults (Testable.Element msg))
80+ , highlightDomId : Maybe String
8381 }
8482
8583
@@ -87,49 +85,44 @@ type alias WithResults thing =
8785 { element : thing
8886 , label : String
8987 , results :
90− List
91− ( String
92− , Maybe
93− { given : Maybe String
94− , description : String
95− , reason : Failure.Reason
96− }
97− )
88+ List Testable.LayoutTest
9889 }
9990
10091
101−prepareResults :
92+encodeForReport :
10293 List (WithResults (Testable.Element msg))
10394 ->
10495 List
10596 { label : String
10697 , results :
10798 List
108− ( String
109− , Maybe
110− { given : Maybe String
111− , description : String
112− }
113− )
99+ { description : String
100+ , passing : Bool
101+ , todo : Bool
102+ }
114103 }
115−prepareResults withResults =
104+encodeForReport withResults =
116105 let
117− prepareNode ( x, maybeResult ) =
118− ( x
119− , case maybeResult of
120− Nothing ->
121− Nothing
106+ prepareExpectation layoutTest exp =
107+ case exp of
108+ Testable.Todo description ->
109+ { description = description
110+ , passing = False
111+ , todo = True
112+ }
122113
123− Just res ->
124− Just
125− { given = res.given
126− , description = res.description
127− }
128− )
114+ Testable.Expect details ->
115+ { description = details.description
116+ , passing = details.result
117+ , todo = False
118+ }
119+
120+ prepareNode layoutTest =
121+ List.map (prepareExpectation layoutTest) layoutTest.expectations
129122
130123 prepare { label, results } =
131124 { label = label
132− , results = List.map prepareNode results
125+ , results = List.concatMap prepareNode results
133126 }
134127 in
135128 List.map prepare withResults
@@ -138,6 +131,7 @@ prepareResults withResults =
138131type Msg
139132 = NoOp
140133 | Analyze
134+ | HighlightDomID (Maybe String)
141135 | RefreshBoundingBox
142136 (List
143137 { id : String
@@ -151,14 +145,8 @@ type Msg
151145runTest : Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
152146runTest boxes label element =
153147 let
154− tests =
155− Testable.toTest label boxes element
156−
157− seed =
158− Random.initialSeed 227852860
159−
160148 results =
161− Testable.runTests seed tests
149+ Testable.runTests boxes element
162150 in
163151 { element = element
164152 , label = label
@@ -172,6 +160,11 @@ update msg model =
172160 NoOp ->
173161 ( model, Cmd.none )
174162
163+ HighlightDomID newId ->
164+ ( { model | highlightDomId = newId }
165+ , Cmd.none
166+ )
167+
175168 RefreshBoundingBox boxes ->
176169 case model.current of
177170 Nothing ->
@@ -203,7 +196,7 @@ update msg model =
203196 | current = Nothing
204197 , finished = model.finished ++ [ currentResults ]
205198 }
206− , report (prepareResults (currentResults :: model.finished))
199+ , report (encodeForReport (currentResults :: model.finished))
207200 )
208201
209202 newCurrent :: remaining ->
@@ -246,23 +239,42 @@ view model =
246239 [ Element.spacing 20
247240 , Element.padding 20
248241 , Element.width (Element.px 800)
249−
250− -- , Background.color Color.grey
251242 ]
252243 [ Element.none ]
253244
254245 finished :: remaining ->
255− if False then
256− viewResultsInline finished
257−
258− else
259− Element.layout [] <|
260− Element.column
246+ Element.layout
247+ [ Font.size 16
248+ , Element.inFront (Element.html (viewElementHighlight model))
249+ ]
250+ <|
251+ Element.row [ Element.width Element.fill ]
252+ [ Element.el
253+ [ Element.width Element.fill
254+ ]
255+ (Element.el
256+ [ Element.centerX
257+ , Element.padding 100
258+ , Border.dashed
259+ , Border.width 2
260+ , Border.color palette.lightGrey
261+ , Element.inFront
262+ (Element.el
263+ [ Font.size 14
264+ , Font.color palette.lightGrey
265+ ]
266+ (Element.text "test case")
267+ )
268+ ]
269+ (Testable.toElement finished.element)
270+ )
271+ , Element.column
261272 [ Element.spacing 20
262273 , Element.padding 20
263− , Element.width (Element.px 800)
274+ , Element.width Element.fill
264275 ]
265276 (List.map viewResult (finished :: remaining))
277+ ]
266278 ]
267279 }
268280
@@ -274,162 +286,181 @@ view model =
274286 Just ( label, current ) ->
275287 { title = "running"
276288 , body =
277− [ Testable.render current ]
289+ [ Testable.toHtml current ]
278290 }
279291
280292
281−viewResultsInline : WithResults (Testable.Element Msg) -> Html Msg
282−viewResultsInline testable =
283− Html.div
284− []
285− [ viewResultsAnnotationStylesheet testable.results
286− , Testable.render testable.element
287− ]
288−
289−
290−{-| Our ID is part of our label. This could be fixed farther down the chain, but I think it'd be pretty involved.
291−
292−So, now we can just parse the id out of the label.
293−
294−-}
295−parseId str =
296− str
297− |> Parser.run
298− (Parser.succeed identity
299− |. Parser.chompWhile (\c -> c /= '#')
300− |= Parser.variable
301− { start = \c -> c == '#'
302− , inner = \c -> Char.isAlphaNum c || c == '-'
303− , reserved = Set.empty
304− }
305− )
306− |> Result.toMaybe
293+viewElementHighlight model =
294+ case model.highlightDomId of
295+ Nothing ->
296+ Html.text ""
307297
298+ Just highlightDomId ->
299+ let
300+ elementHighlight =
301+ highlightDomId ++ " { outline: solid; }"
308302
309−viewResultsAnnotationStylesheet results =
310− let
311− toStyleClass ( label, maybeFailure ) =
312− case maybeFailure of
313− Nothing ->
314− ""
303+ testId =
304+ highlightDomId
305+ |> String.dropLeft 1
306+ |> String.append "#tests-"
315307
316− Just failure ->
317− case parseId label of
318− Nothing ->
319− Debug.log "NO ID FOUND" label
308+ testHighlight =
309+ testId ++ " { outline: dashed; }"
320310
321− Just id ->
322− id ++ " { background-color:red; outline: dashed; };"
323−
324− styleSheet =
325− results
326− |> List.map toStyleClass
327− |> String.join ""
328− in
329− Html.node "style"
330− []
331− [ Html.text styleSheet
332− ]
311+ styleSheet =
312+ String.join "\n"
313+ [ elementHighlight
314+ , testHighlight
315+ ]
316+ in
317+ Html.node "style"
318+ []
319+ [ Html.text styleSheet
320+ ]
333321
334322
335323viewResult : WithResults (Testable.Element Msg) -> Element.Element Msg
336324viewResult testable =
337325 let
338− isPassing result =
339− case Tuple.second result of
340− Nothing ->
326+ isExpectationPassing result =
327+ case result of
328+ Testable.Todo label ->
341329 True
342330
343− Just _ ->
344− False
331+ Testable.Expect details ->
332+ details.result
333+
334+ isPassing layoutTest =
335+ List.any isExpectationPassing layoutTest.expectations
345336
346337 ( passing, failing ) =
347338 List.partition isPassing testable.results
348−
349− viewSingle result =
350− case result of
351− ( label, Nothing ) ->
352− Element.el
353− [ Background.color palette.green
354− , Font.color palette.black
355− , Element.paddingXY 20 10
356− , Element.alignLeft
357− , Border.rounded 3
358− ]
359− <|
360− Element.text ("Success! - " ++ label)
361−
362− ( label, Just ({ given, description } as reason) ) ->
363− Element.column
364− [ Background.color palette.red
365− , Font.color palette.black
366− , Element.paddingXY 20 10
367− , Element.alignLeft
368− , Element.width Element.shrink
369−
370− -- , Element.spacing 25
371− , Border.rounded 3
372− ]
373− [ Element.el [ Element.width Element.fill ] <| Element.text label
374− , Element.el [ Element.width Element.fill ] <| Element.text (viewReason reason)
375− ]
376339 in
377340 Element.column
378− [ Border.width 1
379− , Border.color palette.lightGrey
380− , Element.padding 20
381− , Element.height Element.shrink
382− , Element.alignLeft
341+ [ Element.alignLeft
383342 , Element.spacing 16
384343 ]
385− [ Element.el [ Font.bold, Font.size 64 ] (Element.text testable.label)
344+ [ Element.el [ Font.size 24 ] (Element.text testable.label)
386345 , Element.column [ Element.alignLeft, Element.spacing 20 ]
387− (failing
388− |> List.map viewSingle
346+ (List.map viewLayoutTest failing)
347+ , Element.column
348+ [ Element.alignLeft, Element.spacing 16 ]
349+ (passing
350+ |> groupBy .elementDomId
351+ |> List.map viewLayoutTestGroup
352+ )
353+ ]
354+
355+
356+groupBy fn list =
357+ groupWhile (\one two -> fn one == fn two) list
358+ |> List.map
359+ (\( fst, remaining ) ->
360+ { id = fn fst
361+ , members = fst :: remaining
362+ }
389363 )
390− , Element.el
391− [ Element.alignLeft
392− , Element.spacing 20
393− , Background.color palette.green
394− , Font.color palette.black
395− , Element.paddingXY 20 10
396− , Element.alignLeft
397− , Border.rounded 3
364+
365+
366+groupWhile : (a -> a -> Bool) -> List a -> List ( a, List a )
367+groupWhile isSameGroup items =
368+ List.foldr
369+ (\x acc ->
370+ case acc of
371+ [] ->
372+ [ ( x, [] ) ]
373+
374+ ( y, restOfGroup ) :: groups ->
375+ if isSameGroup x y then
376+ ( x, y :: restOfGroup ) :: groups
377+
378+ else
379+ ( x, [] ) :: acc
380+ )
381+ []
382+ items
383+
384+
385+viewLayoutTestGroup group =
386+ let
387+ testId =
388+ group.id
389+ |> String.dropLeft 1
390+ |> String.append "tests-"
391+ in
392+ Element.column
393+ [ Element.spacing 8
394+ , Element.htmlAttribute (Html.Attributes.id testId)
395+ , Events.onMouseEnter (HighlightDomID (Just group.id))
396+ , Events.onMouseLeave (HighlightDomID Nothing)
397+ , Element.htmlAttribute (Html.Attributes.style "user-select" "none")
398+ ]
399+ [ Element.el [ Font.color palette.lightGrey ] (Element.text group.id)
400+ , Element.column
401+ [ Element.spacing 8
402+ , Element.paddingXY 32 0
398403 ]
399− (Element.text (String.fromInt (List.length passing) ++ " tests passing!"))
404+ (List.map viewLayoutTest group.members)
400405 ]
401406
402407
403−viewReason { description, reason } =
404− case reason of
405− Failure.Custom ->
406− description
408+type alias Grouped thing =
409+ { id : String
410+ , members : List thing
411+ }
412+
413+
414+viewLayoutTest layoutTest =
415+ Element.column
416+ [ Element.spacing 8
417+ ]
418+ [ Element.row [ Element.spacing 8 ]
419+ [ Element.el [ Font.bold ] (Element.text layoutTest.label)
407420
408− Failure.Equality one two ->
409− description ++ " " ++ one ++ " " ++ two
421+ -- , Element.el [ Font.color palette.lightGrey ] (Element.text layoutTest.elementDomId)
422+ ]
423+ , Element.column [ Element.spacing 8 ]
424+ (List.map viewLayoutExpectation layoutTest.expectations)
425+ ]
410426
411− Failure.Comparison one two ->
412− description ++ " " ++ one ++ " " ++ two
413427
414− Failure.ListDiff expected actual ->
415− "expected\n"
416− ++ String.join " \n" expected
417− ++ "actual\n"
418− ++ String.join " \n" actual
428+viewLayoutExpectation expectation =
429+ case expectation of
430+ Testable.Todo label ->
431+ Element.row [ Element.spacing 4 ]
432+ [ todo, Element.text label ]
419433
420− Failure.CollectionDiff { expected, actual, extra, missing } ->
421− String.join "\n"
422− [ formatKeyValue "expected" expected
423− , formatKeyValue "actual" actual
424− , formatKeyValue "extra" (String.join ", " extra)
425− , formatKeyValue "missing" (String.join ", " missing)
426− ]
434+ Testable.Expect details ->
435+ if details.result then
436+ Element.row [ Element.spacing 4 ]
437+ [ pass, Element.text details.description ]
438+
439+ else
440+ Element.row [ Element.spacing 4 ]
441+ [ fail, Element.text details.description ]
427442
428− Failure.TODO ->
429− description
430443
431− Failure.Invalid _ ->
432− description
444+badge color text =
445+ Element.el
446+ [ Background.color color
447+ , Font.color palette.black
448+ , Element.paddingXY 4 8
449+ , Border.rounded 2
450+ ]
451+ (Element.text text)
452+
453+
454+todo =
455+ badge palette.lightGrey "todo"
456+
457+
458+pass =
459+ badge palette.green "pass"
460+
461+
462+fail =
463+ badge palette.red "fail"
433464
434465
435466formatKeyValue : String -> String -> String
@@ -442,12 +473,10 @@ port report :
442473 { label : String
443474 , results :
444475 List
445− ( String
446− , Maybe
447− { given : Maybe String
448− , description : String
449− }
450− )
476+ { description : String
477+ , passing : Bool
478+ , todo : Bool
479+ }
451480 }
452481 -> Cmd msg
453482
tests-rendering/view/view.html+1−1
@@ -9,7 +9,7 @@
99 <body id="root"></body>
1010
1111 <script type="text/javascript">
12− var app = Elm.InFrontSize.init();
12+ var app = Elm.WeirdCentering.init();
1313
1414 var test_results = "waiting..";
1515