Skip to content

Commit d13f30b

Browse files
authored
Merge pull request #273 from ritaf-ORM/patch-9
Rita's edits ch 16
2 parents c0ca388 + fc24e4c commit d13f30b

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

chapter_16_javascript.asciidoc

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[chapter_16_javascript]]
22
== A Gentle Excursion Into JavaScript
33

4-
[quote, Geoffrey Willans]
4+
[quote, Geoffrey Willans, English author and journalist]
55
______________________________________________________________
66
You can never understand one language until you understand at least two.
77
______________________________________________________________
@@ -24,13 +24,16 @@ once the user started fixing the problem?
2424
Just like our nice HTML5 validation errors do?
2525
For that we'd need a teeny-tiny bit of JavaScript.
2626

27+
28+
// RITA: In this paragraph, please tell us how we're going to play around with JavaScript and what it'll teach us. I mean, you're going to use Javascript to make it so the duplicate item error message disappears once the user fixes the problem.
2729
Python is a delightful language to program in.
2830
JavaScript wasn't always that.
2931
But many of the rough edges have been smoothed off,
30-
and I think it's fair to say that it's actually quite nice now.
31-
And in the world of web development, it's unavoidable.
32+
and I think it's fair to say that JavaScript is actually quite nice now.
33+
And in the world of web development, using JavaScript is unavoidable.
3234
So let's dip our toes in, and see if we can't have a bit of fun.
3335

36+
// RITA: Consider dropping mention of JavaScript: The Good Parts and just referencing your more recent recommendations. If you've read Eloquent JavaScript, consider dropping "I've heard good things" to make your recommendation sound more confident. I suppose you could still mention JavaScript: The Good Parts after that.
3437
NOTE: I'm going to assume you know the basics of JavaScript syntax.
3538
If not, I used to recommend https://amzn.to/3UXVUKd[JavaScript: The Good Parts],
3639
which was the best guide, once upon a time.
@@ -46,6 +49,8 @@ NOTE: I'm going to assume you know the basics of JavaScript syntax.
4649

4750
((("JavaScript testing", "functional test")))
4851
((("functional tests (FTs)", "JavaScript", id="FTjava16")))
52+
53+
// RITA: In this first paragraph, please tell us WHY we're adding a new FT. How does this relate to making it so the duplicate item error messages disappear once the user fixes the problem? Give us context.
4954
Let's add a new functional test to the `ItemValidationTest` class:
5055

5156
[role="sourcecode"]
@@ -91,7 +96,7 @@ def test_error_messages_are_cleared_on_input(self):
9196
rather than removing them from the DOM altogether.
9297

9398

94-
That fails appropriately:
99+
The functional test fails appropriately:
95100

96101

97102

@@ -111,6 +116,7 @@ _validation.ItemValidationTest.test_error_messages_are_cleared_on_input)
111116
AssertionError: True is not false
112117
----
113118

119+
// RITA: Move on to do what?
114120
But, before we move on: three strikes and refactor!
115121
We've got several places where we find the error element using CSS.
116122
Let's move the logic to a helper function:
@@ -199,6 +205,7 @@ TIP: Always do a commit before embarking on a spike.
199205

200206
==== A Simple Inline Script
201207

208+
// RITA: First thing you came up with to do what?
202209
I hacked around for a bit,
203210
and here's more or less the first thing I came up with.
204211
I'm adding the code inline, in a `<script>` tag
@@ -269,13 +276,13 @@ TIP: It's good practice to put your script loads at the end of your body HTML,
269276
The test might be happy, but our solution is a little unsatisfactory.
270277
If you actually try it in your browser,
271278
you'll see that although the error message is gone,
272-
the input is still red an invalid-looking, see <<input-still-red>>.
279+
the input is still red and invalid-looking, see <<input-still-red>>.
273280

274281
[[input-still-red]]
275282
.The error message is gone but the input box is still red
276283
image::images/error-gone-but-input-still-red.png["Screenshot of our page where the error div is gone but the input is still red."]
277284

