Cinema seat grid with drag-to-select rectangular seat blocks
Build the seat picker of a cinema booking page. Groups usually want seats next to each other, so instead of clicking seats one by one, the user presses on a seat and drags: every free seat in the rectangle between the seat they pressed and the seat under the pointer is selected.
The starter code includes the hall layout:
const ROWS = ['A', 'B', 'C', 'D', 'E'];
const SEATS_PER_ROW = 8;
const BOOKED = ['B3', 'C5', 'C6', 'E1'];
Seat IDs are the row letter followed by the seat number, starting at 1: A1 is the first seat of the first row, E8 the last seat of the last row.
A1 … A8, then B1 …). Each seat shows its number and has aria-label="<ID>, <status>", where status is available, selected or booked (for example aria-label="B3, booked").Seats outside the rectangle keep the state they had before the press.
No seats selected1 seat selected: A13 seats selected: A1, A2, C8Clear selection deselects every seat.Press B2, drag over C3 to D4, release
Rectangle B2..D4 = B2 B3 B4 / C2 C3 C4 / D2 D3 D4
B3 is booked, so: "8 seats selected: B2, B4, C2, C3, C4, D2, D3, D4"
Press D7, drag up to B6
Rectangle B6..D7 = B6 B7 / C6 C7 / D6 D7
C6 is booked, so: "5 seats selected: B6, B7, C7, D6, D7"
Selected: A1 A2 A3 A4 A5 and D8
Press A2 (selected, so remove mode), drag to B4, release
A2 A3 A4 are removed, B2 B4 were not selected and stay that way
"3 seats selected: A1, A5, D8"
B2. Press A1, drag to C3, then back to A2. The rectangle is now A1..A2, so the selection is A1, A2, B2: B2 was selected before the press, so it stays.click after a press and release on the same seat. The press already toggled it, so don’t toggle again on click.mouseup on another element, so listen for it on window or document, not only on the seats.The tests press, move and release the mouse on the seats and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They:
aria-label (<ID>, <status>), in DOM order.pointerdown and mousedown to press, pointerover/pointerenter and mouseover/mouseenter (with the matching out/leave events on the seat the pointer left) to move, and pointerup and mouseup to release. Handle either the mouse events or the pointer events, not both.Clear selection button.Capitalization and extra spacing don’t matter.