"""Tests for board column detection helpers.""" from __future__ import annotations from unittest.mock import MagicMock from selenium.common.exceptions import InvalidSelectorException from onedrive_planner import ( _FIRST_COLUMN_CLUSTER_WIDTH_PX, _element_in_board_container, _parent_element, ) def test_first_column_cluster_width_reasonable(): assert _FIRST_COLUMN_CLUSTER_WIDTH_PX >= 150 def test_parent_element_stops_at_html_document_error(): """ChromeDriver rejects .. on with InvalidSelectorException.""" html = MagicMock() html.tag_name = "html" html.find_element.side_effect = InvalidSelectorException( 'The result of the xpath expression ".." is: [object HTMLDocument].' ) assert _parent_element(html) is None def test_parent_element_returns_parent_for_body(): body = MagicMock() body.tag_name = "body" parent = MagicMock() parent.tag_name = "html" body.find_element.return_value = parent assert _parent_element(body) is parent def test_element_in_board_container_does_not_crash_at_root(): """Containment walk must not raise when ancestors hit document root.""" child = MagicMock() child.tag_name = "div" container = MagicMock() container.tag_name = "div" html = MagicMock() html.tag_name = "html" html.find_element.side_effect = InvalidSelectorException("document root") body = MagicMock() body.tag_name = "body" body.find_element.return_value = html child.find_element.return_value = body assert _element_in_board_container(child, container) is False