278-
You're probably imagining that this is something to do with Bootstrap.
285+
You're probably imagining that this has something to do with Bootstrap.
279286
We might have been able to hide the error message,
280287
but we also need to tell bootstrap that this input no longer has invalid contents.
281288

@@ -298,12 +305,14 @@ but also the red border around the input box.
298305
We have a reasonable solution now, time to de-spike!
299306

300307

301-
.Do we Really Need to Write Unit Tests for This?
308+
.Do We Really Need to Write Unit Tests for This?
302309
*******************************************************************************
303310
311+
// RITA: The first sentence following a heading should not refer syntactically to the heading; words should be repeated where necessary.
304312
By this point in the book, you probably know I'm going to say "yes",
305313
but let's talk about it anyway.
306314
315+
// RITA: What functionality?
307316
Our FT definitely covers this functionality,
308317
and we could extend it if we wanted to,
309318
to check on the colour of the input box,
@@ -361,7 +370,7 @@ without needing to dive into the whole Node/NPM ecosystem.
361370
// TODO: go all in and use jasmine-browser-runner instead,
362371
// it will let me use ES6 modules.
363372

364-
Let's download that now:
373+
Let's download Jasmine now:
365374

366375
[role="small-code"]
367376
[subs="specialcharacters,quotes"]
@@ -499,6 +508,8 @@ image::images/jasmine-in-browser-red.png["Jasmine browser-based spec runner show
499508

500509
.Is the Jasmine Standalone Browser Test Runner Unconventional?
501510
*******************************************************************************
511+
512+
// RITA: Again, the first sentence following a heading should not refer syntactically to the heading; words should be repeated where necessary.
502513
I think it probably is, to be honest.
503514
Although the JavaScript world moves so fast,
504515
I could be wrong by the time you read this.
@@ -637,7 +648,7 @@ on-failure messages into individual `expect/toBe` expressions.
637648

638649
If you refresh the browser, you should see that all passes:
639650

640-
651+
// RITA: You don't usually have captions other than commits. Was this one intentional?
641652
[[first-jasmine-output]]
642653
.Expected results from Jasmine in the browser
643654
====
@@ -653,7 +664,7 @@ Superlists tests
653664
----
654665
====
655666

656-
667+
// RITA: Should this be put into a note box?
657668
(I'll show the Jasmine outputs as text, as in <<first-jasmine-output>>, from now on,
658669
to avoid filling the chapter with screenshots.)
659670

@@ -769,6 +780,8 @@ Expected true to be false.
769780
((("global state")))
770781
((("JavaScript testing", "key challenges of", id="JSTkey16")))
771782
((("HTML fixtures")))
783+
784+
// RITA: In this paragraph, please tell us how this relates to the goal of the example in this chapter. How does this help the goal of this chapter, which is to get rid of the duplicate item error messages as they are resolved?
772785
One of the difficulties with JavaScript in general, and testing in particular,
773786
is in understanding the order of execution of our code (i.e., what happens when).
774787
When does our code in _lists.js_ run, and when does each of our tests run? And
@@ -901,7 +914,7 @@ And in our tests file, we call `initialize()` in our key test:
901914
});
902915
----
903916
====
904-
917+
//RITA: What does "here" refer to?
905918
<1> Here. We don't need to call it in our sense-check.
906919

907920

@@ -918,7 +931,7 @@ Superlists tests
918931
* error message should be hidden on input
919932
* sense-check our html fixture
920933
----
921-
934+
// RITA: Why does it make more sense now?
922935
And now the `console.log` outputs should make more sense:
923936

924937
[role="skipme"]
@@ -934,9 +947,10 @@ initialize called lists.js:3:11
934947
=== Deliberately Breaking Our Code to Force Ourselves To Write More Tests
935948

936949
I'm always nervous when I see green tests.
937-
We've copy-pasted 5 lines of code from our spike with just one test?
950+
We've copy-pasted five lines of code from our spike with just one test.
938951
That was a little too easy, even despite that little `initialize()` dance.
939952

953+
// RITA: Why do we want to try to deliberately break the initialize function? Give us context.
940954
Let's change our `initialize()` function to deliberately break it.
941955
What if we just immediately hide errors?
942956

