@@ -27,6 +27,93 @@ def _open_subtitle_harness(
2727 mock_page .goto (f"http://neko.test{ path } " )
2828
2929
30+ @pytest .mark .frontend
31+ def test_subtitle_background_opacity_tracks_dark_theme (
32+ mock_page : Page ,
33+ ):
34+ _open_subtitle_harness (
35+ mock_page ,
36+ "subtitle-window-host" ,
37+ """
38+ <div id="subtitle-display">
39+ <div id="subtitle-scroll"><span id="subtitle-text"></span></div>
40+ </div>
41+ """ ,
42+ )
43+ mock_page .evaluate (
44+ """
45+ () => {
46+ document.documentElement.setAttribute('data-theme', 'dark');
47+ window.localStorage.setItem('subtitleOpacity', '80');
48+ }
49+ """
50+ )
51+ mock_page .add_script_tag (path = str (PROJECT_ROOT / "static/subtitle-shared.js" ))
52+
53+ result = mock_page .evaluate (
54+ """
55+ async () => {
56+ const controller = window.nekoSubtitleShared.initSubtitleUI({ host: 'web' });
57+ const display = document.getElementById('subtitle-display');
58+ const darkBackground = display.style.background;
59+ document.documentElement.removeAttribute('data-theme');
60+ await new Promise((resolve) => setTimeout(resolve, 0));
61+ const lightBackground = display.style.background;
62+ document.documentElement.setAttribute('data-theme', 'dark');
63+ await new Promise((resolve) => setTimeout(resolve, 0));
64+ const darkBackgroundAfterAttributeChange = display.style.background;
65+ controller.destroy();
66+ return { darkBackground, lightBackground, darkBackgroundAfterAttributeChange };
67+ }
68+ """
69+ )
70+
71+ assert "rgba(18, 29, 45, 0.8)" in result ["darkBackground" ]
72+ assert "rgba(68, 183, 254, 0.8)" in result ["lightBackground" ]
73+ assert "rgba(18, 29, 45, 0.8)" in result ["darkBackgroundAfterAttributeChange" ]
74+
75+
76+ @pytest .mark .frontend
77+ def test_standalone_subtitle_background_uses_stored_dark_theme_on_open (
78+ mock_page : Page ,
79+ ):
80+ _open_subtitle_harness (
81+ mock_page ,
82+ "subtitle-window-host" ,
83+ """
84+ <div id="subtitle-display">
85+ <div id="subtitle-scroll"><span id="subtitle-text"></span></div>
86+ </div>
87+ """ ,
88+ )
89+ mock_page .evaluate (
90+ """
91+ () => {
92+ window.localStorage.setItem('neko-dark-mode', 'true');
93+ window.localStorage.setItem('subtitleOpacity', '80');
94+ }
95+ """
96+ )
97+ mock_page .add_script_tag (path = str (PROJECT_ROOT / "static/theme-manager.js" ))
98+ mock_page .add_script_tag (path = str (PROJECT_ROOT / "static/subtitle-shared.js" ))
99+
100+ result = mock_page .evaluate (
101+ """
102+ () => {
103+ const controller = window.nekoSubtitleShared.initSubtitleUI({ host: 'window' });
104+ const display = document.getElementById('subtitle-display');
105+ const background = display.style.background;
106+ const theme = document.documentElement.getAttribute('data-theme');
107+ controller.destroy();
108+ return { background, theme };
109+ }
110+ """
111+ )
112+
113+ assert result ["theme" ] == "dark"
114+ assert "rgba(18, 29, 45, 0.8)" in result ["background" ]
115+
116+
30117@pytest .mark .frontend
31118def test_subtitle_incremental_translation_starts_when_sentence_punctuation_arrives (
32119 mock_page : Page ,
0 commit comments