Skip to content

Commit 8aafc99

Browse files
committed
add link to https://github.com/dwyl/learn-tape as using Tape in Todo List App example #44
1 parent 94bbbbf commit 8aafc99

File tree

3 files changed

+88
-137
lines changed

3 files changed

+88
-137
lines changed

Diff for: test/elmish.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const test = require('tape'); // see: https://github.com/dwyl/learn-tape
2+
const fs = require('fs');
3+
const path = require('path');
4+
const { JSDOM } = require("jsdom"); // https://github.com/jsdom/jsdom
5+
6+
// const html = fs.readFileSync(path.resolve(__dirname,
7+
// '../examples/counter-reset/index.html'));
8+
// const DOM = new JSDOM(html); // create DOM based on HTML
9+
// const id = 'test-app';
10+
// const document = DOM.window.document; // shortcut to JSDOM document
11+
// const counter = require(path.resolve(__dirname,
12+
// '../examples/counter-reset/counter.js'));
13+
// const { view, mount, update, div, button, empty, init} = counter;
14+
// init(document); // pass the JSDOM into counter.js
15+
16+
// test('Mount app expect state to be Zero', function (t) {
17+
// mount(0, update, view, id);
18+
// var actual = document.getElementById(id).textContent;
19+
// var actual_stripped = parseInt(actual.replace('+', '').replace('-Reset', ''), 10);
20+
// var expected = 0;
21+
// t.equal(expected, actual_stripped, "Inital state set to 0.");
22+
// t.end()
23+
// });
24+
//
25+
// test('Test Update update(0) returns 0 (current state)', function (t) {
26+
// var result = update(0);
27+
// t.equal(result, 0, "Initial state: 0, No Action, Final state: 0");
28+
// t.end();
29+
// });

Diff for: test/test.js

-135
This file was deleted.

Diff for: todo-list.md

+59-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ by opening a question you help _everyone_ learn more effectively!
6262

6363
## _How?_
6464

65+
### Testing?
66+
67+
_Before_ diving into _building_ the Todo List App,
68+
we need to consider how we are going to _test_ it.
69+
By ensuring that we follow **TDD** from the _start_ of an App,
70+
we won't need to "correct" any "**bad habits**".
71+
72+
We will be using **Tape** and **JSDOM** for testing
73+
both our functions and the final application.
74+
If you are `new` to either of these tools,
75+
please see:
76+
[https://github.com/dwyl/**learn-tape**](https://github.com/dwyl/learn-tape)
77+
and
78+
[front-end-with-tape.md](https://github.com/dwyl/learn-tape/blob/master/front-end-with-tape.md)
79+
80+
### _Analyse_
81+
6582
Our _first_ step is to _analyse_ the required functionality of a Todo List.
6683

6784
### Todo List _Basic_ Functionality
@@ -157,6 +174,9 @@ each `case` is functionality that is _specific_ to the Todo List App. <br />
157174
The `view` function _invokes_ several "helper" functions
158175
which create HTML elements e.g: `div` & `<button>`; these _can_ be generalised.
159176

177+
178+
### HTML Elements (Functions)
179+
160180
The _requirements_ for the HTML elements we _need_ for a Todo List
161181
can be _gathered_ by viewing the source code of the VanillaJS TodoMVC
162182
in a web browser:
@@ -210,17 +230,54 @@ This is a "copy-paste" of the _generated_ code including the Todo items:
210230
</section>
211231
```
212232

233+
Let's split each one of these elements into it's own `function`
234+
(_with any necessary "helpers"_) in the order they appear.
213235

236+
#### `<section>`
214237

238+
The _first_ HTML we encounter in the TodoMVC app is
239+
`<section>`.
240+
`<section>` represents a standalone section — which doesn't have
241+
a more specific semantic element to represent it —
242+
it's an alternative way to group elements to a `<div>`.
243+
244+
> info: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section <br />
245+
> difference:
246+
https://stackoverflow.com/questions/6939864/what-is-the-difference-between-section-and-div
247+
248+
As with other "grouping" or "container" HTML elements,
249+
our `section` function (_which will create the_ `<section>` _DOM node_)
250+
will be a function with _two_ arguments:
251+
+ `attributes` - a list (Array) of HTML attributes/properties
252+
e.g: `id` or `class`.
253+
+ `children` - a list (Array) of child HTML elements
254+
(_nested within the_ `<section>`)
255+
256+
Each of these function arguments will be "_applied_" to the HTML element.
257+
We therefore need a pair of "helper" functions (_one for each argument_).
215258

216-
### `mount`
217259

218-
### ``
219260

220261

221262

222263

223264

265+
Section in Elm: http://package.elm-lang.org/packages/elm-lang/html/2.0.0/Html
266+
<br />
267+
Demo: https://ellie-app.com/LTtNVQjfWVa1
268+
![ellie-elm-section](https://user-images.githubusercontent.com/194400/42708957-bbcc1020-86d6-11e8-97bf-f2f3a1c6fdea.png)
269+
270+
271+
272+
273+
### `mount`
274+
275+
The `mount` function is the "glue" or "wiring" function that
276+
connects the `model`, `update` and `view`; we _can_ `generalise` it.
277+
278+
279+
280+
224281

225282

226283

0 commit comments

Comments
 (0)