@@ -1041,6 +1055,7 @@ so that they're defined in the same file that actually has the HTML elements.
10411055

10421056
And while we're at it, our tests could do with a bit of refactoring too!
10431057

1058+
// RITA: Please tell us the goal of the following code block.
10441059

10451060
[role="sourcecode"]
10461061
.src/lists/static/tests/Spec.js (ch16l022)
@@ -1256,7 +1271,7 @@ Expected true to be false.
12561271
<Jasmine>
12571272
----
12581273

1259-
Ok, back to the right way around:
1274+
OK, back to the right way around:
12601275

12611276
[role="sourcecode"]
12621277
.src/lists/static/lists.js (ch16l027)
@@ -1334,6 +1349,7 @@ NOTE: We're using `<script>` tag to import our code,
13341349
As the tests flashed past, you may have noticed an unsatisfactory bit of red,
13351350
still left around our input box.
13361351

1352+
// RITA: Please make sure to conclude this in the spike section so that you can call back to it here.
13371353
Wait a minute! We forgot one of the key things we learned in our spike!
13381354
We don't need to manually hack `style.display=none`,
13391355
we can work _with_ the Boostrap framework,
@@ -1484,7 +1500,7 @@ And the base template, yay. Nothing more satisfying than _deleting code_:
14841500
----
14851501
====
14861502

1487-
1503+
// RITA: Are we missing code here?
14881504
And we can run the FT one more time, just for safety:
14891505

14901506

@@ -1497,13 +1513,13 @@ And we can run the FT one more time, just for safety:
14971513

14981514
[[columbo-onload]]
14991515
=== Columbo Says: wait for Onload
1500-
1501-
[quote, Columbo]
1516+
// RITA: We need a descriptor to give Columbo context.
1517+
[quote, Columbo, fictional American detective]
15021518
______________________________________________________________
15031519
Wait, there's just one more thing...
15041520
______________________________________________________________
15051521

1506-
1522+
// RITA: It might be nice to add something to the effect of "before we continue, it's good to do one more thing" so that it ties in with the Columbo quote.
15071523
Finally, whenever you have some JavaScript that interacts with the DOM,
15081524
it's always good to wrap it in some "onload" boilerplate
15091525
to make sure that the page has fully loaded before it tries to do anything.
@@ -1525,7 +1541,7 @@ The modern js onload boilerplate is minimal
15251541
</script>
15261542
----
15271543
====
1528-
1544+
// RITA: Please embed URLs to descriptive text. Also, this link didn't work for me. Please check.
15291545
Read more here
15301546

15311547
https://developer.mozilla.org/en-US/docs/Web/API/Window/load_even://developer.mozilla.org/en-US/docs/Web/API/Window/load_event
@@ -1540,13 +1556,14 @@ https://developer.mozilla.org/en-US/docs/Web/API/Window/load_even://developer.mo
15401556
You may be wondering how these JavaScript tests fit in with our "double loop" TDD cycle.
15411557
The answer is that they play exactly the same role as our Python unit tests.
15421558

1559+
// RITA: Please add a sentence to introduce this list. What is the process described by the items in the list?
15431560
1. Write an FT and see it fail.
15441561
2. Figure out what kind of code you need next: Python or JavaScript?
15451562
3. Write a unit test in either language, and see it fail.
15461563
4. Write some code in either language, and make the test pass.
15471564
5. Rinse and repeat.
15481565

1549-
1566+
// RITA: Tell the reader what will happen in Part 3. Also, tell us the next step will be covered in the next chapter.
15501567
We're almost ready to move on to <<part3>>. The last step is to deploy our
15511568
new code to our servers.
15521569
Don't forget to do a final commit including _base.html_ first!
@@ -1588,7 +1605,7 @@ NOTE: Want a little more practice with JavaScript? See if you can get our
15881605
((("global state")))
15891606
15901607
* An awful lot of frontend work these days is done in frameworks,
1591-
React being the 1000-pound gorilla.
1608+
React being the 1,000-pound gorilla.
15921609
There are lots of resources on React testing out there,
15931610
so I'll let you go out and find them if you need them.
15941611

0 commit comments

Comments
 (0)