← Saboteur

todomvc: try the bugs

These are the builds Saboteur tests: the correct app, and the same app with exactly one planted bug each. Open one, use it like a customer, and see whether you would have noticed. Saboteur's Kane CLI runs used local builds of the same code.

cleanThe correct appOpen this build

No planted bug. Everything works as described.

M01"items left" counts completed todos tooOpen this build

The counter overstates the work left: completed todos are still counted as left

The patch
diff --git a/src/todo/components/footer.jsx b/src/todo/components/footer.jsx
index 70b7ac5..0d1cd74 100644
--- a/src/todo/components/footer.jsx
+++ b/src/todo/components/footer.jsx
@@ -14,7 +14,7 @@ export function Footer({ todos, dispatch }) {
 
     return (
         <footer className="footer" data-testid="footer" hidden={todos.length === 0}>
-            <span className="todo-count">{`${activeTodos.length} ${activeTodos.length === 1 ? "item" : "items"} left!`}</span>
+            <span className="todo-count">{`${todos.length} ${todos.length === 1 ? "item" : "items"} left!`}</span>
             <ul className="filters" data-testid="footer-navigation">
                 <li>
                     <a className={classnames({ selected: route === "/" })} href="#/">All</a>
M02Counter says "1 items left!"Open this build

With exactly one active todo the counter reads "1 items left!" instead of "1 item left!"

The patch
diff --git a/src/todo/components/footer.jsx b/src/todo/components/footer.jsx
index 70b7ac5..47088ec 100644
--- a/src/todo/components/footer.jsx
+++ b/src/todo/components/footer.jsx
@@ -14,7 +14,7 @@ export function Footer({ todos, dispatch }) {
 
     return (
         <footer className="footer" data-testid="footer" hidden={todos.length === 0}>
-            <span className="todo-count">{`${activeTodos.length} ${activeTodos.length === 1 ? "item" : "items"} left!`}</span>
+            <span className="todo-count">{`${activeTodos.length} ${activeTodos.length === 0 ? "item" : "items"} left!`}</span>
             <ul className="filters" data-testid="footer-navigation">
                 <li>
                     <a className={classnames({ selected: route === "/" })} href="#/">All</a>
M03Active filter also shows completed todosOpen this build

The Active view lists completed todos, so users cannot see only what is left

The patch
diff --git a/src/todo/components/main.jsx b/src/todo/components/main.jsx
index 4cf1a8a..80cd59a 100644
--- a/src/todo/components/main.jsx
+++ b/src/todo/components/main.jsx
@@ -12,7 +12,7 @@ export function Main({ todos, dispatch }) {
         () =>
             todos.filter((todo) => {
                 if (route === "/active")
-                    return !todo.completed;
+                    return todo;
 
                 if (route === "/completed")
                     return todo.completed;
M04Completed filter shows the active todosOpen this build

The Completed view lists the wrong todos: active ones instead of completed ones

The patch
diff --git a/src/todo/components/main.jsx b/src/todo/components/main.jsx
index 4cf1a8a..203cfce 100644
--- a/src/todo/components/main.jsx
+++ b/src/todo/components/main.jsx
@@ -15,7 +15,7 @@ export function Main({ todos, dispatch }) {
                     return !todo.completed;
 
                 if (route === "/completed")
-                    return todo.completed;
+                    return !todo.completed;
 
                 return todo;
             }),
M05"Clear completed" deletes the active todosOpen this build

Clicking Clear completed throws away every unfinished todo and keeps the finished ones

The patch
diff --git a/src/todo/reducer.js b/src/todo/reducer.js
index b43c358..1adc83b 100644
--- a/src/todo/reducer.js
+++ b/src/todo/reducer.js
@@ -57,7 +57,7 @@ export const todoReducer = (state, action) => {
         case TOGGLE_ALL:
             return state.map((todo) => (todo.completed !== action.payload.completed ? { ...todo, completed: action.payload.completed } : todo));
         case REMOVE_COMPLETED_ITEMS:
-            return state.filter((todo) => !todo.completed);
+            return state.filter((todo) => todo.completed);
     }
 
     throw Error(`Unknown action: ${action.type}`);
M06A todo of only spaces can be addedOpen this build

Pressing Enter in the new-todo box with only spaces adds an empty todo

The patch
diff --git a/src/todo/components/input.jsx b/src/todo/components/input.jsx
index bfaab32..b2b3147 100644
--- a/src/todo/components/input.jsx
+++ b/src/todo/components/input.jsx
@@ -13,7 +13,7 @@ export function Input({ onSubmit, placeholder, label, defaultValue, onBlur, edit
     const handleKeyDown = useCallback(
         (e) => {
             if (e.key !== "Enter") return;
-            const value = e.target.value.trim();
+            const value = e.target.value;
             // For new-todo, ignore empty submits. For edit, an empty
             // submit means "delete this todo" — let the parent decide.
             if (!editing && value.length === 0) return;
M07Clearing a todo's text no longer deletes itOpen this build

Editing a todo to empty text and pressing Enter keeps the old todo instead of deleting it

The patch
diff --git a/src/todo/components/item.jsx b/src/todo/components/item.jsx
index e558306..8b49c72 100644
--- a/src/todo/components/item.jsx
+++ b/src/todo/components/item.jsx
@@ -24,7 +24,7 @@ export const Item = memo(function Item({ todo, dispatch }) {
             // otherwise dispatch twice.
             if (!isWritable) return;
             setIsWritable(false);
-            if (newTitle.length === 0) removeItem();
+            if (newTitle.length === 0) return;
             else updateItem(newTitle);
         },
         [isWritable, removeItem, updateItem]
M08Delete button removes the first todo, not the one clickedOpen this build

Deleting any todo removes the first todo in the list instead

The patch
diff --git a/src/todo/reducer.js b/src/todo/reducer.js
index b43c358..94b31e3 100644
--- a/src/todo/reducer.js
+++ b/src/todo/reducer.js
@@ -49,7 +49,7 @@ export const todoReducer = (state, action) => {
         case UPDATE_ITEM:
             return state.map((todo) => (todo.id === action.payload.id ? { ...todo, title: action.payload.title } : todo));
         case REMOVE_ITEM:
-            return state.filter((todo) => todo.id !== action.payload.id);
+            return state.slice(1);
         case TOGGLE_ITEM:
             return state.map((todo) => (todo.id === action.payload.id ? { ...todo, completed: !todo.completed } : todo));
         case REMOVE_ALL_ITEMS:
M09"Mark all as complete" cannot un-completeOpen this build

The toggle-all arrow marks everything complete but never marks them active again

The patch
diff --git a/src/todo/components/main.jsx b/src/todo/components/main.jsx
index 4cf1a8a..2f9e6bd 100644
--- a/src/todo/components/main.jsx
+++ b/src/todo/components/main.jsx
@@ -22,7 +22,7 @@ export function Main({ todos, dispatch }) {
         [todos, route]
     );
 
-    const toggleAll = useCallback((e) => dispatch({ type: TOGGLE_ALL, payload: { completed: e.target.checked } }), [dispatch]);
+    const toggleAll = useCallback((e) => dispatch({ type: TOGGLE_ALL, payload: { completed: true } }), [dispatch]);
 
     return (
         <main className="main" data-testid="main" hidden={todos.length === 0}>
M10Edited todo text is not savedOpen this build

After double-click editing a todo and pressing Enter, the old text comes back

The patch
diff --git a/src/todo/reducer.js b/src/todo/reducer.js
index b43c358..efe5cc8 100644
--- a/src/todo/reducer.js
+++ b/src/todo/reducer.js
@@ -47,7 +47,7 @@ export const todoReducer = (state, action) => {
         case ADD_ITEM:
             return state.concat({ id: nanoid(), title: action.payload.title, completed: false });
         case UPDATE_ITEM:
-            return state.map((todo) => (todo.id === action.payload.id ? { ...todo, title: action.payload.title } : todo));
+            return state.map((todo) => (todo.id === action.payload.id ? { ...todo, title: todo.title } : todo));
         case REMOVE_ITEM:
             return state.filter((todo) => todo.id !== action.payload.id);
         case TOGGLE_ITEM: