Spotlight grid that blacks out in reverse toggle order
A small theatre controls its lighting rig from a tablet. The rig is a grid with a few empty mounting slots. The operator taps spotlights on and off. At the end of a scene, a blackout turns the lights off one at a time, starting with the last one that was turned on, so the stage fades in the reverse of how it was lit. Build the control panel.
The starter code includes the rig layout and the blackout speed:
const STEP_MS = 300;
// 1 = a spotlight, 0 = an empty slot. Spots are numbered 1 to 8 in row order.
const RIG = [
[1, 1, 0, 1],
[1, 0, 1, 1],
[0, 1, 1, 0],
];
RIG as a grid (3 rows of 4). Every 1 is a spotlight button; every 0 is an empty slot that is not a button. Number the spots 1 to 8 in row order (left to right, top to bottom), so the top row holds Spots 1, 2 and 3.aria-label="Spot N" and aria-pressed="true" when it is on, "false" when it is off. All spots start off.Lit: N of 8.Blackout button starts a blackout. Disable it when no spot is on, and while a blackout is running.Blacking out, and hide it when the blackout ends.STEP_MS after it starts, the spot that was turned on most recently turns off. Then another one turns off every STEP_MS, always the most recent of those still on, until none is on.Click Spot 3, Spot 5, Spot 1 Lit: 3 of 8, order 3, 5, 1
Click Spot 5 Spot 5 off, order 3, 1
Click Spot 8, Spot 5 order 3, 1, 8, 5
Click Blackout "Blacking out", all 4 still on
+300ms Spot 5 off (Lit: 3 of 8)
+300ms Spot 8 off
+300ms Spot 1 off
+300ms Spot 3 off, "Blacking out" disappears
STEP_MS later.The tests click your spots and buttons and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. The test frame is hidden, so real timers don’t run there: each test replaces setTimeout, setInterval and their clear functions with a fake clock and moves it forward by hand. They check that:
aria-label="Spot N" and an aria-pressed attribute, in DOM order.Lit: N of 8 and Blacking out appear as described.Blackout button is found by its text. Disabled means the disabled attribute (or aria-disabled="true").Capitalization and extra spacing don’t matter.