import { test, expect } from '@playwright/test'

test.describe('OMS-CLM-001 클레임 업무 흐름', () => {
  test('선택 계약과 WorkflowBar가 실제 승인 Command까지 연결된다', async ({ page }) => {
    await page.goto('/oms/claims')
    await expect(page.locator('[data-screen-id="OMS-CLM-001"]')).toBeVisible()
    await page.keyboard.press('F3')
    await expect(page.getByText('CLM-260811-01', { exact: true })).toBeVisible()

    await page.getByText('CLM-260811-01', { exact: true }).click()
    const workflow=page.getByLabel('업무 상태')
    await expect(workflow).toBeVisible()
    await expect(workflow.getByRole('button', { name: '승인', exact: true })).toBeVisible()
    await workflow.getByRole('button', { name: '승인', exact: true }).click()

    const receipt=page.locator('[data-kbx-surface="claim-action-receipt"]')
    await expect(receipt).toBeVisible()
    await expect(receipt).toBeFocused()
    await expect(receipt).toContainText('요청 1건 · 성공 1건 · 실패 0건')
  })

  test('승인 상태는 처리 시작으로 이어지고 보류는 명시적 상태로 표시된다', async ({ page }) => {
    await page.goto('/oms/claims')
    await page.getByLabel('상태').selectOption('APPROVED')
    await page.keyboard.press('F3')
    await page.getByText('CLM-260811-02', { exact: true }).click()

    const workflow=page.getByLabel('업무 상태')
    await expect(workflow).toContainText('승인')
    await workflow.getByRole('button', { name: '처리 시작', exact: true }).click()
    await expect(page.locator('[data-kbx-surface="claim-action-receipt"]')).toContainText('처리 시작 결과')

    await page.getByLabel('상태').selectOption('HOLD')
    await page.keyboard.press('F3')
    await page.getByText('CLM-260811-04', { exact: true }).click()
    await expect(page.getByLabel('업무 상태')).toContainText('보류')
    await expect(page.getByLabel('업무 상태')).toContainText('현재 상태에서 실행 가능한 다음 작업이 없습니다.')
  })
})
