import { test, expect } from "@playwright/test";
import { USERS, login } from "./helpers";
import { vendorWithCode, closeDb } from "./fixtures";

/**
 * Issue #57 — /catalogue/vendors (formerly /inventory/vendors) is searchable by
 * vendor id/code, and the id is shown next to the name.
 */
test.afterAll(closeDb);

test("#57 vendors are searchable by vendor id, with the id shown next to the name", async ({ page }) => {
  const vendor = await vendorWithCode();
  test.skip(!vendor, "no vendor with a vendorId code in staging data");

  await login(page, USERS.MANAGER);
  await page.goto("/catalogue/vendors");

  await page.getByPlaceholder(/Search by name, ID, GSTIN/i).fill(vendor!.vendorId!);
  // The matching vendor row shows both the name and the id badge.
  await expect(page.getByText(vendor!.name).first()).toBeVisible();
  await expect(page.getByText(vendor!.vendorId!, { exact: false }).first()).toBeVisible();
});
