- 개발/테스트 스크립트를 dev_scripts/ 폴더로 이동 - 스크린샷을 screenshots/ 폴더로 이동 - 백업 파일 보존 (.backup) - 처방 관련 추가 스크립트 포함 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
200 lines
6.0 KiB
Python
200 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
신규 약재 추가 드롭다운 버그 테스트
|
|
십전대보탕 조제 시 새로운 약재 추가가 안되는 문제 확인
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
from datetime import datetime
|
|
|
|
BASE_URL = "http://localhost:5001"
|
|
|
|
def test_herb_dropdown_api():
|
|
"""약재 목록 API 테스트"""
|
|
print("\n" + "="*80)
|
|
print("1. 약재 목록 API 테스트")
|
|
print("="*80)
|
|
|
|
# 1. 전체 약재 목록 조회
|
|
response = requests.get(f"{BASE_URL}/api/herbs")
|
|
print(f"상태 코드: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
herbs = response.json()
|
|
print(f"총 약재 수: {len(herbs)}")
|
|
|
|
# 처음 5개만 출력
|
|
print("\n처음 5개 약재:")
|
|
for herb in herbs[:5]:
|
|
print(f" - ID: {herb.get('herb_item_id')}, 이름: {herb.get('herb_name')}, 코드: {herb.get('insurance_code')}")
|
|
else:
|
|
print(f"오류: {response.text}")
|
|
|
|
return response.status_code == 200
|
|
|
|
def test_formula_ingredients():
|
|
"""십전대보탕 처방 구성 테스트"""
|
|
print("\n" + "="*80)
|
|
print("2. 십전대보탕 처방 구성 조회")
|
|
print("="*80)
|
|
|
|
# 십전대보탕 ID 찾기
|
|
response = requests.get(f"{BASE_URL}/api/formulas")
|
|
formulas = response.json()
|
|
|
|
sipjeon_id = None
|
|
for formula in formulas:
|
|
if '십전대보탕' in formula.get('formula_name', ''):
|
|
sipjeon_id = formula['formula_id']
|
|
print(f"십전대보탕 ID: {sipjeon_id}")
|
|
break
|
|
|
|
if not sipjeon_id:
|
|
print("십전대보탕을 찾을 수 없습니다")
|
|
return False
|
|
|
|
# 처방 구성 조회
|
|
response = requests.get(f"{BASE_URL}/api/formulas/{sipjeon_id}/ingredients")
|
|
if response.status_code == 200:
|
|
ingredients = response.json()
|
|
print(f"\n십전대보탕 구성 약재 ({len(ingredients)}개):")
|
|
|
|
ingredient_codes = []
|
|
for ing in ingredients:
|
|
print(f" - {ing.get('herb_name')} ({ing.get('ingredient_code')}): {ing.get('grams_per_cheop')}g")
|
|
ingredient_codes.append(ing.get('ingredient_code'))
|
|
|
|
return ingredient_codes
|
|
else:
|
|
print(f"오류: {response.text}")
|
|
return []
|
|
|
|
def test_available_herbs_for_compound():
|
|
"""조제 시 사용 가능한 약재 목록 테스트"""
|
|
print("\n" + "="*80)
|
|
print("3. 조제용 약재 목록 API 테스트")
|
|
print("="*80)
|
|
|
|
# 재고가 있는 약재만 조회하는 API가 있는지 확인
|
|
endpoints = [
|
|
"/api/herbs",
|
|
"/api/herbs/available",
|
|
"/api/herbs-with-inventory"
|
|
]
|
|
|
|
for endpoint in endpoints:
|
|
print(f"\n테스트: {endpoint}")
|
|
try:
|
|
response = requests.get(f"{BASE_URL}{endpoint}")
|
|
if response.status_code == 200:
|
|
herbs = response.json()
|
|
print(f" ✓ 성공 - {len(herbs)}개 약재")
|
|
|
|
# 재고 정보 확인
|
|
if herbs and len(herbs) > 0:
|
|
sample = herbs[0]
|
|
print(f" 샘플 데이터: {sample}")
|
|
if 'quantity_onhand' in sample or 'total_quantity' in sample:
|
|
print(" → 재고 정보 포함됨")
|
|
else:
|
|
print(f" ✗ 실패 - 상태코드: {response.status_code}")
|
|
except Exception as e:
|
|
print(f" ✗ 오류: {e}")
|
|
|
|
def check_frontend_code():
|
|
"""프론트엔드 코드에서 약재 추가 부분 확인"""
|
|
print("\n" + "="*80)
|
|
print("4. 프론트엔드 코드 분석")
|
|
print("="*80)
|
|
|
|
print("""
|
|
app.js의 약재 추가 관련 주요 함수:
|
|
1. loadHerbOptions() - 약재 드롭다운 로드
|
|
2. addIngredientRow() - 약재 행 추가
|
|
3. loadOriginOptions() - 원산지 옵션 로드
|
|
|
|
문제 가능성:
|
|
- loadHerbOptions() 함수가 제대로 호출되지 않음
|
|
- API 엔드포인트가 잘못됨
|
|
- 드롭다운 element 선택자 오류
|
|
- 이벤트 바인딩 문제
|
|
""")
|
|
|
|
def test_with_playwright():
|
|
"""Playwright로 실제 UI 테스트"""
|
|
print("\n" + "="*80)
|
|
print("5. Playwright UI 테스트 스크립트 생성")
|
|
print("="*80)
|
|
|
|
test_code = '''from playwright.sync_api import sync_playwright
|
|
import time
|
|
|
|
def test_herb_dropdown():
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=False)
|
|
page = browser.new_page()
|
|
|
|
# 1. 조제 페이지로 이동
|
|
page.goto("http://localhost:5001")
|
|
page.click('a[href="#compound"]')
|
|
time.sleep(1)
|
|
|
|
# 2. 십전대보탕 선택
|
|
page.select_option('#compoundFormula', label='십전대보탕')
|
|
time.sleep(1)
|
|
|
|
# 3. 새 약재 추가 버튼 클릭
|
|
page.click('#addIngredientBtn')
|
|
time.sleep(1)
|
|
|
|
# 4. 드롭다운 확인
|
|
dropdown = page.locator('.herb-select').last
|
|
options = dropdown.locator('option').all_text_contents()
|
|
|
|
print(f"드롭다운 옵션 수: {len(options)}")
|
|
print(f"처음 5개: {options[:5]}")
|
|
|
|
browser.close()
|
|
|
|
if __name__ == "__main__":
|
|
test_herb_dropdown()
|
|
'''
|
|
|
|
print("Playwright 테스트 코드를 test_ui_dropdown.py 파일로 저장합니다.")
|
|
|
|
with open('/root/kdrug/test_ui_dropdown.py', 'w') as f:
|
|
f.write(test_code)
|
|
|
|
return True
|
|
|
|
def main():
|
|
"""메인 테스트 실행"""
|
|
print("\n" + "="*80)
|
|
print("신규 약재 추가 드롭다운 버그 테스트")
|
|
print("="*80)
|
|
|
|
# 1. API 테스트
|
|
if not test_herb_dropdown_api():
|
|
print("\n❌ 약재 목록 API에 문제가 있습니다")
|
|
return
|
|
|
|
# 2. 처방 구성 테스트
|
|
ingredient_codes = test_formula_ingredients()
|
|
|
|
# 3. 조제용 약재 테스트
|
|
test_available_herbs_for_compound()
|
|
|
|
# 4. 프론트엔드 코드 분석
|
|
check_frontend_code()
|
|
|
|
# 5. Playwright 테스트 생성
|
|
test_with_playwright()
|
|
|
|
print("\n" + "="*80)
|
|
print("테스트 완료 - app.js 파일을 확인하여 문제를 찾아보겠습니다")
|
|
print("="*80)
|
|
|
|
if __name__ == "__main__":
|
|
main() |