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

test.describe('번호알기 (봉투번호확인)', () => {
  test.beforeEach(async ({ page }) => {
    await login(page, 'local');
  });

  test('페이지 로드 및 기본 UI', async ({ page }) => {
    await page.goto('/bag/number-lookup');
    await expect(page).toHaveURL(/\/bag\/number-lookup/);
    await expect(page.locator('#numLookupTitle')).toHaveText(/봉투번호확인/);
    await expect(page.locator('#codeInput')).toBeVisible();
    await expect(page.locator('#barcodeOut')).toHaveText(/-  -  -  -/);
    await expect(page.locator('#printOut')).toHaveText(/-  -  -/);
    await expect(page.locator('#recognitionOut')).toHaveText(/-  -/);
  });

  test('LOT-팩-낱장 코드 조회', async ({ page }) => {
    await page.goto('/bag/number-lookup');
    await page.fill('#codeInput', 'OQXCKH-000008-P299-S00125');
    await page.click('button.num-lookup-btn-primary');

    await expect(page).toHaveURL(/code=OQXCKH-000008-P299-S00125/);
    await expect(page.locator('#barcodeOut')).toContainText('OQXCKH');
    await expect(page.locator('#barcodeOut')).toContainText('P299');
    await expect(page.locator('#printOut')).toContainText('8');
    await expect(page.locator('#recognitionOut')).toContainText('P299');
  });

  test('도움말에서 번호알기 링크', async ({ page }) => {
    await page.goto('/bag/help');
    await page.click('a[href*="bag/number-lookup"]');
    await expect(page).toHaveURL(/\/bag\/number-lookup/);
  });
});
