feat: 优化批量匹配和分页默认值 (#244)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -35,6 +36,8 @@ func TestInnerCodeTemplate_独立导航与安全表单(t *testing.T) {
|
||||
`data-need-checked="inner-code-delete"`, `data-confirm-delete-action="inner-code-delete"`,
|
||||
`inner-code-delete {{if .CanMatch}}inner-code-match{{end}}{{if .CanApply}} inner-code-apply`,
|
||||
`删除不会撤销顺运宝已写入的快递单号`, `匹配已选`, `aria-label="档口入库码记录列表"`,
|
||||
`data-auto-dismiss-toast data-transient-feedback`, `role="alertdialog"`,
|
||||
`id="inner-code-feedback-error-modal" data-auto-open-modal`,
|
||||
} {
|
||||
if !strings.Contains(page, want) {
|
||||
t.Errorf("正式页面缺少 %s", want)
|
||||
@@ -43,6 +46,62 @@ func TestInnerCodeTemplate_独立导航与安全表单(t *testing.T) {
|
||||
if strings.Contains(page, `{{if not .CanMatch}}disabled{{end}}`) {
|
||||
t.Fatal("所有状态都应允许勾选删除,不能再按 CanMatch 禁用复选框")
|
||||
}
|
||||
if strings.Contains(page, `inner-code-notice`) {
|
||||
t.Fatal("档口入库码反馈不应继续占用列表上方布局")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInnerCodeTemplate_错误弹窗自动转义且成功提示不占布局(t *testing.T) {
|
||||
tmpl, err := template.ParseFS(templateFS, "templates/*/*.html")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var output bytes.Buffer
|
||||
data := map[string]any{
|
||||
"Title": "档口入库码", "Active": "inner-codes", "CSRFToken": "test-csrf",
|
||||
"FeedbackError": true, "FeedbackMessage": `<script>alert("secret")</script>`,
|
||||
}
|
||||
if err := tmpl.ExecuteTemplate(&output, "inner_code/list", data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := output.String()
|
||||
for _, want := range []string{
|
||||
`role="alertdialog"`, `data-auto-open-modal`,
|
||||
`<script>alert("secret")</script>`,
|
||||
`系统不会因本弹窗自动重复匹配或回写`,
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("错误反馈弹窗缺少 %q", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, `<script>alert("secret")</script>`) {
|
||||
t.Fatal("错误反馈未经 html/template 自动转义")
|
||||
}
|
||||
|
||||
rawJS, err := os.ReadFile("static/js/app.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
js := string(rawJS)
|
||||
for _, want := range []string{
|
||||
`function setupTransientFeedback()`, `data-auto-dismiss-toast`,
|
||||
`window.setTimeout(function ()`, `}, 4000);`,
|
||||
`current.searchParams.delete(name)`, `window.history.replaceState`,
|
||||
`setupTransientFeedback();`,
|
||||
} {
|
||||
if !strings.Contains(js, want) {
|
||||
t.Errorf("临时反馈脚本缺少 %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
cssRaw, err := os.ReadFile("static/css/app.css")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
css := string(cssRaw)
|
||||
if !strings.Contains(css, `.inner-code-toast {`) || !strings.Contains(css, `position: fixed;`) {
|
||||
t.Fatal("成功提示必须固定定位,不能占用表格布局")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInnerCodeTemplate_模块状态白名单已登记(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user