Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import pytest
|
|
from datetime import datetime
|
|
import tkinter as tk
|
|
from src.ui_manager import UIManager
|
|
|
|
@pytest.fixture
|
|
def root_window():
|
|
root = tk.Tk()
|
|
yield root
|
|
root.destroy()
|
|
|
|
@pytest.fixture
|
|
def ui_manager(root_window):
|
|
class DummyLogger:
|
|
def debug(self, *a, **k): pass
|
|
def warning(self, *a, **k): pass
|
|
def error(self, *a, **k): pass
|
|
return UIManager(root_window, DummyLogger())
|
|
|
|
def test_parse_dose_history_for_saving_bullet_and_delete(ui_manager):
|
|
# Simulate user editing: add, delete, and custom lines
|
|
date_str = "07/30/2025"
|
|
# User deletes one line, adds a custom one
|
|
text = """
|
|
• 09:00 AM - 150mg
|
|
• 06:00 PM - 150mg
|
|
Custom note
|
|
""".strip()
|
|
result = ui_manager._parse_dose_history_for_saving(text, date_str)
|
|
# Should parse both bullets and keep the custom line
|
|
assert "2025-07-30 09:00:00:150mg" in result
|
|
assert "2025-07-30 18:00:00:150mg" in result
|
|
assert "Custom note" in result
|
|
# If user deletes all, should return empty string
|
|
assert ui_manager._parse_dose_history_for_saving("", date_str) == ""
|
|
assert ui_manager._parse_dose_history_for_saving("No doses recorded today", date_str) == ""
|
|
|
|
def test_parse_dose_history_for_saving_simple_time(ui_manager):
|
|
date_str = "07/30/2025"
|
|
text = "09:00 150mg\n18:00 150mg"
|
|
result = ui_manager._parse_dose_history_for_saving(text, date_str)
|
|
assert "2025-07-30 09:00:00:150mg" in result
|
|
assert "2025-07-30 18:00:00:150mg" in result
|
|
|
|
def test_parse_dose_history_for_saving_mixed(ui_manager):
|
|
date_str = "07/30/2025"
|
|
text = "• 09:00 AM - 150mg\n18:00 150mg\nJust a note"
|
|
result = ui_manager._parse_dose_history_for_saving(text, date_str)
|
|
assert "2025-07-30 09:00:00:150mg" in result
|
|
assert "2025-07-30 18:00:00:150mg" in result
|
|
assert "Just a note" in result
|