Stock counter with step buttons, history, undo, and redo
Warehouse staff fix shelf counts on a tablet with big step buttons. Fingers slip, so every change goes into a short history, and they can undo and redo changes. Build the widget.
The starter code includes the step buttons and the history size:
const STEPS = [-10, -1, 1, 10];
const HISTORY_LIMIT = 5;
Stock: N. It starts at 0.STEPS, labelled with its signed value: -10, -1, +1, +10. Clicking one adds the step to the stock.
-10 at 4 makes it 0.-1 at 0), nothing happens: no history entry, and the redo list is kept.<li> per entry, newest first. Each entry reads <step>: <before> → <after>, with the step signed, for example +10: 0 → 10 or -10: 4 → 0 (-> works too).
<li> and show No changes yet.HISTORY_LIMIT entries. When a new entry would make 6, drop the oldest one. A dropped entry can no longer be undone.Undo button sets the stock back to the newest entry’s before value and removes that entry from the history. Disable it when the history is empty.Redo button re-applies the most recently undone entry: the stock becomes its after value and the entry is back at the top of the history. Disable it when nothing has been undone.Click +10 Stock: 10 history: +10: 0 → 10
Click -1 Stock: 9 history: -1: 10 → 9, +10: 0 → 10
Click -10 Stock: 0 history: -10: 9 → 0, -1: 10 → 9, +10: 0 → 10
Click -1 Stock: 0 (nothing changes)
Click Undo Stock: 9 history: -1: 10 → 9, +10: 0 → 10
Click Undo Stock: 10 history: +10: 0 → 10
Click Redo Stock: 9 history: -1: 10 → 9, +10: 0 → 10
Click +1 Stock: 10 Redo is disabled (the undone -10 is gone)
-10: 4 → 0, so undo restores exactly 4.The tests click your buttons and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
Stock: N and, for an empty history, No changes yet are shown.-10, -1, +1, +10, Undo, Redo. Disabled means the disabled attribute (or aria-disabled="true").<li> elements in your component, read in DOM order.Capitalization and extra spacing don’t matter. A minus sign (−) or en dash works in place of -.