fix(admin): 壁纸注入补测试;测试夹具真实备案号换占位值;后台历史条数展示

This commit is contained in:
JianFeeeee
2026-10-02 11:24:55 +08:00
parent 85abe9f728
commit 495e4ee20e
3 changed files with 75 additions and 2 deletions

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -236,7 +236,7 @@ html[data-theme="dark"] .toast{ box-shadow:0 10px 30px rgba(0,0,0,.5) }
<!-- 历史访问 -->
<div class="card">
<h2>历史访问</h2>
<p class="sub" style="margin:0 0 12px">删除单条或清空全部浏览记录;删除后 Dashy 的「历史访问」分组会立即重建。</p>
<p class="sub" style="margin:0 0 12px">删除单条或清空全部浏览记录;删除后 Dashy 的「历史访问」分组会立即重建。<span id="hist-count" class="muted"></span></p>
<div id="hist"><div class="muted">读取中…</div></div>
<div style="margin-top:14px"><button class="ghost" id="clear-hist">清空全部历史</button></div>
</div>
@ -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 = '<div class="muted">暂无历史记录</div>'; return; }
el.innerHTML = HIST.map((it, i) => `
<div class="itm">