// @ts-check
const { test, expect } = require('@playwright/test');
const { login } = require('./helpers/auth');

async function loginAsAdmin(page) {
  await login(page, 'admin');
  await page.locator('input[name="lg_idx"]').first().check();
  await page.click('button[type="submit"]');
  await page.waitForURL(url => !url.pathname.includes('select-local-government'), { timeout: 30000 });
}

test.describe('P2-05/06: 포장 단위 관리', () => {

  test.beforeEach(async ({ page }) => {
    await loginAsAdmin(page);
  });

  test('포장 단위 목록 접근', async ({ page }) => {
    await page.goto('/bag/packaging-units/manage');
    await expect(page).toHaveURL(/\/admin\/packaging-units/);
  });

  test('포장 단위 등록 폼 표시', async ({ page }) => {
    await page.goto('/bag/packaging-units/manage/create');
    await expect(page.locator('select[name="pu_bag_code"]')).toBeVisible();
    await expect(page.locator('input[name="pu_box_per_pack"]')).toBeVisible();
    await expect(page.locator('input[name="pu_pack_per_sheet"]')).toBeVisible();
  });

  test('기간 필터 조회', async ({ page }) => {
    await page.goto('/bag/packaging-units/manage?start_date=2026-01-01&end_date=2026-12-31');
    await expect(page).toHaveURL(/start_date/);
  });
});
