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

export default async function getShoppingItemCompletedQuantity(
  page: Page,
  ingredientName: string,
): Promise<string | undefined> {
  const listItem = await getCompletedShoppingItem(page, ingredientName);

  const specifyButton = listItem.getByRole("button", {
    name: "Указать кол-во",
  });

  if (await specifyButton.isVisible()) {
    return undefined;
  }

  const result = await listItem.getByTestId("completed-quantity").textContent();

  return result?.trim();
}
