Skip to content

Commit 53c0adf

Browse files
author
cjyuan
committed
Update files based on Daniel feedback
1 parent d6f24dc commit 53c0adf

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed

Sprint-3/todo-list/README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,49 @@ Each ToDo task has two properties:
1212

1313
## Installation
1414

15-
To view the website, open `index.html` with Live Server in VS Code.
15+
Run the following command in this directory to install all required dependencies:
16+
```
17+
npm install
18+
```
19+
> This will install
20+
- `jest` - for running unix test
21+
- `http-server` - for serving `index.html` over HTTP
22+
23+
**Note:** If you are using a Windows CLI, replace `package.json` by `package.json-windows`.
24+
25+
## Running the App
26+
27+
Since the app uses **ES modules**, the HTML file **must be loaded via HTTP/HTTPS** rather than
28+
directly from the file system.
29+
30+
Make sure you run the server in this directory where `index.html` is located.
31+
32+
Two possible ways to serve `index.html` over HTTP:
33+
34+
#### Option 1: `http-server`
35+
36+
1. Run
37+
```
38+
npm run serve
39+
```
40+
> Here, `serve` is a shortcut defined in `package.json` for running `http-server`.
41+
42+
43+
2. Open one of the URLs shown in the terminal (e.g., `http://127.0.0.1:8080`).
44+
45+
46+
#### Option 2: Open `index.html` with Live Server in VSCode.
1647

17-
**Note**: The app is loaded **as ES modules** in the HTML file, and as such, the HTML file must be accessed via the HTTP or HTTPS protocol.
1848

1949
## Understanding how the code is organized as ES modules
2050

2151
- [What is ES Modules?](00-what_is_ES_modules.md)
2252
- [How to use ES modules with Node.js and Jest?](01-using_esm_with_nodejs_and_jest.md)
2353
- [A guide to modularize a web app](02-guide_to_modularize_code.md)
2454

25-
## Instructions
55+
---
56+
57+
## Exercise Instructions
2658

2759
In this exercise, your objective is to extend the ToDo app by implementing new features.
2860
Start with the main feature and then try the stretch goals if you have extra time.

Sprint-3/todo-list/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"description": "You must update this package",
66
"type": "module",
77
"scripts": {
8+
"serve": "http-server",
89
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
910
},
1011
"repository": {
@@ -16,6 +17,7 @@
1617
},
1718
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
1819
"devDependencies": {
20+
"http-server": "^14.1.1",
1921
"jest": "^30.0.4"
2022
}
2123
}

Sprint-3/todo-list/package.json-windows

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"description": "You must update this package",
66
"type": "module",
77
"scripts": {
8+
"serve": "http-server",
89
"test": "set NODE_OPTIONS=--experimental-vm-modules && jest"
910
},
1011
"repository": {
@@ -16,6 +17,7 @@
1617
},
1718
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
1819
"devDependencies": {
20+
"http-server": "^14.1.1",
1921
"jest": "^30.0.4"
2022
}
2123
}

Sprint-3/todo-list/script.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as Todos from "./todos.mjs";
33

44
// To store the todo tasks
5-
let todos = [];
5+
const todos = [];
66

77
// Set up tasks to be performed once on page load
88
window.addEventListener("load", () => {
@@ -58,8 +58,9 @@ function createListItem(todo, index) {
5858
const li = todoListItemTemplate.cloneNode(true); // true => Do a deep copy of the node
5959

6060
li.querySelector(".description").textContent = todo.task;
61-
if (todo.completed)
61+
if (todo.completed) {
6262
li.classList.add("completed");
63+
}
6364

6465
li.querySelector('.complete-btn').addEventListener("click", () => {
6566
Todos.toggleCompletedOnTask(todos, index);

Sprint-3/todo-list/todos.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export function addTask(todos, task, completed = false) {
1616

1717
// Delete todos[taskIndex] if it exists
1818
export function deleteTask(todos, taskIndex) {
19-
if (todos[taskIndex])
19+
if (todos[taskIndex]) {
2020
todos.splice(taskIndex, 1);
21+
}
2122
}
2223

2324
// Toggle the "completed" property of todos[taskIndex] if the task exists.
2425
export function toggleCompletedOnTask(todos, taskIndex) {
25-
if (todos[taskIndex])
26+
if (todos[taskIndex]) {
2627
todos[taskIndex].completed = !todos[taskIndex].completed;
28+
}
2729
}

Sprint-3/todo-list/todos.test.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ describe("toggleCompletedOnTask()", () => {
9797

9898
test("Expect the 'completed' property to toggle on an existing task", () => {
9999
const todos = createMockTodos();
100-
const taskIdx = 1;
101-
const completedStateBeforeToggle = todos[taskIdx].completed;
102-
Todos.toggleCompletedOnTask(todos, taskIdx);
103-
expect(todos[taskIdx].completed).toEqual(!completedStateBeforeToggle);
100+
const taskIndex = 1;
101+
const completedStateBeforeToggle = todos[taskIndex].completed;
102+
Todos.toggleCompletedOnTask(todos, taskIndex);
103+
expect(todos[taskIndex].completed).toEqual(!completedStateBeforeToggle);
104104

105105
// Toggle again
106-
Todos.toggleCompletedOnTask(todos, taskIdx);
107-
expect(todos[taskIdx].completed).toEqual(completedStateBeforeToggle);
106+
Todos.toggleCompletedOnTask(todos, taskIndex);
107+
expect(todos[taskIndex].completed).toEqual(completedStateBeforeToggle);
108108
});
109109

110110
test("Expect toggling on a task does not affect other tasks", () => {

0 commit comments

Comments
 (0)