feat: Add test scripts for dose parsing and UI tracking functionality
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
111
scripts/test_dose_tracking_ui.py
Normal file
111
scripts/test_dose_tracking_ui.py
Normal file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script for dose tracking UI in edit window.
|
||||
Tests the specific issue where adding new doses replaces existing ones.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tkinter as tk
|
||||
from datetime import datetime
|
||||
|
||||
# Add the src directory to Python path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
|
||||
|
||||
from init import logger
|
||||
from medicine_manager import MedicineManager
|
||||
from pathology_manager import PathologyManager
|
||||
from theme_manager import ThemeManager
|
||||
from ui_manager import UIManager
|
||||
|
||||
|
||||
def test_dose_tracking():
|
||||
"""Test the dose tracking functionality."""
|
||||
|
||||
# Create test window
|
||||
root = tk.Tk()
|
||||
root.title("Dose Tracking Test")
|
||||
root.geometry("800x600")
|
||||
|
||||
# Initialize managers
|
||||
medicine_manager = MedicineManager(logger=logger)
|
||||
pathology_manager = PathologyManager(logger=logger)
|
||||
theme_manager = ThemeManager(root, logger)
|
||||
|
||||
ui_manager = UIManager(
|
||||
root, logger, medicine_manager, pathology_manager, theme_manager
|
||||
)
|
||||
|
||||
# Add a test medicine if none exist
|
||||
medicines = medicine_manager.get_all_medicines()
|
||||
if not medicines:
|
||||
from medicine_manager import Medicine
|
||||
|
||||
test_medicine = Medicine(
|
||||
key="bupropion",
|
||||
display_name="Bupropion",
|
||||
dosage="150mg",
|
||||
color="#4CAF50",
|
||||
quick_doses=["150", "300"],
|
||||
is_default=True,
|
||||
)
|
||||
medicine_manager.add_medicine(test_medicine)
|
||||
print("Added test medicine: Bupropion")
|
||||
|
||||
# Test data - simulate existing doses for today
|
||||
test_date = datetime.now().strftime("%Y-%m-%d")
|
||||
existing_doses = {"bupropion": "• 08:00 AM - 150mg\n• 12:00 PM - 150mg"}
|
||||
|
||||
# Create test callbacks
|
||||
def test_save_callback(edit_win, *args):
|
||||
print(f"Save callback called with {len(args)} arguments")
|
||||
print(f"Arguments: {args}")
|
||||
# Don't actually save, just print for testing
|
||||
|
||||
def test_delete_callback(edit_win):
|
||||
print("Delete callback called")
|
||||
edit_win.destroy()
|
||||
|
||||
callbacks = {"save": test_save_callback, "delete": test_delete_callback}
|
||||
|
||||
# Test values to populate the edit window
|
||||
test_values = (
|
||||
test_date, # date
|
||||
0, # pathology score (if any)
|
||||
1, # medicine taken (bupropion)
|
||||
existing_doses["bupropion"], # existing doses
|
||||
"Test note", # note
|
||||
)
|
||||
|
||||
print(f"Creating edit window with test values: {test_values}")
|
||||
|
||||
# Create the edit window
|
||||
_ = ui_manager.create_edit_window(test_values, callbacks)
|
||||
|
||||
# Add instructions label
|
||||
instructions = tk.Label(
|
||||
root,
|
||||
text="Instructions:\n"
|
||||
"1. The edit window should show existing doses: 08:00 AM and 12:00 PM\n"
|
||||
"2. Enter a new dose (e.g., 150) and click 'Take Bupropion'\n"
|
||||
"3. The new dose should be ADDED to existing doses, not replace them\n"
|
||||
"4. Click Save to see the final dose data in console",
|
||||
justify=tk.LEFT,
|
||||
wraplength=500,
|
||||
bg="lightyellow",
|
||||
padx=10,
|
||||
pady=10,
|
||||
)
|
||||
instructions.pack(pady=10, padx=10, fill=tk.X)
|
||||
|
||||
print("Test setup complete. Check the edit window for dose tracking behavior.")
|
||||
print(
|
||||
"Expected behavior: New doses should be added to existing ones, "
|
||||
"not replace them."
|
||||
)
|
||||
|
||||
root.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_dose_tracking()
|
||||
Reference in New Issue
Block a user