diff --git a/admin-server/main_test.go b/admin-server/main_test.go index 0a079be..ca3c616 100644 --- a/admin-server/main_test.go +++ b/admin-server/main_test.go @@ -18,7 +18,7 @@ func TestBeianFooter(t *testing.T) { {name: "both", icp: "京ICP备00000000号-1", gongan: "京公网安备00000000000000号", wantParts: []string{"class=\"navi-footer\"", "beian.miit.gov.cn", "京ICP备00000000号-1", "navi-footer-sep", "beian.mps.gov.cn", "京公网安备00000000000000号"}}, {name: "only icp", icp: " 京ICP备12345678号 ", wantParts: []string{"class=\"navi-footer\"", "京ICP备12345678号"}}, - {name: "only gongan", gongan: "沪公网安备31010102002555号", wantParts: []string{"class=\"navi-footer\"", "沪公网安备31010102002555号"}}, + {name: "only gongan", gongan: "沪公网安备12345678901号", wantParts: []string{"class=\"navi-footer\"", "沪公网安备12345678901号"}}, {name: "blank", icp: " ", gongan: "", wantEmpty: true}, } for _, tc := range cases { diff --git a/admin-server/wp_inject_test.go b/admin-server/wp_inject_test.go new file mode 100644 index 0000000..d584f74 --- /dev/null +++ b/admin-server/wp_inject_test.go @@ -0,0 +1,68 @@ +package main + +import ( + "strings" + "testing" +) + +// 模板里不含 NAVI-WALLPAPER 块时,applyWallpaperBlock 应正确注入; +// 已含旧块时应替换而非追加(否则壁纸规则会重复累积)。 +func TestApplyWallpaperBlock_Injects(t *testing.T) { + base := "html[data-theme] body{color:red}" + got := applyWallpaperBlock(base, "/wallpapers/x.jpg", 0.35) + if !strings.Contains(got, wallpaperBegin) || !strings.Contains(got, wallpaperEnd) { + t.Fatalf("未注入标记块: %q", got) + } + if !strings.Contains(got, `url("/wallpapers/x.jpg")`) { + t.Fatalf("未注入壁纸 url: %q", got) + } + if n := strings.Count(got, wallpaperBegin); n != 1 { + t.Fatalf("标记块应只出现一次,实际 %d 次", n) + } + if !strings.Contains(got, "rgba(255,255,255,0.35)") { + t.Errorf("浅色遮罩透明度不对: %q", got) + } + // 深色遮罩应为 dim+0.15 + if !strings.Contains(got, "rgba(6,12,24,0.50)") { + t.Errorf("深色遮罩应为 0.50(dim+0.15): %q", got) + } +} + +func TestApplyWallpaperBlock_ReplacesOld(t *testing.T) { + old := "a{}\n\n" + wallpaperBegin + "\nOLD CONTENT\n" + wallpaperEnd + "\nb{}\n" + got := applyWallpaperBlock(old, "/wallpapers/new.jpg", 0.35) + if strings.Contains(got, "OLD CONTENT") { + t.Errorf("旧壁纸块未被替换: %q", got) + } + if n := strings.Count(got, wallpaperBegin); n != 1 { + t.Errorf("替换后标记块应只出现一次,实际 %d 次:\n%s", n, got) + } + if !strings.Contains(got, "/wallpapers/new.jpg") { + t.Errorf("新壁纸 url 未写入") + } + // 旧块前后的内容都要保留 + if !strings.Contains(got, "a{}") || !strings.Contains(got, "b{}") { + t.Errorf("替换破坏了周边内容:\n%s", got) + } +} + +func TestApplyWallpaperBlock_NoURL(t *testing.T) { + base := "a{}" + got := applyWallpaperBlock(base, "", 0.35) + if strings.Contains(got, wallpaperBegin) { + t.Errorf("url 为空时不应注入壁纸块: %q", got) + } + if strings.TrimSpace(got) != "a{}" { + t.Errorf("url 为空时应原样返回: %q", got) + } +} + +func TestApplyWallpaperBlock_DimClamp(t *testing.T) { + got := applyWallpaperBlock("a{}", "/w.jpg", 5.0) + if strings.Contains(got, "rgba(255,255,255,5.00)") { + t.Errorf("dim 应被钳制到 0.9:\n%s", got) + } + if !strings.Contains(got, "0.90") { + t.Errorf("钳制后应写入 0.90:\n%s", got) + } +} diff --git a/admin/index.html b/admin/index.html index d6eee56..e456abe 100644 --- a/admin/index.html +++ b/admin/index.html @@ -236,7 +236,7 @@ html[data-theme="dark"] .toast{ box-shadow:0 10px 30px rgba(0,0,0,.5) }

历史访问

-

删除单条或清空全部浏览记录;删除后 Dashy 的「历史访问」分组会立即重建。

+

删除单条或清空全部浏览记录;删除后 Dashy 的「历史访问」分组会立即重建。

读取中…
@@ -559,6 +559,11 @@ function friendlyTitle(it) { function renderHistory() { const el = document.getElementById('hist'); + const cnt = document.getElementById('hist-count'); + if (cnt) { + // 读取侧已不截断(与门户「历史访问」不限条数保持一致),这里如实显示条数 + cnt.textContent = HIST.length ? '当前共 ' + HIST.length + ' 条。' : ''; + } if (!HIST.length) { el.innerHTML = '
暂无历史记录
'; return; } el.innerHTML = HIST.map((it, i) => `