feat: theme

This commit is contained in:
kodi
2026-03-12 18:26:29 +01:00
parent 939a7fd191
commit ab83ee3f20
13 changed files with 374 additions and 34 deletions
@@ -59,6 +59,8 @@ class SettingsApiGoldenTest(unittest.TestCase):
"show_thumbnails": False,
"preferred_startup_path_left": None,
"preferred_startup_path_right": None,
"selected_theme": "default",
"selected_color_mode": "dark",
},
)
@@ -75,6 +77,8 @@ class SettingsApiGoldenTest(unittest.TestCase):
"show_thumbnails": False,
"preferred_startup_path_left": "storage1/docs",
"preferred_startup_path_right": None,
"selected_theme": "default",
"selected_color_mode": "dark",
},
)
@@ -96,6 +100,8 @@ class SettingsApiGoldenTest(unittest.TestCase):
"show_thumbnails": True,
"preferred_startup_path_left": "storage1/docs",
"preferred_startup_path_right": "storage1/docs",
"selected_theme": "default",
"selected_color_mode": "dark",
},
)
self.assertEqual(
@@ -104,6 +110,8 @@ class SettingsApiGoldenTest(unittest.TestCase):
"show_thumbnails": True,
"preferred_startup_path_left": "storage1/docs",
"preferred_startup_path_right": "storage1/docs",
"selected_theme": "default",
"selected_color_mode": "dark",
},
)
@@ -113,6 +121,8 @@ class SettingsApiGoldenTest(unittest.TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["preferred_startup_path_left"], "storage1/docs")
self.assertEqual(response.json()["preferred_startup_path_right"], None)
self.assertEqual(response.json()["selected_theme"], "default")
self.assertEqual(response.json()["selected_color_mode"], "dark")
def test_settings_preferred_startup_path_right_persistence(self) -> None:
response = self._request("POST", "/api/settings", {"preferred_startup_path_right": "storage1/docs"})
@@ -120,6 +130,8 @@ class SettingsApiGoldenTest(unittest.TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["preferred_startup_path_left"], None)
self.assertEqual(response.json()["preferred_startup_path_right"], "storage1/docs")
self.assertEqual(response.json()["selected_theme"], "default")
self.assertEqual(response.json()["selected_color_mode"], "dark")
def test_settings_preferred_startup_path_empty_string_resets_only_left_to_null(self) -> None:
self._request(
@@ -135,6 +147,34 @@ class SettingsApiGoldenTest(unittest.TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["preferred_startup_path_left"], None)
self.assertEqual(response.json()["preferred_startup_path_right"], "storage1/docs")
self.assertEqual(response.json()["selected_theme"], "default")
self.assertEqual(response.json()["selected_color_mode"], "dark")
def test_settings_selected_theme_persistence(self) -> None:
response = self._request("POST", "/api/settings", {"selected_theme": "default"})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["selected_theme"], "default")
self.assertEqual(response.json()["selected_color_mode"], "dark")
def test_settings_selected_color_mode_persistence(self) -> None:
response = self._request("POST", "/api/settings", {"selected_color_mode": "light"})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["selected_theme"], "default")
self.assertEqual(response.json()["selected_color_mode"], "light")
def test_settings_rejects_invalid_selected_theme(self) -> None:
response = self._request("POST", "/api/settings", {"selected_theme": "unknown"})
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["error"]["code"], "invalid_request")
def test_settings_rejects_invalid_selected_color_mode(self) -> None:
response = self._request("POST", "/api/settings", {"selected_color_mode": "sepia"})
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["error"]["code"], "invalid_request")
def test_settings_preferred_startup_path_left_rejects_file_path(self) -> None:
response = self._request("POST", "/api/settings", {"preferred_startup_path_left": "storage1/file.txt"})
@@ -65,14 +65,19 @@ class UiSmokeGoldenTest(unittest.TestCase):
self.assertIn('id="rename-input"', body)
self.assertIn('id="rename-apply-btn"', body)
self.assertIn('id="settings-general-tab"', body)
self.assertIn('id="settings-interface-tab"', body)
self.assertIn('id="settings-logs-tab"', body)
self.assertIn('id="settings-show-thumbnails"', body)
self.assertIn("Show thumbnails", body)
self.assertIn('id="settings-selected-theme"', body)
self.assertIn("Theme", body)
self.assertNotIn('id="settings-selected-color-mode"', body)
self.assertIn('id="settings-startup-path-left"', body)
self.assertIn('id="settings-startup-path-right"', body)
self.assertIn("Preferred startup path (left)", body)
self.assertIn("Preferred startup path (right)", body)
self.assertIn('id="settings-general-save-btn"', body)
self.assertIn('id="settings-interface-save-btn"', body)
self.assertIn('id="settings-logs-list"', body)
self.assertIn('id="viewer-content"', body)
self.assertIn('id="editor-modal"', body)
@@ -119,7 +124,9 @@ class UiSmokeGoldenTest(unittest.TestCase):
self.assertTrue((static_root / "style.css").exists())
app_js = (static_root / "app.js").read_text(encoding="utf-8")
self.assertIn('currentPath: "/Volumes"', app_js)
self.assertIn('const THEME_STORAGE_KEY = "webmanager-theme"', app_js)
self.assertIn('selectedTheme: "default"', app_js)
self.assertIn('selectedColorMode: "dark"', app_js)
self.assertIn('function effectiveThemeKey(theme, colorMode)', app_js)
self.assertIn("document.documentElement.dataset.theme", app_js)
self.assertIn('document.getElementById("theme-toggle").onclick = toggleTheme;', app_js)
self.assertIn('document.getElementById("settings-btn").onclick = () => openSettings("general");', app_js)
@@ -127,12 +134,19 @@ class UiSmokeGoldenTest(unittest.TestCase):
self.assertIn('await loadSettings();', app_js)
self.assertIn('settings.showThumbnailsInput.onchange = handleShowThumbnailsChange;', app_js)
self.assertIn('settings.generalSaveButton.onclick = handlePreferredStartupPathSave;', app_js)
self.assertIn('settings.interfaceSaveButton.onclick = handleInterfaceSave;', app_js)
self.assertIn('preferredStartupPathLeft', app_js)
self.assertIn('preferredStartupPathRight', app_js)
self.assertIn('selected_theme', app_js)
self.assertIn('selected_color_mode', app_js)
self.assertNotIn("localStorage", app_js)
self.assertNotIn("THEME_STORAGE_KEY", app_js)
self.assertIn('preferred_startup_path_left', app_js)
self.assertIn('preferred_startup_path_right', app_js)
self.assertIn('paneState("left").currentPath = settingsState.preferredStartupPathLeft || "/Volumes";', app_js)
self.assertIn('paneState("right").currentPath = settingsState.preferredStartupPathRight || "/Volumes";', app_js)
self.assertIn('applyTheme(settingsState.selectedTheme, settingsState.selectedColorMode);', app_js)
self.assertIn('settings.interfaceTab.onclick = () => setSettingsTab("interface");', app_js)
self.assertIn('"/api/settings"', app_js)
self.assertIn('`/api/files/thumbnail?', app_js)
self.assertIn("function iconTypeForEntry(entry)", app_js)
@@ -180,8 +194,8 @@ class UiSmokeGoldenTest(unittest.TestCase):
self.assertIn("function rootKeyFromPath(path)", app_js)
self.assertIn("function isNestedPath(sourcePath, destinationPath)", app_js)
style_css = (static_root / "style.css").read_text(encoding="utf-8")
self.assertIn(':root[data-theme="dark"]', style_css)
self.assertIn(':root[data-theme="light"]', style_css)
self.assertIn(':root[data-theme="default-dark"]', style_css)
self.assertIn(':root[data-theme="default-light"]', style_css)
self.assertIn('#theme-toggle', style_css)
self.assertIn('.settings-card', style_css)
self.assertIn('.settings-tabs', style_css)