import { Page } from "@playwright/test";
import getCompletedShoppingItem from "./getCompletedShoppingItem";

export default async function markShoppingItemCompleted(
  page: Page,
  ingredientName: string,
): Promise<void> {
  const shoppingItem = page.getByRole("listitem", { name: ingredientName });

  await shoppingItem.waitFor({ state: "visible" });

  await shoppingItem.getByRole("button", { name: ingredientName }).click();

  await getCompletedShoppingItem(page, ingredientName);
}
