690504:1641 Update specs [skip ci]
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
# **Workflow DSL Specification v1.0**
|
||||
|
||||
เอกสารนี้ระบุโครงสร้างภาษา (Domain-Specific Language) สำหรับกำหนด Business Logic ของการเดินเอกสารในระบบ LCBP3-DMS
|
||||
|
||||
## **1\. โครงสร้างหลัก (Root Structure)**
|
||||
|
||||
ไฟล์ Definition ต้องอยู่ในรูปแบบ YAML หรือ JSON โดยมีโครงสร้างดังนี้:
|
||||
|
||||
```json
|
||||
workflow: "RFA_FLOW" # รหัส Workflow (Unique)
|
||||
version: 1 # เวอร์ชันของ Logic
|
||||
description: "RFA Approval Process" # คำอธิบาย
|
||||
|
||||
# รายการสถานะทั้งหมดที่เป็นไปได้
|
||||
states:
|
||||
- name: "DRAFT" # ชื่อสถานะ (Case-sensitive)
|
||||
initial: true # เป็นสถานะเริ่มต้น (ต้องมี 1 สถานะ)
|
||||
on: # รายการ Action ที่ทำได้จากสถานะนี้
|
||||
SUBMIT: # ชื่อ Action (ปุ่มที่ User กด)
|
||||
to: "IN_REVIEW" # สถานะปลายทาง
|
||||
require: # (Optional) เงื่อนไขสิทธิ์
|
||||
role: "EDITOR"
|
||||
events: # (Optional) เหตุการณ์ที่จะเกิดขึ้นเมื่อเปลี่ยนสถานะ
|
||||
- type: "notify"
|
||||
target: "reviewer"
|
||||
|
||||
- name: "IN_REVIEW"
|
||||
on:
|
||||
APPROVE:
|
||||
to: "APPROVED"
|
||||
condition: "context.amount < 1000000" # (Optional) JS Expression
|
||||
REJECT:
|
||||
to: "DRAFT"
|
||||
events:
|
||||
- type: "notify"
|
||||
target: "creator"
|
||||
|
||||
- name: "APPROVED"
|
||||
terminal: true # เป็นสถานะจบ (ไม่สามารถไปต่อได้)
|
||||
```
|
||||
|
||||
## **2. รายละเอียด Field (Field Definitions)**
|
||||
|
||||
### **2.1 State Object**
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| :------- | :------ | :------- | :--------------------------------------------- |
|
||||
| name | string | Yes | ชื่อสถานะ (Unique Key) |
|
||||
| initial | boolean | No | ระบุว่าเป็นจุดเริ่มต้น (ต้องมี 1 state ในระบบ) |
|
||||
| terminal | boolean | No | ระบุว่าเป็นจุดสิ้นสุด |
|
||||
| on | object | No | Map ของ Action -> Transition Rule |
|
||||
|
||||
### **2.2 Transition Rule Object**
|
||||
|
||||
| Field | Type | Required | Description |
|
||||
| :-------- | :----- | :------- | :-------------------------------------- |
|
||||
| to | string | Yes | ชื่อสถานะปลายทาง |
|
||||
| require | object | No | เงื่อนไข Role/User |
|
||||
| condition | string | No | JavaScript Expression (return boolean) |
|
||||
| events | array | No | Side-effects ที่จะทำงานหลังเปลี่ยนสถานะ |
|
||||
|
||||
### **2.3 Requirements Object**
|
||||
|
||||
| Field | Type | Description |
|
||||
| :---- | :----- | :------------------------------------------ |
|
||||
| role | string | User ต้องมี Role นี้ (เช่น PROJECT_MANAGER) |
|
||||
| user | string | User ต้องมี ID นี้ (Hard-code) |
|
||||
|
||||
### **2.4 Event Object**
|
||||
|
||||
| Field | Type | Description |
|
||||
| :------- | :----- | :----------------------------------------- |
|
||||
| type | string | notify, webhook, update_status |
|
||||
| target | string | ผู้รับ (เช่น creator, assignee, หรือ Role) |
|
||||
| template | string | รหัส Template ข้อความ |
|
||||
|
||||
## **3\. ตัวอย่างการใช้งานจริง (Real-world Examples)**
|
||||
|
||||
### **ตัวอย่าง: RFA Approval Flow**
|
||||
|
||||
```json
|
||||
{
|
||||
"workflow": "RFA_STD",
|
||||
"version": 1,
|
||||
"states": [
|
||||
{
|
||||
"name": "DRAFT",
|
||||
"initial": true,
|
||||
"on": {
|
||||
"SUBMIT": {
|
||||
"to": "CONSULTANT_REVIEW",
|
||||
"require": { "role": "CONTRACTOR" }
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CONSULTANT_REVIEW",
|
||||
"on": {
|
||||
"APPROVE_1": {
|
||||
"to": "OWNER_REVIEW",
|
||||
"condition": "context.priority === 'HIGH'"
|
||||
},
|
||||
"APPROVE_2": {
|
||||
"to": "APPROVED",
|
||||
"condition": "context.priority === 'NORMAL'"
|
||||
},
|
||||
"REJECT": {
|
||||
"to": "DRAFT"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "OWNER_REVIEW",
|
||||
"on": {
|
||||
"APPROVE": { "to": "APPROVED" },
|
||||
"REJECT": { "to": "CONSULTANT_REVIEW" }
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "APPROVED",
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,113 @@
|
||||
## การใช้งาน Playwright ใน LCBP3-DMS
|
||||
|
||||
จากการตรวจสอบ spec มี test strategy ที่รองรับ Playwright:
|
||||
|
||||
### 1. **Test Strategy** (จาก [05-04-testing-strategy.md](cci:7://file:///e:/np-dms/lcbp3/specs/05-Engineering-Guidelines/05-04-testing-strategy.md:0:0-0:0))
|
||||
|
||||
**Stack**:
|
||||
- **Backend**: Jest (Unit + Integration + E2E)
|
||||
- **Frontend**: Vitest (Unit) + **Playwright** (E2E)
|
||||
|
||||
### 2. **Setup Playwright**
|
||||
|
||||
```bash
|
||||
# ติดตั้ง Playwright browsers
|
||||
npx playwright install chromium
|
||||
|
||||
# หรือติดตั้งทั้งหมด
|
||||
npx playwright install
|
||||
```
|
||||
|
||||
### 3. **MCP Server สำหรับ Windsurf**
|
||||
|
||||
เพิ่มใน [.windsurfrc](cci:7://file:///e:/np-dms/lcbp3/.windsurfrc:0:0-0:0):
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"playwright": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@playwright/mcp@latest"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Restart Windsurf** แล้วจะเห็น Playwright MCP panel
|
||||
|
||||
### 4. **การใช้งานผ่าน Windsurf Cascade**
|
||||
|
||||
เมื่อ MCP พร้อมแล้ว สามารถใช้คำสั่ง:
|
||||
|
||||
- **Open browser**: `Navigate to http://localhost:3000`
|
||||
- **Take screenshot**: `Take a screenshot of the current page`
|
||||
- **Click element**: `Click the "Submit" button`
|
||||
- **Fill form**: `Type "test@example.com" into the email field`
|
||||
- **Verify**: `Check if "Success" message is visible`
|
||||
|
||||
### 5. **E2E Test Script Example**
|
||||
|
||||
สร้างไฟล์ `e2e/workflow-adr021.spec.ts`:
|
||||
|
||||
```typescript
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test('ADR-021 workflow transition with attachment', async ({ page }) => {
|
||||
// 1. Login
|
||||
await page.goto('http://localhost:3000/login');
|
||||
await page.fill('[name="email"]', 'test@example.com');
|
||||
await page.fill('[name="password"]', 'password');
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// 2. Navigate to RFA detail
|
||||
await page.goto('http://localhost:3000/rfas/test-uuid');
|
||||
|
||||
// 3. Verify IntegratedBanner
|
||||
await expect(page.locator('[data-testid="integrated-banner"]')).toBeVisible();
|
||||
await expect(page.locator('[data-testid="priority-badge"]')).toHaveText('HIGH');
|
||||
|
||||
// 4. Upload attachment
|
||||
await page.setInputFiles('[data-testid="file-dropzone"]', 'test.pdf');
|
||||
|
||||
// 5. Submit approval
|
||||
await page.click('[data-testid="approve-button"]');
|
||||
|
||||
// 6. Verify success
|
||||
await expect(page.locator('[data-testid="success-toast"]')).toBeVisible();
|
||||
});
|
||||
```
|
||||
|
||||
### 6. **Run E2E Tests**
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
|
||||
# Run all E2E tests
|
||||
npx playwright test
|
||||
|
||||
# Run specific test
|
||||
npx playwright test e2e/workflow-adr021.spec.ts
|
||||
|
||||
# Run with UI mode (debug)
|
||||
npx playwright test --ui
|
||||
|
||||
# Run headed (see browser)
|
||||
npx playwright test --headed
|
||||
```
|
||||
|
||||
### 7. **Generate Test Report**
|
||||
|
||||
```bash
|
||||
npx playwright show-report
|
||||
```
|
||||
|
||||
### 8. **ถ้าใช้ MCP ผ่าน Windsurf**
|
||||
|
||||
Cascade จะมี tool ให้ใช้:
|
||||
- `browser_navigate` - เปิด URL
|
||||
- `browser_click` - คลิก element
|
||||
- `browser_type` - พิมพ์ข้อความ
|
||||
- `browser_take_screenshot` - ถ่าย screenshot
|
||||
- `browser_evaluate` - รัน JavaScript
|
||||
|
||||
ต้องการให้ช่วย setup หรือสร้าง E2E test สำหรับ feature ใด feature หนึ่งไหมครับ?
|
||||
Reference in New Issue
Block a user