fix: close map buy modal with escape
This commit is contained in:
parent
853a30093f
commit
567d4b6088
@ -26,6 +26,17 @@ export default function ConfirmBuyModal({
|
|||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
}, [item.id, item.quantity]);
|
}, [item.id, item.quantity]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (event) => {
|
||||||
|
if (event.key === "Escape" && !isSubmitting) {
|
||||||
|
onCancel();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
}, [isSubmitting, onCancel]);
|
||||||
|
|
||||||
const currentIndex = allItems.findIndex((listItem) => listItem.id === item.id);
|
const currentIndex = allItems.findIndex((listItem) => listItem.id === item.id);
|
||||||
const hasPrev = currentIndex > 0;
|
const hasPrev = currentIndex > 0;
|
||||||
const hasNext = currentIndex < allItems.length - 1;
|
const hasNext = currentIndex < allItems.length - 1;
|
||||||
|
|||||||
@ -3611,6 +3611,56 @@ test("viewer can buy selected zone items from the map", async ({ page }) => {
|
|||||||
await expect(page.getByRole("button", { name: "sourdough bought" })).toBeDisabled();
|
await expect(page.getByRole("button", { name: "sourdough bought" })).toBeDisabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("viewer can close map buy modal with Escape", async ({ page }) => {
|
||||||
|
await mockMapShell(page);
|
||||||
|
|
||||||
|
const mapState = publishedMapState([
|
||||||
|
{
|
||||||
|
id: 1533,
|
||||||
|
location_map_id: 901,
|
||||||
|
zone_id: 501,
|
||||||
|
zone_name: "Bakery",
|
||||||
|
type: "zone",
|
||||||
|
label: "Bakery",
|
||||||
|
x: 40,
|
||||||
|
y: 40,
|
||||||
|
width: 260,
|
||||||
|
height: 160,
|
||||||
|
rotation: 0,
|
||||||
|
locked: false,
|
||||||
|
visible: true,
|
||||||
|
sort_order: 1,
|
||||||
|
},
|
||||||
|
], true);
|
||||||
|
const boughtPayloads: Array<Record<string, unknown>> = [];
|
||||||
|
|
||||||
|
await page.route("**/households/1/locations/10/map", async (route) => {
|
||||||
|
await route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: "application/json",
|
||||||
|
body: JSON.stringify(mapState),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.route("**/households/1/locations/10/list/item", async (route) => {
|
||||||
|
if (route.request().method() === "PATCH") {
|
||||||
|
boughtPayloads.push(await route.request().postDataJSON());
|
||||||
|
}
|
||||||
|
await route.fulfill({ status: 404, contentType: "application/json", body: "{}" });
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto("/stores/100/locations/10/map");
|
||||||
|
await page.locator('[data-object-key="1533"]').locator("rect").first().click();
|
||||||
|
await page.getByRole("button", { name: "Mark french bread bought" }).click();
|
||||||
|
await expect(page.locator(".confirm-buy-modal")).toBeVisible();
|
||||||
|
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
|
||||||
|
await expect(page.locator(".confirm-buy-modal")).toHaveCount(0);
|
||||||
|
expect(boughtPayloads).toEqual([]);
|
||||||
|
await expect(page.getByRole("button", { name: "Mark french bread bought" })).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
test("viewer advances map buy modal after partial quantity buys", async ({ page }) => {
|
test("viewer advances map buy modal after partial quantity buys", async ({ page }) => {
|
||||||
await mockMapShell(page);
|
await mockMapShell(page);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user