Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(tests): 补上三处只在 CI 上红的判据

longmeidaof160e6574600
diff --git a/frontend/src/review-bulk.ts b/frontend/src/review-bulk.ts
index 9d96fb58b..806cc899d 100644
--- a/frontend/src/review-bulk.ts
+++ b/frontend/src/review-bulk.ts
@@ -21,8 +21,9 @@ export function updateReviewSticky(root: HTMLElement | null) {
每层只糊自己身后那一段页面,两行相接处就显出两种颜色,读起来是上下两个框。 */
const stuck = bars.filter(bar => bar.classList.contains('is-stuck'));
root.classList.toggle('review-is-stuck', stuck.length > 0);
- if (!stuck.length) return;
- const head = stuck[0].getBoundingClientRect(), foot = stuck[stuck.length - 1].getBoundingClientRect();
+ const first = stuck[0], last = stuck.at(-1);
+ if (!first || !last) return;
+ const head = first.getBoundingClientRect(), foot = last.getBoundingClientRect();
root.style.setProperty('--review-pane-left', `${head.left}px`);
root.style.setProperty('--review-pane-width', `${head.width}px`);
root.style.setProperty('--review-pane-height', `${foot.bottom - head.top}px`);
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index 19cf3cc2c..e4f0510c2 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -1710,7 +1710,9 @@ class FollowWebSourceTests(unittest.TestCase):
page = self.page
manage = page[page.index("function renderFollowManage("):
page.index("function wireFollowItems(")]
- add_section = manage[manage.index('<section class="fsec">'):
+ # 三块内容各是一个工作区面板,按 `data-follow-workspace-panel` 认,别按
+ # `class="fsec"` 认——三块都带这个类,取到的会是第一块而不是「添加关注」。
+ add_section = manage[manage.index('<section class="fsec" data-follow-workspace-panel="add">'):
manage.index('</section>')]
self.assertIn('id="followPicks"', add_section)
self.assertNotIn('</section>\n <div id="followPicks">', manage)
@@ -1925,10 +1927,12 @@ class FollowWebSourceTests(unittest.TestCase):
self.assertPageContains(
"document.body.classList.toggle('follow-manage-layout',"
"decodeURIComponent(location.pathname)==='/follow-manage')")
- # 凭据现在是主列里的第三块,不再是 aside。
+ # 凭据是主列里的第三块,标题是「来源管理」,凭据行就渲染在它里面。
body = page[page.index("function renderFollowManage("):
page.index("function wireFollowManage(")]
- self.assertLess(body.index("<h3>关注列表</h3>"), body.index("<h3>凭据</h3>"))
+ self.assertLess(body.index("<h3>关注列表</h3>"), body.index("<h3>来源管理</h3>"))
+ credentials = body[body.index("<h3>来源管理</h3>"):]
+ self.assertIn("creds.map(followCredentialRow)", credentials)
def test_sections_have_a_frame_but_their_rows_do_not(self):
"""反模式是卡片**套**卡片,不是「不要任何容器」。
diff --git a/tests/test_rm_web.py b/tests/test_rm_web.py
index 853f37b06..1402ff978 100644
--- a/tests/test_rm_web.py
+++ b/tests/test_rm_web.py
@@ -8,9 +8,9 @@ import threading
import time
import unittest
from contextlib import closing, contextmanager
+from dataclasses import replace
from pathlib import Path
from unittest import mock
-from types import SimpleNamespace
from peach import catalog_rules, web_batch, web_catalog, web_stats
from peach import web_contract as rm_web
@@ -202,8 +202,13 @@ class WebDataTests(unittest.TestCase):
connection.execute("UPDATE asset SET path=? WHERE id=1", (r"R:\Media\one.mp4",))
connection.execute("UPDATE asset SET path=? WHERE id=3", (r"R:\Media\cover.jpg",))
connection.commit()
- config = SimpleNamespace(locations={"local": [r"R:\Media", r"R:\Media-more"]},
- library_names={}, library_icons={})
+ # 改真配置的这几个字段,不另捏一个只带它们的对象:`active()` 是全模块共用的,
+ # 存储卷那一段顺着 `translate_ledger_path` 也要读 `mounts`,缺字段就是
+ # AttributeError。Windows 上账本路径不必翻译、走不到那一步,只有 macOS 会红。
+ config = replace(
+ web_stats.settings_file.load_config(environ={}, strict=False),
+ locations={"local": (r"R:\Media", r"R:\Media-more")},
+ library_names={}, library_icons={})
with mock.patch.object(web_stats.settings_file, "active", return_value=config):
rows = rm_web.q_stats(self.contract)["by_library"]
self.assertEqual([(row["name"], row["videos"], row["bytes"]) for row in rows],
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index d33879e08..33ad80e1e 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -7586,7 +7586,9 @@ class WebUiSourceTests(unittest.TestCase):
self.assertIn(fallback, board)
bulk = (Path(__file__).resolve().parents[1] / "frontend" / "src" / "review-bulk.ts").read_text(encoding="utf-8")
self.assertIn("root.classList.toggle('review-is-stuck', stuck.length > 0);", bulk)
- self.assertIn("const head = stuck[0].getBoundingClientRect(), foot = stuck[stuck.length - 1].getBoundingClientRect();", bulk)
+ # 玻璃的两端取自首尾两条粘住的横条;下面三行 setProperty 才是它铺多大。
+ self.assertIn("const first = stuck[0], last = stuck.at(-1);", bulk)
+ self.assertIn("const head = first.getBoundingClientRect(), foot = last.getBoundingClientRect();", bulk)
for name, edge in (("left", "head.left"), ("width", "head.width"), ("height", "foot.bottom - head.top")):
self.assertIn(f"root.style.setProperty('--review-pane-{name}', `${{{edge}}}px`);", bulk)
diff --git a/web/dist/peach-ui.js b/web/dist/peach-ui.js
index 6df45d968..d5a31a967 100644
--- a/web/dist/peach-ui.js
+++ b/web/dist/peach-ui.js
@@ -3949,9 +3949,11 @@ function Qr(e) {
e.classList.toggle("is-stuck", e.offsetParent !== null && window.scrollY > 0 && Number.isFinite(t) && Math.abs(e.getBoundingClientRect().top - t) <= 1);
}
let r = n.filter((e) => e.classList.contains("is-stuck"));
- if (e.classList.toggle("review-is-stuck", r.length > 0), !r.length) return;
- let i = r[0].getBoundingClientRect(), a = r[r.length - 1].getBoundingClientRect();
- e.style.setProperty("--review-pane-left", `${i.left}px`), e.style.setProperty("--review-pane-width", `${i.width}px`), e.style.setProperty("--review-pane-height", `${a.bottom - i.top}px`);
+ e.classList.toggle("review-is-stuck", r.length > 0);
+ let i = r[0], a = r.at(-1);
+ if (!i || !a) return;
+ let o = i.getBoundingClientRect(), s = a.getBoundingClientRect();
+ e.style.setProperty("--review-pane-left", `${o.left}px`), e.style.setProperty("--review-pane-width", `${o.width}px`), e.style.setProperty("--review-pane-height", `${s.bottom - o.top}px`);
}
function $r(e, t) {
let n = [[