feat: add local library and refresh interface
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parents[1] / "main.py"
|
||||
spec = importlib.util.spec_from_file_location("toreadeck_main", MODULE_PATH)
|
||||
main = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(main)
|
||||
|
||||
|
||||
class LocalLibraryTests(unittest.TestCase):
|
||||
def test_default_config_has_reader_directory(self):
|
||||
with patch.object(main, "CONFIG_FILE", "missing-config.json"):
|
||||
config = main.load_config()
|
||||
self.assertEqual(config["reader_directory"], str(Path(main.BASE_DIR) / "pages"))
|
||||
|
||||
def test_library_lists_files_without_loading_their_contents(self):
|
||||
from tempfile import TemporaryDirectory
|
||||
with TemporaryDirectory() as directory:
|
||||
path = Path(directory)
|
||||
(path / "note.txt").write_text("Очень большой текст файла", encoding="utf-8")
|
||||
with patch.object(main, "load_config", return_value={"reader_directory": str(path)}):
|
||||
response = main.reader_window()
|
||||
body = response.body.decode("utf-8")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Локальная библиотека", body)
|
||||
self.assertIn("note.txt", body)
|
||||
self.assertIn("Открыть", body)
|
||||
self.assertNotIn("Очень большой текст файла", body)
|
||||
self.assertNotIn("<textarea", body)
|
||||
|
||||
def test_reader_page_displays_file_and_can_send_it_to_importer(self):
|
||||
from tempfile import TemporaryDirectory
|
||||
with TemporaryDirectory() as directory:
|
||||
path = Path(directory)
|
||||
(path / "note.txt").write_text("Текст заметки", encoding="utf-8")
|
||||
with patch.object(main, "load_config", return_value={"reader_directory": str(path)}):
|
||||
response = main.reader_file("note.txt")
|
||||
body = response.body.decode("utf-8")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Текст заметки", body)
|
||||
self.assertIn("Отправить в Readeck", body)
|
||||
self.assertIn("window.opener.postMessage", body)
|
||||
self.assertNotIn("<textarea", body)
|
||||
|
||||
|
||||
class ApplicationDesignTests(unittest.TestCase):
|
||||
def test_main_ui_uses_the_calm_workspace_design_system(self):
|
||||
page = main.HTML_TEMPLATE
|
||||
self.assertIn("--workspace", page)
|
||||
self.assertIn("--surface", page)
|
||||
self.assertIn(".app-shell", page)
|
||||
self.assertIn(".workspace-card", page)
|
||||
self.assertNotIn("background: linear-gradient(135deg, #667eea", page)
|
||||
|
||||
def test_library_and_reader_use_shared_reader_design_tokens(self):
|
||||
from tempfile import TemporaryDirectory
|
||||
with TemporaryDirectory() as directory:
|
||||
path = Path(directory)
|
||||
(path / "note.txt").write_text("Текст", encoding="utf-8")
|
||||
with patch.object(main, "load_config", return_value={"reader_directory": str(path)}):
|
||||
library = main.reader_window().body.decode("utf-8")
|
||||
reader = main.reader_file("note.txt").body.decode("utf-8")
|
||||
self.assertIn("--workspace", library)
|
||||
self.assertIn("--workspace", reader)
|
||||
self.assertIn("reader-topbar", reader)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user