98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
|
|
import tkinter as tk
|
|||
|
|
from unittest.mock import Mock
|
|||
|
|
import pytest
|
|||
|
|
from time_tracker.ui.overlay import OverlayWindow
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_overlay_window_appears():
|
|||
|
|
"""Test that overlay window actually appears and has expected widgets"""
|
|||
|
|
root = tk.Tk()
|
|||
|
|
root.withdraw() # Hide the root window initially
|
|||
|
|
|
|||
|
|
# Mock dependencies with proper return values
|
|||
|
|
mock_tracker = Mock()
|
|||
|
|
mock_tracker.get_current_session_duration.return_value = 0
|
|||
|
|
mock_tracker.get_total_work_today.return_value = 0
|
|||
|
|
mock_tracker.get_planned_duration.return_value = None
|
|||
|
|
mock_tracker.active_window = 'Desktop'
|
|||
|
|
mock_tracker.window_classification = 'neutral'
|
|||
|
|
mock_tracker.has_active_session.return_value = False
|
|||
|
|
mock_tracker.get_available_tasks.return_value = []
|
|||
|
|
|
|||
|
|
mock_config = Mock()
|
|||
|
|
mock_config.tracking_enabled = True
|
|||
|
|
mock_config.current_task_id = None
|
|||
|
|
|
|||
|
|
# Create overlay window
|
|||
|
|
overlay = OverlayWindow(root, mock_tracker, mock_config)
|
|||
|
|
|
|||
|
|
# Check that the window is actually created and visible
|
|||
|
|
assert overlay.root is not None
|
|||
|
|
assert isinstance(overlay.root, tk.Tk)
|
|||
|
|
|
|||
|
|
# Check that window properties are set
|
|||
|
|
assert overlay.root.wm_attributes('-topmost') == 1
|
|||
|
|
|
|||
|
|
# Check that required widgets exist
|
|||
|
|
assert hasattr(overlay, 'status_label')
|
|||
|
|
assert hasattr(overlay, 'task_label')
|
|||
|
|
assert hasattr(overlay, 'window_label')
|
|||
|
|
assert hasattr(overlay, 'total_label')
|
|||
|
|
|
|||
|
|
# Check that buttons exist
|
|||
|
|
assert hasattr(overlay, 'track_btn')
|
|||
|
|
|
|||
|
|
# Check that labels have been created and are not None
|
|||
|
|
assert overlay.status_label is not None
|
|||
|
|
assert overlay.task_label is not None
|
|||
|
|
assert overlay.window_label is not None
|
|||
|
|
assert overlay.total_label is not None
|
|||
|
|
|
|||
|
|
# Check that the widgets are packed/grid
|
|||
|
|
assert overlay.status_label.winfo_exists() == 1
|
|||
|
|
assert overlay.task_label.winfo_exists() == 1
|
|||
|
|
assert overlay.window_label.winfo_exists() == 1
|
|||
|
|
assert overlay.total_label.winfo_exists() == 1
|
|||
|
|
|
|||
|
|
root.destroy()
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_overlay_window_widgets_are_visible():
|
|||
|
|
"""Test that overlay window widgets are properly configured and visible"""
|
|||
|
|
root = tk.Tk()
|
|||
|
|
root.withdraw()
|
|||
|
|
|
|||
|
|
# Mock dependencies
|
|||
|
|
mock_tracker = Mock()
|
|||
|
|
mock_tracker.get_current_session_duration.return_value = 3600 # 1 hour
|
|||
|
|
mock_tracker.get_total_work_today.return_value = 7200 # 2 hours
|
|||
|
|
mock_tracker.get_planned_duration.return_value = None
|
|||
|
|
mock_tracker.active_window = 'PyCharm'
|
|||
|
|
mock_tracker.window_classification = 'work'
|
|||
|
|
mock_tracker.has_active_session.return_value = True
|
|||
|
|
mock_tracker.get_available_tasks.return_value = ['TASK-1', 'TASK-2']
|
|||
|
|
|
|||
|
|
mock_config = Mock()
|
|||
|
|
mock_config.tracking_enabled = True
|
|||
|
|
mock_config.current_task_id = 'PRJ-123'
|
|||
|
|
|
|||
|
|
overlay = OverlayWindow(root, mock_tracker, mock_config)
|
|||
|
|
|
|||
|
|
# Force an update to populate the labels
|
|||
|
|
overlay.update_display()
|
|||
|
|
|
|||
|
|
# Check that labels have text content
|
|||
|
|
status_text = overlay.status_label.cget('text')
|
|||
|
|
task_text = overlay.task_label.cget('text')
|
|||
|
|
window_text = overlay.window_label.cget('text')
|
|||
|
|
total_text = overlay.total_label.cget('text')
|
|||
|
|
|
|||
|
|
# Verify that the labels contain expected information
|
|||
|
|
assert 'Трекинг:' in status_text
|
|||
|
|
assert 'PRJ-123' in task_text
|
|||
|
|
assert 'Окно:' in window_text
|
|||
|
|
assert 'Всего сегодня:' in total_text
|
|||
|
|
|
|||
|
|
root.destroy()
|
|||
|
|
|