git.iko.soy/typeable/elm-ui
on master help sign in
redo testing interface so it's actually readable by a human.
639efbbElm UI Automation
tests-rendering/automation/run.js+8−10
@@ -265,31 +265,29 @@ function renderEnvName(env) {
265 return `${env.platform}, ${env.browser} ${env.browserVersion}`;
265 return `${env.platform}, ${env.browser} ${env.browserVersion}`;
266}
266}
267
267
268−function print_results(label, results) {
268+function print_results(label, tests) {
269 var total_passed = 0;
269 var total_passed = 0;
270 var total_failed = 0;
270 var total_failed = 0;
271 var i;
271 var i;
272 if (program.verbose) {
272 if (program.verbose) {
273 console.log(label);
273 console.log(label);
274 }
274 }
275− for (i = 0; i < results.length; i++) {
275+ for (i = 0; i < tests.length; i++) {
276 var passed = 0;
276 var passed = 0;
277 var failed = 0;
277 var failed = 0;
278− for (j = 0; j < results[i].results.length; j++) {
278+ for (j = 0; j < tests[i].results.length; j++) {
279− if (results[i].results[j][1] == null) {
279+ if (tests[i].results[j].passing) {
280 passed = passed + 1;
280 passed = passed + 1;
281 } else {
281 } else {
282 if (failed == 0) {
282 if (failed == 0) {
283 if (!program.verbose) {
283 if (!program.verbose) {
284 console.log(label);
284 console.log(label);
285 }
285 }
286− console.log(results[i].label);
286+ console.log(tests[i].label);
287 }
287 }
288 failed = failed + 1;
288 failed = failed + 1;
289− console.log(
289+ console.log(" " + chalk.red("fail") + " ->");
290− " " + chalk.red("fail") + " -> " + results[i].results[j][0]
291− );
292− console.log(" " + results[i].results[j][1].description);
290+ console.log(" " + tests[i].results[j][1].description);
293 }
291 }
294 }
292 }
295 total_passed = total_passed + passed;
293 total_passed = total_passed + passed;
@@ -300,7 +298,7 @@ function print_results(label, results) {
300 console.log(chalk.red(` ${failed} tests failed`));
298 console.log(chalk.red(` ${failed} tests failed`));
301 console.log();
299 console.log();
302 } else if (program.verbose) {
300 } 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`));
304 }
302 }
305 }
303 }
306 if (total_failed == 0) {
304 if (total_failed == 0) {
tests-rendering/automation/templates/gather-styles.html+105−103
@@ -1,105 +1,107 @@
1−<!DOCTYPE HTML>
1+<!DOCTYPE html>
2<html>
2<html>
3− <head>
3+ <head>
4− <meta charset="UTF-8">
4+ <meta charset="UTF-8" />
5− <title>Rendering Benchmark Viewer</title>
5+ <title>Rendering Benchmark Viewer</title>
6− <script>
6+ <script>
7− ${compiled_elm_code}
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−
104 </script>
8 </script>
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>
105−</html>
107+</html>
tests-rendering/make.sh+1−1
@@ -1,2 +1,2 @@
1
1
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
4 , Element(..)
4 , Element(..)
5 , Found
5 , Found
6 , LayoutContext(..)
6 , LayoutContext(..)
7+ , LayoutExpectation(..)
8+ , LayoutTest
7 , Location(..)
9 , Location(..)
8 , Style
10 , Style
9 , Surroundings
11 , Surroundings
10− , addAttribute
11− , applyLabels
12 , compareFormattedColor
12 , compareFormattedColor
13− , createAttributeTest
13+ , equal
14− , createTest
15 , formatColor
14 , formatColor
16 , formatColorWithAlpha
15 , formatColorWithAlpha
17− , getElementId
18 , getIds
16 , getIds
19 , getSpacing
17 , getSpacing
20− , idAttr
21− , levelToString
22− , render
23− , renderAttribute
24− , renderElement
25 , runTests
18 , runTests
26− , toTest
19+ , toElement
20+ , toHtml
21+ , todo
22+ , true
27 )
23 )
28
24
29{-| -}
25{-| -}
30
26
31import Dict exposing (Dict)
27import Dict exposing (Dict)
32import Element exposing (Color)
28import Element exposing (Color)
33−import Expect
34import Html exposing (Html)
29import Html exposing (Html)
35import Html.Attributes
30import Html.Attributes
36import Internal.Model as Internal
31import Internal.Model as Internal
37−import Random
38import Test exposing (Test)
32import Test exposing (Test)
39−import Test.Runner
40−import Test.Runner.Failure
41
33
42
34
43type Element msg
35type Element msg
@@ -52,18 +44,20 @@ type Element msg
52
44
53type Attr msg
45type Attr msg
54 = Attr (Element.Attribute msg)
46 = Attr (Element.Attribute msg)
55− | AttrTest (Surroundings -> Test)
47+ | AttrTest
48+ { test : Surroundings -> List LayoutExpectation
49+ , label : String
50+ }
56 | Batch (List (Attr msg))
51 | Batch (List (Attr msg))
57 | Spacing Int
52 | Spacing Int
58 | Nearby
53 | Nearby
59 { location : Location
54 { location : Location
60 , element : Element msg
55 , element : Element msg
61− , test : Surroundings -> () -> Expect.Expectation
56+ , test : Surroundings -> List LayoutExpectation
62 , label : String
57 , label : String
63 }
58 }
64− | Label String
65 | LabeledTest
59 | LabeledTest
66− { test : Surroundings -> () -> Expect.Expectation
60+ { test : Surroundings -> List LayoutExpectation
67 , label : String
61 , label : String
68 , attr : Element.Attribute msg
62 , attr : Element.Attribute msg
69 }
63 }
@@ -125,6 +119,46 @@ type alias BoundingBox =
125 }
119 }
126
120
127
121
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+
128
162
129{- Retrieve Ids -}
163{- Retrieve Ids -}
130
164
@@ -183,8 +217,13 @@ getElementId level el =
183{- Render as Html -}
217{- Render as Html -}
184
218
185
219
220+toElement : Element msg -> Element.Element msg
221+toElement el =
222+ renderElement [ 0, 0 ] el
223+
224+
186−render : Element msg -> Html msg
225+toHtml : Element msg -> Html msg
187−render el =
226+toHtml el =
188 Element.layout [ idAttr "0" ] <|
227 Element.layout [ idAttr "0" ] <|
189 renderElement [ 0, 0 ] el
228 renderElement [ 0, 0 ] el
190
229
@@ -253,9 +292,6 @@ renderAttribute level attrIndex attr =
253 Spacing _ ->
292 Spacing _ ->
254 []
293 []
255
294
256− Label _ ->
257− []
258−
259 Nearby { location, element } ->
295 Nearby { location, element } ->
260 case location of
296 case location of
261 Above ->
297 Above ->
@@ -288,30 +324,35 @@ renderAttribute level attrIndex attr =
288{- Convert to Test -}
324{- Convert to Test -}
289
325
290
326
291−toTest : String -> Dict String Found -> Element msg -> Test
327+runTests : Dict String Found -> Element msg -> List LayoutTest
292−toTest label harvested el =
328+runTests harvested el =
293 let
329 let
294 maybeFound =
330 maybeFound =
295 Dict.get "se-0" harvested
331 Dict.get "se-0" harvested
296 in
332 in
297 case maybeFound of
333 case maybeFound of
298 Nothing ->
334 Nothing ->
299− Test.describe label
335+ [ { elementDomId = "se-0"
300− [ Test.test "Find Root" <|
336+ , label = "Finding root element"
301− \_ -> Expect.fail "unable to find root"
337+ , expectations =
338+ [ Expect
339+ { description = "Locating root element for rendering tests"
340+ , result = False
341+ }
342+ ]
343+ }
302− ]
344+ ]
303
345
304 Just root ->
346 Just root ->
305− Test.describe label <|
306− createTest
347+ createTest
307− { siblings = []
348+ { siblings = []
308− , parent = root
349+ , parent = root
309− , cache = harvested
350+ , cache = harvested
310− , parentSpacing = 0
351+ , parentSpacing = 0
311− , level = [ 0, 0 ]
352+ , level = [ 0, 0 ]
312− , element = el
353+ , element = el
313− , location = InEl
354+ , location = InEl
314− }
355+ }
315
356
316
357
317levelToString : List Int -> String
358levelToString : List Int -> String
@@ -331,7 +372,7 @@ createTest :
331 , location : LayoutContext
372 , location : LayoutContext
332 , parentSpacing : Int
373 , parentSpacing : Int
333 }
374 }
334− -> List Test
375+ -> List LayoutTest
335createTest { siblings, parent, cache, level, element, location, parentSpacing } =
376createTest { siblings, parent, cache, level, element, location, parentSpacing } =
336 let
377 let
337 spacing =
378 spacing =
@@ -341,7 +382,7 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
341 id =
382 id =
342 levelToString level
383 levelToString level
343
384
344− testChildren : Found -> List (Element msg) -> List Test
385+ testChildren : Found -> List (Element msg) -> List LayoutTest
345 testChildren found children =
386 testChildren found children =
346 let
387 let
347 childrenFound =
388 childrenFound =
@@ -369,13 +410,13 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
369 { a
410 { a
370 | index : Int
411 | index : Int
371 , previous : List Found
412 , previous : List Found
372− , tests : List Test
413+ , tests : List LayoutTest
373 , upcoming : List Found
414 , upcoming : List Found
374 }
415 }
375 ->
416 ->
376 { index : Int
417 { index : Int
377 , previous : List Found
418 , previous : List Found
378− , tests : List Test
419+ , tests : List LayoutTest
379 , upcoming : List Found
420 , upcoming : List Found
380 }
421 }
381 applyChildTest found child childTest =
422 applyChildTest found child childTest =
@@ -439,7 +480,7 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
439 rest
480 rest
440 }
481 }
441
482
442− tests : Found -> List (Attr msg) -> List (Element msg) -> List Test
483+ tests : Found -> List (Attr msg) -> List (Element msg) -> List LayoutTest
443 tests self attributes children =
484 tests self attributes children =
444 let
485 let
445 findBBox elem ( i, gathered ) =
486 findBBox elem ( i, gathered ) =
@@ -479,7 +520,6 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
479
520
480 attributeTests =
521 attributeTests =
481 attributes
522 attributes
482− |> applyLabels
483 |> List.indexedMap
523 |> List.indexedMap
484 -- Found -> Dict String Found -> List Int -> Int -> Surroundings -> Attr msg -> List Test
524 -- Found -> Dict String Found -> List Int -> Int -> Surroundings -> Attr msg -> List Test
485 (\i attr ->
525 (\i attr ->
@@ -511,7 +551,16 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
511 []
551 []
512
552
513 _ ->
553 _ ->
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+ ]
515
564
516 Just self ->
565 Just self ->
517 case element of
566 case element of
@@ -537,59 +586,31 @@ createTest { siblings, parent, cache, level, element, location, parentSpacing }
537 []
586 []
538
587
539
588
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
576createAttributeTest parent cache level attrIndex surroundings attr =
597createAttributeTest parent cache level attrIndex surroundings attr =
577 let
598 let
578− indexLabel =
599+ domId =
579− levelToString (attrIndex :: level)
600+ "#" ++ levelToString level
580 in
601 in
581 case attr of
602 case attr of
582 Attr _ ->
603 Attr _ ->
583 []
604 []
584
605
585− Label _ ->
586− []
587−
588 Spacing _ ->
606 Spacing _ ->
589 []
607 []
590
608
591− AttrTest test ->
609+ AttrTest details ->
610+ [ { elementDomId = domId
611+ , label = details.label
592− [ test surroundings
612+ , expectations = details.test surroundings
613+ }
593 ]
614 ]
594
615
595 Nearby nearby ->
616 Nearby nearby ->
@@ -600,7 +621,15 @@ createAttributeTest parent cache level attrIndex surroundings attr =
600 , parentSpacing = 0
621 , parentSpacing = 0
601 , level = attrIndex :: -1 :: level
622 , level = attrIndex :: -1 :: level
602 , location = IsNearby nearby.location
623 , 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
604 }
633 }
605
634
606 Batch batch ->
635 Batch batch ->
@@ -609,7 +638,10 @@ createAttributeTest parent cache level attrIndex surroundings attr =
609 |> List.concat
638 |> List.concat
610
639
611 LabeledTest { label, test } ->
640 LabeledTest { label, test } ->
641+ [ { elementDomId = domId
642+ , label = label
612− [ Test.test (label ++ " #" ++ indexLabel) (test surroundings)
643+ , expectations = test surroundings
644+ }
613 ]
645 ]
614
646
615
647
@@ -638,46 +670,43 @@ addAttribute attr el =
638 Text str
670 Text str
639
671
640
672
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
669
673
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
670− Test.Runner.Skipping rnrs ->
700+-- Test.Runner.Skipping rnrs ->
671− List.map run rnrs
701+-- List.map run rnrs
672−
673− Test.Runner.Invalid invalid ->
702+-- Test.Runner.Invalid invalid ->
674− let
703+-- let
675− _ =
704+-- _ =
676− Debug.log "Invalid tests" invalid
705+-- Debug.log "Invalid tests" invalid
677− in
706+-- in
678− []
707+-- []
679− in
708+-- in
680− List.concat results
709+-- List.concat results
681
710
682
711
683compareFormattedColor : Color -> String -> Bool
712compareFormattedColor : Color -> String -> Bool
tests-rendering/src/Testable/Element.elm+143−104
@@ -23,6 +23,8 @@ module Testable.Element exposing
23 , maximum
23 , maximum
24 , minimum
24 , minimum
25 , moveDown
25 , moveDown
26+ , moveLeft
27+ , moveRight
26 , moveUp
28 , moveUp
27 , none
29 , none
28 , onLeft
30 , onLeft
@@ -104,6 +106,12 @@ textColumn =
104 Testable.TextColumn
106 Testable.TextColumn
105
107
106
108
109+{-| Old labeling mechanism that i removed to hastily
110+-}
111+label str =
112+ Testable.Batch []
113+
114+
107moveUp x =
115moveUp x =
108 Testable.Attr (Element.moveUp x)
116 Testable.Attr (Element.moveUp x)
109
117
@@ -112,6 +120,14 @@ moveDown x =
112 Testable.Attr (Element.moveDown x)
120 Testable.Attr (Element.moveDown x)
113
121
114
122
123+moveRight x =
124+ Testable.Attr (Element.moveRight x)
125+
126+
127+moveLeft x =
128+ Testable.Attr (Element.moveLeft x)
129+
130+
115type Length
131type Length
116 = Px Int
132 = Px Int
117 | Fill Int
133 | Fill Int
@@ -156,11 +172,6 @@ fillPortion =
156 Fill
172 Fill
157
173
158
174
159−label : String -> Testable.Attr msg
160−label =
161− Testable.Label
162−
163−
164transparent : Bool -> Testable.Attr msg
175transparent : Bool -> Testable.Attr msg
165transparent on =
176transparent on =
166 Testable.LabeledTest
177 Testable.LabeledTest
@@ -172,7 +183,7 @@ transparent on =
172 "opaque"
183 "opaque"
173 , attr = Element.transparent on
184 , attr = Element.transparent on
174 , test =
185 , test =
175− \context _ ->
186+ \context ->
176 let
187 let
177 selfTransparency =
188 selfTransparency =
178 context.self.style
189 context.self.style
@@ -186,7 +197,7 @@ transparent on =
186 else
197 else
187 "1"
198 "1"
188 in
199 in
189− Expect.equal value selfTransparency
200+ [ Testable.equal value selfTransparency ]
190 }
201 }
191
202
192
203
@@ -197,8 +208,8 @@ isVisible =
197 { label = "is-visible"
208 { label = "is-visible"
198 , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
209 , attr = Element.htmlAttribute (Html.Attributes.style "not" "applicable")
199 , test =
210 , test =
200− \context _ ->
211+ \context ->
201− Expect.equal context.self.isVisible True
212+ [ Testable.equal context.self.isVisible True ]
202 }
213 }
203
214
204
215
@@ -209,14 +220,14 @@ alpha a =
209 { label = "alpha-" ++ String.fromFloat a
220 { label = "alpha-" ++ String.fromFloat a
210 , attr = Element.alpha a
221 , attr = Element.alpha a
211 , test =
222 , test =
212− \context _ ->
223+ \context ->
213 let
224 let
214 selfTransparency =
225 selfTransparency =
215 context.self.style
226 context.self.style
216 |> Dict.get "opacity"
227 |> Dict.get "opacity"
217 |> Maybe.withDefault "notfound"
228 |> Maybe.withDefault "notfound"
218 in
229 in
219− Expect.equal (String.fromFloat a) selfTransparency
230+ [ Testable.equal (String.fromFloat a) selfTransparency ]
220 }
231 }
221
232
222
233
@@ -227,8 +238,8 @@ padding pad =
227 { label = "padding " ++ String.fromInt pad
238 { label = "padding " ++ String.fromInt pad
228 , attr = Element.padding pad
239 , attr = Element.padding pad
229 , test =
240 , test =
230− \found _ ->
241+ \found ->
231− Expect.true ("Padding " ++ String.fromInt pad ++ " is present")
242+ [ Testable.true ("Padding " ++ String.fromInt pad ++ " is present")
232 (List.all ((==) pad)
243 (List.all ((==) pad)
233 [ floor found.self.bbox.padding.left
244 [ floor found.self.bbox.padding.left
234 , floor found.self.bbox.padding.right
245 , floor found.self.bbox.padding.right
@@ -236,6 +247,7 @@ padding pad =
236 , floor found.self.bbox.padding.bottom
247 , floor found.self.bbox.padding.bottom
237 ]
248 ]
238 )
249 )
250+ ]
239 }
251 }
240
252
241
253
@@ -246,8 +258,8 @@ paddingXY x y =
246 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
258 { label = "paddingXY " ++ String.fromInt x ++ ", " ++ String.fromInt y
247 , attr = Element.paddingXY x y
259 , attr = Element.paddingXY x y
248 , test =
260 , test =
249− \found _ ->
261+ \found ->
250− Expect.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
262+ [ Testable.true ("PaddingXY (" ++ String.fromInt x ++ ", " ++ String.fromInt y ++ ") is present")
251 (List.all ((==) x)
263 (List.all ((==) x)
252 [ floor found.self.bbox.padding.left
264 [ floor found.self.bbox.padding.left
253 , floor found.self.bbox.padding.right
265 , floor found.self.bbox.padding.right
@@ -257,6 +269,7 @@ paddingXY x y =
257 , floor found.self.bbox.padding.bottom
269 , floor found.self.bbox.padding.bottom
258 ]
270 ]
259 )
271 )
272+ ]
260 }
273 }
261
274
262
275
@@ -326,18 +339,20 @@ widthHelper maybeMin maybeMax len =
326 |> addMax
339 |> addMax
327 )
340 )
328 , test =
341 , test =
329− \found _ ->
342+ \found ->
330− Expect.all
331− [ \_ ->
332− Expect.true "exact width is exact" (floor found.self.bbox.width == val)
343+ [ Testable.true "exact width is exact" (floor found.self.bbox.width == val)
333− , \_ -> Expect.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
344+ , Testable.true "min/max is upheld" (minMaxTest (floor found.self.bbox.width))
334− ]
345+ ]
335− ()
336 }
346 }
337
347
338 Fill portion ->
348 Fill portion ->
339 Testable.LabeledTest
349 Testable.LabeledTest
350+ { label =
351+ if portion == 1 then
352+ "width fill" ++ minLabel ++ maxLabel
353+
354+ else
340− { label = "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
355+ "width fill-" ++ String.fromInt portion ++ minLabel ++ maxLabel
341 , attr =
356 , attr =
342 Element.width
357 Element.width
343 (Element.fillPortion portion
358 (Element.fillPortion portion
@@ -345,30 +360,30 @@ widthHelper maybeMin maybeMax len =
345 |> addMax
360 |> addMax
346 )
361 )
347 , test =
362 , test =
348− \context _ ->
363+ \context ->
349 if List.member context.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
364 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 ]
351
366
352 else
367 else
353 let
368 let
354 parentAvailableWidth =
369 parentAvailableWidth =
355 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
370 context.parent.bbox.width - (context.self.bbox.padding.left + context.self.bbox.padding.right)
356 in
371 in
357− case context.location of
372+ [ case context.location of
358 Testable.IsNearby _ ->
373 Testable.IsNearby _ ->
359− Expect.true "Nearby Element has fill width"
374+ Testable.true "Nearby Element has fill width"
360 ((floor context.parent.bbox.width == floor context.self.bbox.width)
375 ((floor context.parent.bbox.width == floor context.self.bbox.width)
361 || minMaxTest (floor context.self.bbox.width)
376 || minMaxTest (floor context.self.bbox.width)
362 )
377 )
363
378
364 Testable.InColumn ->
379 Testable.InColumn ->
365− Expect.true "Element within column has fill width"
380+ Testable.true "Element within column has fill width"
366 ((floor parentAvailableWidth == floor context.self.bbox.width)
381 ((floor parentAvailableWidth == floor context.self.bbox.width)
367 || minMaxTest (floor context.self.bbox.width)
382 || minMaxTest (floor context.self.bbox.width)
368 )
383 )
369
384
370 Testable.InEl ->
385 Testable.InEl ->
371− Expect.true "Element within element has fill width" <|
386+ Testable.true "Element within element has fill width" <|
372 (floor parentAvailableWidth == floor context.self.bbox.width)
387 (floor parentAvailableWidth == floor context.self.bbox.width)
373 || minMaxTest (floor context.self.bbox.width)
388 || minMaxTest (floor context.self.bbox.width)
374
389
@@ -377,9 +392,10 @@ widthHelper maybeMin maybeMax len =
377 spacePerPortion =
392 spacePerPortion =
378 parentAvailableWidth / toFloat (List.length context.siblings + 1)
393 parentAvailableWidth / toFloat (List.length context.siblings + 1)
379 in
394 in
380− Expect.true "element has fill width" <|
395+ Testable.true "element has fill width" <|
381 (floor spacePerPortion == floor context.self.bbox.width)
396 (floor spacePerPortion == floor context.self.bbox.width)
382 || minMaxTest (floor context.self.bbox.width)
397 || minMaxTest (floor context.self.bbox.width)
398+ ]
383 }
399 }
384
400
385 Shrink ->
401 Shrink ->
@@ -392,7 +408,7 @@ widthHelper maybeMin maybeMax len =
392 |> addMax
408 |> addMax
393 )
409 )
394 , test =
410 , test =
395− \context _ ->
411+ \context ->
396 let
412 let
397 childWidth child =
413 childWidth child =
398 -- TODO: add margin values to widths
414 -- TODO: add margin values to widths
@@ -412,12 +428,12 @@ widthHelper maybeMin maybeMax len =
412 if totalChildren == 0 then
428 if totalChildren == 0 then
413 -- TODO: The issue is that we have a hard time measuring `text` elements
429 -- TODO: The issue is that we have a hard time measuring `text` elements
414 -- So if a element has a text child, then it's width isn't going to show up in the system.
430 -- 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 ]
416
432
417 else
433 else
418 -- This fails if this element is actually a column
434 -- This fails if this element is actually a column
419 -- So we need to capture what this element is in order to do this calculation.
435 -- 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 ]
421 }
437 }
422
438
423
439
@@ -487,16 +503,12 @@ heightHelper maybeMin maybeMax len =
487 |> addMax
503 |> addMax
488 )
504 )
489 , test =
505 , test =
490− \found _ ->
506+ \found ->
491− Expect.all
492− [ \_ ->
493− Expect.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
507+ [ Testable.true ("exact height is exact: " ++ String.fromInt (floor found.self.bbox.height) ++ "," ++ String.fromInt val)
494− (floor found.self.bbox.height == val)
508+ (floor found.self.bbox.height == val)
495− , \_ ->
496− Expect.true "min/max holds true"
509+ , Testable.true "min/max holds true"
497− (minMaxTest (floor found.self.bbox.height))
510+ (minMaxTest (floor found.self.bbox.height))
498− ]
511+ ]
499− ()
500 }
512 }
501
513
502 Fill portion ->
514 Fill portion ->
@@ -509,30 +521,30 @@ heightHelper maybeMin maybeMax len =
509 |> addMax
521 |> addMax
510 )
522 )
511 , test =
523 , test =
512− \context _ ->
524+ \context ->
513− if List.member context.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
525+ [ 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
526+ Testable.true "height fill doesn't apply to above/below elements" True
515
527
516− else
528+ else
517 let
529 let
518 parentAvailableHeight =
530 parentAvailableHeight =
519 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
531 context.parent.bbox.height - (context.self.bbox.padding.top + context.self.bbox.padding.bottom)
520 in
532 in
521 case context.location of
533 case context.location of
522 Testable.IsNearby _ ->
534 Testable.IsNearby _ ->
523− Expect.true "Nearby Element has fill height"
535+ Testable.true "Nearby Element has fill height"
524 ((floor context.parent.bbox.height == floor context.self.bbox.height)
536 ((floor context.parent.bbox.height == floor context.self.bbox.height)
525 || minMaxTest (floor context.self.bbox.height)
537 || minMaxTest (floor context.self.bbox.height)
526 )
538 )
527
539
528 Testable.InColumn ->
540 Testable.InColumn ->
529− Expect.true "Element within column has fill height"
541+ Testable.true "Element within column has fill height"
530 ((floor parentAvailableHeight == floor context.self.bbox.height)
542 ((floor parentAvailableHeight == floor context.self.bbox.height)
531 || minMaxTest (floor context.self.bbox.height)
543 || minMaxTest (floor context.self.bbox.height)
532 )
544 )
533
545
534 Testable.InEl ->
546 Testable.InEl ->
535− Expect.true "Element within el has fill height" <|
547+ Testable.true "Element within el has fill height" <|
536 (floor parentAvailableHeight == floor context.self.bbox.height)
548 (floor parentAvailableHeight == floor context.self.bbox.height)
537 || minMaxTest (floor context.self.bbox.height)
549 || minMaxTest (floor context.self.bbox.height)
538
550
@@ -541,9 +553,10 @@ heightHelper maybeMin maybeMax len =
541 spacePerPortion =
553 spacePerPortion =
542 parentAvailableHeight / toFloat (List.length context.siblings + 1)
554 parentAvailableHeight / toFloat (List.length context.siblings + 1)
543 in
555 in
544− Expect.true "el has fill height" <|
556+ Testable.true "el has fill height" <|
545 (floor spacePerPortion == floor context.self.bbox.height)
557 (floor spacePerPortion == floor context.self.bbox.height)
546 || minMaxTest (floor context.self.bbox.height)
558 || minMaxTest (floor context.self.bbox.height)
559+ ]
547 }
560 }
548
561
549 Shrink ->
562 Shrink ->
@@ -556,7 +569,7 @@ heightHelper maybeMin maybeMax len =
556 |> addMax
569 |> addMax
557 )
570 )
558 , test =
571 , test =
559− \context _ ->
572+ \context ->
560 let
573 let
561 childWidth child =
574 childWidth child =
562 -- TODO: add margin values to heights
575 -- TODO: add margin values to heights
@@ -576,12 +589,12 @@ heightHelper maybeMin maybeMax len =
576 if totalChildren == 0 then
589 if totalChildren == 0 then
577 -- TODO: The issue is that we have a hard time measuring `text` elements
590 -- TODO: The issue is that we have a hard time measuring `text` elements
578 -- So if a element has a text child, then it's height isn't going to show up in the system.
591 -- 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 ]
580
593
581 else
594 else
582 -- This fails if this element is actually a column
595 -- This fails if this element is actually a column
583 -- So we need to capture what this element is in order to do this calculation.
596 -- 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 ]
585 }
598 }
586
599
587
600
@@ -603,7 +616,7 @@ spacing space =
603 { label = "spacing: " ++ String.fromInt space
616 { label = "spacing: " ++ String.fromInt space
604 , attr = Element.spacing space
617 , attr = Element.spacing space
605 , test =
618 , test =
606− \found _ ->
619+ \found ->
607 let
620 let
608 findDistance child total =
621 findDistance child total =
609 List.concatMap
622 List.concatMap
@@ -649,7 +662,7 @@ spacing space =
649 []
662 []
650 distances
663 distances
651 in
664 in
652− Expect.true
665+ [ Testable.true
653 ("All children are at least "
666 ("All children are at least "
654 ++ String.fromInt space
667 ++ String.fromInt space
655 ++ " pixels apart."
668 ++ " pixels apart."
@@ -657,6 +670,7 @@ spacing space =
657 ++ " are not though"
670 ++ " are not though"
658 )
671 )
659 (allAreSpaced == [])
672 (allAreSpaced == [])
673+ ]
660 }
674 }
661 ]
675 ]
662
676
@@ -680,28 +694,28 @@ alignLeft =
680 { label = "alignLeft"
694 { label = "alignLeft"
681 , attr = Element.alignLeft
695 , attr = Element.alignLeft
682 , test =
696 , test =
683− \found _ ->
697+ \found ->
684− if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
698+ [ 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
699+ Testable.true "alignLeft doesn't apply to elements that are onLeft or onRight" True
686
700
687− else if
701+ else if
688 List.member found.location
702 List.member found.location
689 [ Testable.IsNearby Testable.InFront
703 [ Testable.IsNearby Testable.InFront
690 , Testable.IsNearby Testable.Behind
704 , Testable.IsNearby Testable.Behind
691 , Testable.IsNearby Testable.Above
705 , Testable.IsNearby Testable.Above
692 , Testable.IsNearby Testable.Below
706 , Testable.IsNearby Testable.Below
693 ]
707 ]
694− then
708+ then
695 expectRoundedEquality
709 expectRoundedEquality
696 found.self.bbox.left
710 found.self.bbox.left
697 found.parent.bbox.left
711 found.parent.bbox.left
698
712
699− else if List.length found.siblings == 0 then
713+ else if List.length found.siblings == 0 then
700 expectRoundedEquality
714 expectRoundedEquality
701 found.self.bbox.left
715 found.self.bbox.left
702 (found.parent.bbox.left + found.parent.bbox.padding.left)
716 (found.parent.bbox.left + found.parent.bbox.padding.left)
703
717
704− else
718+ else
705 case found.location of
719 case found.location of
706 Testable.InRow ->
720 Testable.InRow ->
707 let
721 let
@@ -724,6 +738,7 @@ alignLeft =
724 expectRoundedEquality
738 expectRoundedEquality
725 found.self.bbox.left
739 found.self.bbox.left
726 (found.parent.bbox.left + found.parent.bbox.padding.left)
740 (found.parent.bbox.left + found.parent.bbox.padding.left)
741+ ]
727 }
742 }
728
743
729
744
@@ -734,7 +749,7 @@ centerX =
734 { label = "centerX"
749 { label = "centerX"
735 , attr = Element.centerX
750 , attr = Element.centerX
736 , test =
751 , test =
737− \found _ ->
752+ \found ->
738 let
753 let
739 selfCenter : Float
754 selfCenter : Float
740 selfCenter =
755 selfCenter =
@@ -745,12 +760,13 @@ centerX =
745 found.parent.bbox.left + (found.parent.bbox.width / 2)
760 found.parent.bbox.left + (found.parent.bbox.width / 2)
746 in
761 in
747 if List.member found.location [ Testable.IsNearby Testable.OnRight, Testable.IsNearby Testable.OnLeft ] then
762 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 ]
749
764
750 else if List.length found.siblings == 0 then
765 else if List.length found.siblings == 0 then
751− expectRoundedEquality
766+ [ expectRoundedEquality
752 selfCenter
767 selfCenter
753 parentCenter
768 parentCenter
769+ ]
754
770
755 else
771 else
756 case found.location of
772 case found.location of
@@ -783,12 +799,13 @@ centerX =
783 / 2
799 / 2
784 )
800 )
785 in
801 in
786− expectRoundedEquality
802+ [ expectRoundedEquality
787 selfCenter
803 selfCenter
788 expectedCenter
804 expectedCenter
805+ ]
789
806
790 _ ->
807 _ ->
791− expectRoundedEquality selfCenter parentCenter
808+ [ expectRoundedEquality selfCenter parentCenter ]
792 }
809 }
793
810
794
811
@@ -799,9 +816,9 @@ alignRight =
799 { label = "alignRight"
816 { label = "alignRight"
800 , attr = Element.alignRight
817 , attr = Element.alignRight
801 , test =
818 , test =
802− \found _ ->
819+ \found ->
803 if List.member found.location [ Testable.IsNearby Testable.OnLeft, Testable.IsNearby Testable.OnRight ] then
820 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 ]
805
822
806 else if
823 else if
807 List.member found.location
824 List.member found.location
@@ -811,14 +828,16 @@ alignRight =
811 , Testable.IsNearby Testable.Below
828 , Testable.IsNearby Testable.Below
812 ]
829 ]
813 then
830 then
814− expectRoundedEquality
831+ [ expectRoundedEquality
815 found.self.bbox.right
832 found.self.bbox.right
816 found.parent.bbox.right
833 found.parent.bbox.right
834+ ]
817
835
818 else if List.length found.siblings == 0 then
836 else if List.length found.siblings == 0 then
819− expectRoundedEquality
837+ [ expectRoundedEquality
820 found.self.bbox.right
838 found.self.bbox.right
821 (found.parent.bbox.right + found.parent.bbox.padding.right)
839 (found.parent.bbox.right + found.parent.bbox.padding.right)
840+ ]
822
841
823 else
842 else
824 case found.location of
843 case found.location of
@@ -835,14 +854,16 @@ alignRight =
835 |> List.map (.width << .bbox)
854 |> List.map (.width << .bbox)
836 |> List.sum
855 |> List.sum
837 in
856 in
838− expectRoundedEquality
857+ [ expectRoundedEquality
839 found.self.bbox.right
858 found.self.bbox.right
840 (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
859 (found.parent.bbox.right - (found.parent.bbox.padding.right + widthsOnRight + spacings))
860+ ]
841
861
842 _ ->
862 _ ->
843− expectRoundedEquality
863+ [ expectRoundedEquality
844 found.self.bbox.right
864 found.self.bbox.right
845 (found.parent.bbox.right + found.parent.bbox.padding.right)
865 (found.parent.bbox.right + found.parent.bbox.padding.right)
866+ ]
846 }
867 }
847
868
848
869
@@ -853,9 +874,9 @@ alignTop =
853 { label = "alignTop"
874 { label = "alignTop"
854 , attr = Element.alignTop
875 , attr = Element.alignTop
855 , test =
876 , test =
856− \found _ ->
877+ \found ->
857 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
878 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 ]
859
880
860 else if
881 else if
861 List.member found.location
882 List.member found.location
@@ -865,14 +886,16 @@ alignTop =
865 , Testable.IsNearby Testable.OnLeft
886 , Testable.IsNearby Testable.OnLeft
866 ]
887 ]
867 then
888 then
868− expectRoundedEquality
889+ [ expectRoundedEquality
869 found.self.bbox.top
890 found.self.bbox.top
870 found.parent.bbox.top
891 found.parent.bbox.top
892+ ]
871
893
872 else if List.length found.siblings == 0 then
894 else if List.length found.siblings == 0 then
873− expectRoundedEquality
895+ [ expectRoundedEquality
874 found.self.bbox.top
896 found.self.bbox.top
875 (found.parent.bbox.top + found.parent.bbox.padding.top)
897 (found.parent.bbox.top + found.parent.bbox.padding.top)
898+ ]
876
899
877 else
900 else
878 case found.location of
901 case found.location of
@@ -889,14 +912,16 @@ alignTop =
889 |> List.map (.height << .bbox)
912 |> List.map (.height << .bbox)
890 |> List.sum
913 |> List.sum
891 in
914 in
892− expectRoundedEquality
915+ [ expectRoundedEquality
893 found.self.bbox.top
916 found.self.bbox.top
894 (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
917 (found.parent.bbox.top + (found.parent.bbox.padding.top + heightsAbove + spacings))
918+ ]
895
919
896 _ ->
920 _ ->
897− expectRoundedEquality
921+ [ expectRoundedEquality
898 found.self.bbox.top
922 found.self.bbox.top
899 found.parent.bbox.top
923 found.parent.bbox.top
924+ ]
900 }
925 }
901
926
902
927
@@ -907,9 +932,9 @@ alignBottom =
907 { label = "alignBottom"
932 { label = "alignBottom"
908 , attr = Element.alignBottom
933 , attr = Element.alignBottom
909 , test =
934 , test =
910− \found _ ->
935+ \found ->
911 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
936 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 ]
913
938
914 else if
939 else if
915 List.member found.location
940 List.member found.location
@@ -919,14 +944,16 @@ alignBottom =
919 , Testable.IsNearby Testable.OnLeft
944 , Testable.IsNearby Testable.OnLeft
920 ]
945 ]
921 then
946 then
922− expectRoundedEquality
947+ [ expectRoundedEquality
923 found.self.bbox.bottom
948 found.self.bbox.bottom
924 found.parent.bbox.bottom
949 found.parent.bbox.bottom
950+ ]
925
951
926 else if List.length found.siblings == 0 then
952 else if List.length found.siblings == 0 then
927− expectRoundedEquality
953+ [ expectRoundedEquality
928 found.self.bbox.bottom
954 found.self.bbox.bottom
929 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
955 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
956+ ]
930
957
931 else
958 else
932 case found.location of
959 case found.location of
@@ -943,22 +970,30 @@ alignBottom =
943 |> List.map (.height << .bbox)
970 |> List.map (.height << .bbox)
944 |> List.sum
971 |> List.sum
945 in
972 in
946− expectRoundedEquality
973+ [ expectRoundedEquality
947 found.self.bbox.bottom
974 found.self.bbox.bottom
948 (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
975 (found.parent.bbox.bottom - (found.parent.bbox.padding.bottom + heightsBelow + spacings))
976+ ]
949
977
950 _ ->
978 _ ->
951− expectRoundedEquality
979+ [ expectRoundedEquality
952 found.self.bbox.bottom
980 found.self.bbox.bottom
953 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
981 (found.parent.bbox.bottom + found.parent.bbox.padding.bottom)
982+ ]
954 }
983 }
955
984
956
985
957expectRoundedEquality x y =
986expectRoundedEquality 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)
959 (abs (x - y) < 1)
989 (abs (x - y) < 1)
960
990
961
991
992+floatToString : Float -> String
993+floatToString x =
994+ String.fromFloat (toFloat (round (x * 100)) / 100)
995+
996+
962{-| -}
997{-| -}
963centerY : Testable.Attr msg
998centerY : Testable.Attr msg
964centerY =
999centerY =
@@ -966,7 +1001,7 @@ centerY =
966 { label = "centerY"
1001 { label = "centerY"
967 , attr = Element.centerY
1002 , attr = Element.centerY
968 , test =
1003 , test =
969− \found _ ->
1004+ \found ->
970 let
1005 let
971 selfCenter =
1006 selfCenter =
972 found.self.bbox.top + (found.self.bbox.height / 2)
1007 found.self.bbox.top + (found.self.bbox.height / 2)
@@ -975,12 +1010,13 @@ centerY =
975 found.parent.bbox.top + (found.parent.bbox.height / 2)
1010 found.parent.bbox.top + (found.parent.bbox.height / 2)
976 in
1011 in
977 if List.member found.location [ Testable.IsNearby Testable.Above, Testable.IsNearby Testable.Below ] then
1012 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 ]
979
1014
980 else if List.length found.siblings == 0 then
1015 else if List.length found.siblings == 0 then
981− expectRoundedEquality
1016+ [ expectRoundedEquality
982 selfCenter
1017 selfCenter
983 parentCenter
1018 parentCenter
1019+ ]
984
1020
985 else
1021 else
986 case found.location of
1022 case found.location of
@@ -1013,12 +1049,13 @@ centerY =
1013 / 2
1049 / 2
1014 )
1050 )
1015 in
1051 in
1016− expectRoundedEquality
1052+ [ expectRoundedEquality
1017 selfCenter
1053 selfCenter
1018 expectedCenter
1054 expectedCenter
1055+ ]
1019
1056
1020 _ ->
1057 _ ->
1021− expectRoundedEquality selfCenter parentCenter
1058+ [ expectRoundedEquality selfCenter parentCenter ]
1022 }
1059 }
1023
1060
1024
1061
@@ -1030,8 +1067,8 @@ above element =
1030 , element = element
1067 , element = element
1031 , label = "above"
1068 , label = "above"
1032 , test =
1069 , test =
1033− \found _ ->
1070+ \found ->
1034− expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top
1071+ [ expectRoundedEquality found.self.bbox.bottom found.parent.bbox.top ]
1035 }
1072 }
1036
1073
1037
1074
@@ -1043,8 +1080,8 @@ below element =
1043 , element = element
1080 , element = element
1044 , label = "below"
1081 , label = "below"
1045 , test =
1082 , test =
1046− \found _ ->
1083+ \found ->
1047− expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom
1084+ [ expectRoundedEquality found.self.bbox.top found.parent.bbox.bottom ]
1048 }
1085 }
1049
1086
1050
1087
@@ -1056,8 +1093,8 @@ onRight element =
1056 , element = element
1093 , element = element
1057 , label = "onRight"
1094 , label = "onRight"
1058 , test =
1095 , test =
1059− \found _ ->
1096+ \found ->
1060− expectRoundedEquality found.self.bbox.left found.parent.bbox.right
1097+ [ expectRoundedEquality found.self.bbox.left found.parent.bbox.right ]
1061 }
1098 }
1062
1099
1063
1100
@@ -1069,8 +1106,8 @@ onLeft element =
1069 , element = element
1106 , element = element
1070 , label = "onLeft"
1107 , label = "onLeft"
1071 , test =
1108 , test =
1072− \found _ ->
1109+ \found ->
1073− expectRoundedEquality found.self.bbox.right found.parent.bbox.left
1110+ [ expectRoundedEquality found.self.bbox.right found.parent.bbox.left ]
1074 }
1111 }
1075
1112
1076
1113
@@ -1086,11 +1123,12 @@ inFront element =
1086 , element = element
1123 , element = element
1087 , label = "inFront"
1124 , label = "inFront"
1088 , test =
1125 , test =
1126+ \found ->
1089− withinHelper
1127+ [ withinHelper found ]
1090 }
1128 }
1091
1129
1092
1130
1093−withinHelper found _ =
1131+withinHelper found =
1094 let
1132 let
1095 horizontalCheck =
1133 horizontalCheck =
1096 if found.self.bbox.width > found.parent.bbox.width then
1134 if found.self.bbox.width > found.parent.bbox.width then
@@ -1114,7 +1152,7 @@ withinHelper found _ =
1114 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
1152 , compare found.self.bbox.bottom (<=) found.parent.bbox.bottom
1115 ]
1153 ]
1116 in
1154 in
1117− Expect.true "within the confines of the parent"
1155+ Testable.true "within the confines of the parent"
1118 (List.all ((==) True)
1156 (List.all ((==) True)
1119 (List.concat
1157 (List.concat
1120 [ horizontalCheck
1158 [ horizontalCheck
@@ -1132,5 +1170,6 @@ behindContent element =
1132 , element = element
1170 , element = element
1133 , label = "behindContent"
1171 , label = "behindContent"
1134 , test =
1172 , test =
1173+ \found ->
1135− withinHelper
1174+ [ withinHelper found ]
1136 }
1175 }
tests-rendering/src/Testable/Element/Background.elm+4−4
@@ -5,23 +5,23 @@ module Testable.Element.Background exposing (color)
5import Dict
5import Dict
6import Element exposing (Color)
6import Element exposing (Color)
7import Element.Background as Background
7import Element.Background as Background
8−import Expect
9import Testable
8import Testable
10
9
11
10
12color : Color -> Testable.Attr msg
11color : Color -> Testable.Attr msg
13color clr =
12color clr =
14 Testable.LabeledTest
13 Testable.LabeledTest
15− { label = "background color-" ++ Testable.formatColor clr
14+ { label = "background color"
16 , attr = Background.color clr
15 , attr = Background.color clr
17 , test =
16 , test =
18− \context _ ->
17+ \context ->
19 let
18 let
20 selfBackgroundColor =
19 selfBackgroundColor =
21 context.self.style
20 context.self.style
22 |> Dict.get "background-color"
21 |> Dict.get "background-color"
23 |> Maybe.withDefault "notfound"
22 |> Maybe.withDefault "notfound"
24 in
23 in
25− Expect.true ("Expected color: " ++ (Testable.formatColor clr ++ " vs found:" ++ selfBackgroundColor))
24+ [ Testable.true ("expected: " ++ (Testable.formatColor clr ++ ", found:" ++ selfBackgroundColor))
26 (Testable.compareFormattedColor clr selfBackgroundColor)
25 (Testable.compareFormattedColor clr selfBackgroundColor)
26+ ]
27 }
27 }
tests-rendering/src/Testable/Element/Font.elm+6−4
@@ -15,15 +15,16 @@ color clr =
15 { label = "font color-" ++ Testable.formatColor clr
15 { label = "font color-" ++ Testable.formatColor clr
16 , attr = Font.color clr
16 , attr = Font.color clr
17 , test =
17 , test =
18− \context _ ->
18+ \context ->
19 let
19 let
20 selfFontColor =
20 selfFontColor =
21 context.self.style
21 context.self.style
22 |> Dict.get "color"
22 |> Dict.get "color"
23 |> Maybe.withDefault "notfound"
23 |> Maybe.withDefault "notfound"
24 in
24 in
25− Expect.true ("Color Match - " ++ (Testable.formatColor clr ++ " vs " ++ selfFontColor))
25+ [ Testable.true ("Color Match - " ++ (Testable.formatColor clr ++ " vs " ++ selfFontColor))
26 (Testable.compareFormattedColor clr selfFontColor)
26 (Testable.compareFormattedColor clr selfFontColor)
27+ ]
27 }
28 }
28
29
29
30
@@ -33,7 +34,7 @@ size i =
33 { label = "font size-" ++ String.fromInt i
34 { label = "font size-" ++ String.fromInt i
34 , attr = Font.size i
35 , attr = Font.size i
35 , test =
36 , test =
36− \context _ ->
37+ \context ->
37 let
38 let
38 selfFontSize =
39 selfFontSize =
39 context.self.style
40 context.self.style
@@ -43,6 +44,7 @@ size i =
43 formattedInt =
44 formattedInt =
44 String.fromInt i
45 String.fromInt i
45 in
46 in
46− Expect.true ("Size Match - " ++ (formattedInt ++ " vs " ++ selfFontSize))
47+ [ Testable.true ("Size Match - " ++ (formattedInt ++ " vs " ++ selfFontSize))
47 (formattedInt == selfFontSize)
48 (formattedInt == selfFontSize)
49+ ]
48 }
50 }
tests-rendering/src/Testable/Runner.elm+210−181
@@ -3,27 +3,23 @@ port module Testable.Runner exposing (Msg, TestableProgram, program, show)
3{-| -}
3{-| -}
4
4
5import Browser
5import Browser
6−import Char
7import Dict exposing (Dict)
6import Dict exposing (Dict)
8import Element
7import Element
9import Element.Background as Background
8import Element.Background as Background
10import Element.Border as Border
9import Element.Border as Border
10+import Element.Events as Events
11import Element.Font as Font
11import Element.Font as Font
12import Html exposing (Html)
12import Html exposing (Html)
13−import Parser exposing ((|.), (|=))
13+import Html.Attributes
14import Process
14import Process
15−import Random
16−import Set
17import Task
15import Task
18−import Test.Runner
19−import Test.Runner.Failure as Failure
20import Testable
16import Testable
21import Time
17import Time
22
18
23
19
24show : Testable.Element msg -> Html msg
20show : Testable.Element msg -> Html msg
25show =
21show =
26− Testable.render
22+ Testable.toHtml
27
23
28
24
29type alias TestableProgram =
25type alias TestableProgram =
@@ -56,6 +52,7 @@ program tests =
56 ( { current = current
52 ( { current = current
57 , upcoming = upcoming
53 , upcoming = upcoming
58 , finished = []
54 , finished = []
55+ , highlightDomId = Nothing
59 }
56 }
60 , Task.perform (always Analyze)
57 , Task.perform (always Analyze)
61 (Process.sleep 32
58 (Process.sleep 32
@@ -80,6 +77,7 @@ type alias Model msg =
80 { current : Maybe ( String, Testable.Element msg )
77 { current : Maybe ( String, Testable.Element msg )
81 , upcoming : List ( String, Testable.Element msg )
78 , upcoming : List ( String, Testable.Element msg )
82 , finished : List (WithResults (Testable.Element msg))
79 , finished : List (WithResults (Testable.Element msg))
80+ , highlightDomId : Maybe String
83 }
81 }
84
82
85
83
@@ -87,49 +85,44 @@ type alias WithResults thing =
87 { element : thing
85 { element : thing
88 , label : String
86 , label : String
89 , results :
87 , results :
90− List
88+ List Testable.LayoutTest
91− ( String
92− , Maybe
93− { given : Maybe String
94− , description : String
95− , reason : Failure.Reason
96− }
97− )
98 }
89 }
99
90
100
91
101−prepareResults :
92+encodeForReport :
102 List (WithResults (Testable.Element msg))
93 List (WithResults (Testable.Element msg))
103 ->
94 ->
104 List
95 List
105 { label : String
96 { label : String
106 , results :
97 , results :
107 List
98 List
108− ( String
109− , Maybe
110− { given : Maybe String
111− , description : String
99+ { description : String
100+ , passing : Bool
101+ , todo : Bool
112− }
102+ }
113− )
114 }
103 }
115−prepareResults withResults =
104+encodeForReport withResults =
116 let
105 let
117− prepareNode ( x, maybeResult ) =
106+ prepareExpectation layoutTest exp =
118− ( x
119− , case maybeResult of
107+ case exp of
120− Nothing ->
108+ Testable.Todo description ->
121− Nothing
109+ { description = description
110+ , passing = False
111+ , todo = True
112+ }
122
113
123− Just res ->
114+ Testable.Expect details ->
124− Just
115+ { description = details.description
125− { given = res.given
116+ , passing = details.result
126− , description = res.description
117+ , todo = False
127− }
118+ }
128− )
119+
120+ prepareNode layoutTest =
121+ List.map (prepareExpectation layoutTest) layoutTest.expectations
129
122
130 prepare { label, results } =
123 prepare { label, results } =
131 { label = label
124 { label = label
132− , results = List.map prepareNode results
125+ , results = List.concatMap prepareNode results
133 }
126 }
134 in
127 in
135 List.map prepare withResults
128 List.map prepare withResults
@@ -138,6 +131,7 @@ prepareResults withResults =
138type Msg
131type Msg
139 = NoOp
132 = NoOp
140 | Analyze
133 | Analyze
134+ | HighlightDomID (Maybe String)
141 | RefreshBoundingBox
135 | RefreshBoundingBox
142 (List
136 (List
143 { id : String
137 { id : String
@@ -151,14 +145,8 @@ type Msg
151runTest : Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
145runTest : Dict String Testable.Found -> String -> Testable.Element msg -> WithResults (Testable.Element msg)
152runTest boxes label element =
146runTest boxes label element =
153 let
147 let
154− tests =
155− Testable.toTest label boxes element
156−
157− seed =
158− Random.initialSeed 227852860
159−
160 results =
148 results =
161− Testable.runTests seed tests
149+ Testable.runTests boxes element
162 in
150 in
163 { element = element
151 { element = element
164 , label = label
152 , label = label
@@ -172,6 +160,11 @@ update msg model =
172 NoOp ->
160 NoOp ->
173 ( model, Cmd.none )
161 ( model, Cmd.none )
174
162
163+ HighlightDomID newId ->
164+ ( { model | highlightDomId = newId }
165+ , Cmd.none
166+ )
167+
175 RefreshBoundingBox boxes ->
168 RefreshBoundingBox boxes ->
176 case model.current of
169 case model.current of
177 Nothing ->
170 Nothing ->
@@ -203,7 +196,7 @@ update msg model =
203 | current = Nothing
196 | current = Nothing
204 , finished = model.finished ++ [ currentResults ]
197 , finished = model.finished ++ [ currentResults ]
205 }
198 }
206− , report (prepareResults (currentResults :: model.finished))
199+ , report (encodeForReport (currentResults :: model.finished))
207 )
200 )
208
201
209 newCurrent :: remaining ->
202 newCurrent :: remaining ->
@@ -246,23 +239,42 @@ view model =
246 [ Element.spacing 20
239 [ Element.spacing 20
247 , Element.padding 20
240 , Element.padding 20
248 , Element.width (Element.px 800)
241 , Element.width (Element.px 800)
249−
250− -- , Background.color Color.grey
251 ]
242 ]
252 [ Element.none ]
243 [ Element.none ]
253
244
254 finished :: remaining ->
245 finished :: remaining ->
255− if False then
256− viewResultsInline finished
257−
258− else
259− Element.layout [] <|
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+ )
260− Element.column
271+ , Element.column
261 [ Element.spacing 20
272 [ Element.spacing 20
262 , Element.padding 20
273 , Element.padding 20
263− , Element.width (Element.px 800)
274+ , Element.width Element.fill
264 ]
275 ]
265 (List.map viewResult (finished :: remaining))
276 (List.map viewResult (finished :: remaining))
277+ ]
266 ]
278 ]
267 }
279 }
268
280
@@ -274,162 +286,181 @@ view model =
274 Just ( label, current ) ->
286 Just ( label, current ) ->
275 { title = "running"
287 { title = "running"
276 , body =
288 , body =
277− [ Testable.render current ]
289+ [ Testable.toHtml current ]
278 }
290 }
279
291
280
292
281−viewResultsInline : WithResults (Testable.Element Msg) -> Html Msg
293+viewElementHighlight model =
282−viewResultsInline testable =
294+ case model.highlightDomId of
283− Html.div
295+ Nothing ->
284− []
296+ Html.text ""
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
307
297
298+ Just highlightDomId ->
299+ let
300+ elementHighlight =
301+ highlightDomId ++ " { outline: solid; }"
308
302
309−viewResultsAnnotationStylesheet results =
303+ testId =
310− let
304+ highlightDomId
311− toStyleClass ( label, maybeFailure ) =
305+ |> String.dropLeft 1
312− case maybeFailure of
306+ |> String.append "#tests-"
313− Nothing ->
314− ""
315
307
316− Just failure ->
308+ testHighlight =
317− case parseId label of
309+ testId ++ " { outline: dashed; }"
318− Nothing ->
319− Debug.log "NO ID FOUND" label
320
310
321− Just id ->
322− id ++ " { background-color:red; outline: dashed; };"
323−
324− styleSheet =
311+ styleSheet =
325− results
326− |> List.map toStyleClass
327− |> String.join ""
312+ String.join "\n"
313+ [ elementHighlight
314+ , testHighlight
315+ ]
328− in
316+ in
329− Html.node "style"
317+ Html.node "style"
330− []
318+ []
331− [ Html.text styleSheet
319+ [ Html.text styleSheet
332− ]
320+ ]
333
321
334
322
335viewResult : WithResults (Testable.Element Msg) -> Element.Element Msg
323viewResult : WithResults (Testable.Element Msg) -> Element.Element Msg
336viewResult testable =
324viewResult testable =
337 let
325 let
338− isPassing result =
326+ isExpectationPassing result =
339− case Tuple.second result of
327+ case result of
340− Nothing ->
328+ Testable.Todo label ->
341 True
329 True
342
330
343− Just _ ->
331+ Testable.Expect details ->
344− False
332+ details.result
333+
334+ isPassing layoutTest =
335+ List.any isExpectationPassing layoutTest.expectations
345
336
346 ( passing, failing ) =
337 ( passing, failing ) =
347 List.partition isPassing testable.results
338 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− ]
376 in
339 in
377 Element.column
340 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
383 , Element.spacing 16
342 , Element.spacing 16
384 ]
343 ]
385− [ Element.el [ Font.bold, Font.size 64 ] (Element.text testable.label)
344+ [ Element.el [ Font.size 24 ] (Element.text testable.label)
386 , Element.column [ Element.alignLeft, Element.spacing 20 ]
345 , Element.column [ Element.alignLeft, Element.spacing 20 ]
387− (failing
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
388− |> List.map viewSingle
358+ |> List.map
359+ (\( fst, remaining ) ->
360+ { id = fn fst
361+ , members = fst :: remaining
362+ }
389 )
363 )
390− , Element.el
364+
391− [ Element.alignLeft
365+
392− , Element.spacing 20
366+groupWhile : (a -> a -> Bool) -> List a -> List ( a, List a )
393− , Background.color palette.green
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+ ]
394− , Font.color palette.black
399+ [ Element.el [ Font.color palette.lightGrey ] (Element.text group.id)
400+ , Element.column
401+ [ Element.spacing 8
395− , Element.paddingXY 20 10
402+ , Element.paddingXY 32 0
396− , Element.alignLeft
397− , Border.rounded 3
398 ]
403 ]
399− (Element.text (String.fromInt (List.length passing) ++ " tests passing!"))
404+ (List.map viewLayoutTest group.members)
400 ]
405 ]
401
406
402
407
403−viewReason { description, reason } =
408+type alias Grouped thing =
404− case reason of
409+ { id : String
405− Failure.Custom ->
410+ , members : List thing
406− description
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)
407
420
408− Failure.Equality one two ->
421+ -- , Element.el [ Font.color palette.lightGrey ] (Element.text layoutTest.elementDomId)
409− description ++ " " ++ one ++ " " ++ two
422+ ]
423+ , Element.column [ Element.spacing 8 ]
424+ (List.map viewLayoutExpectation layoutTest.expectations)
425+ ]
410
426
411− Failure.Comparison one two ->
412− description ++ " " ++ one ++ " " ++ two
413
427
414− Failure.ListDiff expected actual ->
428+viewLayoutExpectation expectation =
415− "expected\n"
429+ case expectation of
416− ++ String.join " \n" expected
430+ Testable.Todo label ->
417− ++ "actual\n"
431+ Element.row [ Element.spacing 4 ]
418− ++ String.join " \n" actual
432+ [ todo, Element.text label ]
419
433
420− Failure.CollectionDiff { expected, actual, extra, missing } ->
434+ Testable.Expect details ->
421− String.join "\n"
435+ if details.result then
422− [ formatKeyValue "expected" expected
436+ Element.row [ Element.spacing 4 ]
423− , formatKeyValue "actual" actual
437+ [ pass, Element.text details.description ]
424− , formatKeyValue "extra" (String.join ", " extra)
438+
425− , formatKeyValue "missing" (String.join ", " missing)
439+ else
426− ]
440+ Element.row [ Element.spacing 4 ]
441+ [ fail, Element.text details.description ]
427
442
428− Failure.TODO ->
429− description
430
443
431− Failure.Invalid _ ->
444+badge color text =
432− description
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"
433
464
434
465
435formatKeyValue : String -> String -> String
466formatKeyValue : String -> String -> String
@@ -442,12 +473,10 @@ port report :
442 { label : String
473 { label : String
443 , results :
474 , results :
444 List
475 List
445− ( String
446− , Maybe
447− { given : Maybe String
448− , description : String
476+ { description : String
477+ , passing : Bool
478+ , todo : Bool
449− }
479+ }
450− )
451 }
480 }
452 -> Cmd msg
481 -> Cmd msg
453
482
tests-rendering/view/view.html+1−1
@@ -9,7 +9,7 @@
9 <body id="root"></body>
9 <body id="root"></body>
10
10
11 <script type="text/javascript">
11 <script type="text/javascript">
12− var app = Elm.InFrontSize.init();
12+ var app = Elm.WeirdCentering.init();
13
13
14 var test_results = "waiting..";
14 var test_results = "waiting..";
15
15