Files
yiyezhqiu-refactored/tests/ui/test_layout_preferences.py
T

34 lines
1.5 KiB
Python

import json
from PySide6.QtCore import QPoint, QSize
from dx_productivity.ui.layout_preferences import LayoutPreferences
def test_layout_preferences_validate_types_and_recover_from_corruption(tmp_path):
path = tmp_path / 'ui-layout.json'
path.write_text('{broken', encoding='utf-8')
assert LayoutPreferences(path).position is None
path.write_text(json.dumps({'toolbar_position': [True, 40], 'page_sizes': {'0': [720, '420'], '7': [660, 380], '999': [900, 600]}, 'screen': 123}), encoding='utf-8')
preferences = LayoutPreferences(path)
assert preferences.position is None
assert preferences.screen_name == ''
assert preferences.page_sizes == {7: QSize(660, 380)}
def test_layout_preferences_round_trip_negative_monitor_position_and_atomic_write(tmp_path):
path = tmp_path / 'DxProductivity' / 'ui-layout.json'
settings = tmp_path / 'DxProductivity' / 'settings.json'
settings.parent.mkdir()
settings.write_text('{"channel":"stable"}', encoding='utf-8')
preferences = LayoutPreferences(path)
preferences.position = QPoint(-1200, 80)
preferences.screen_name = 'Second monitor'
preferences.page_sizes[0] = QSize(780, 490)
preferences.save()
fresh = LayoutPreferences(path)
assert fresh.position == QPoint(-1200, 80)
assert fresh.page_sizes[0] == QSize(780, 490)
assert fresh.screen_name == 'Second monitor'
assert settings.read_text(encoding='utf-8') == '{"channel":"stable"}'
assert not tuple(path.parent.glob('*.tmp'))