feat: 统一 Admin 主列表分页 (#64)
This commit is contained in:
+24
-2
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -11,7 +12,23 @@ import (
|
||||
"cmautobuy/admin/service"
|
||||
)
|
||||
|
||||
// 五个主页面都走一次真实路由和模板渲染。
|
||||
func TestPaginationCSS_桌面右对齐且窄窗口不遮挡内容(t *testing.T) {
|
||||
content, err := os.ReadFile("static/css/app.css")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
css := string(content)
|
||||
for _, want := range []string{
|
||||
"margin-left: auto", "flex: 0 0 auto", "@media (max-width: 760px)",
|
||||
"position: static", "justify-content: flex-end",
|
||||
} {
|
||||
if !strings.Contains(css, want) {
|
||||
t.Fatalf("分页布局 CSS 缺少 %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 六个主页面都走一次真实路由和模板渲染。
|
||||
// 这样模板字段写错或新增列漏接时,测试阶段就会失败,不必等人工点页面。
|
||||
func TestMainPagesReturnOK(t *testing.T) {
|
||||
db, err := repository.Open(t.TempDir())
|
||||
@@ -49,7 +66,7 @@ func TestMainPagesReturnOK(t *testing.T) {
|
||||
request.AddCookie(&http.Cookie{Name: "cmautobuy_session", Value: token})
|
||||
}
|
||||
|
||||
for _, path := range []string{"/shopee", "/pdd", "/syb", "/tasks", "/clients"} {
|
||||
for _, path := range []string{"/shopee", "/pdd", "/syb", "/tasks", "/clients", "/users"} {
|
||||
t.Run(path, func(t *testing.T) {
|
||||
request := httptest.NewRequest(http.MethodGet, path, nil)
|
||||
addAuth(request)
|
||||
@@ -59,6 +76,11 @@ func TestMainPagesReturnOK(t *testing.T) {
|
||||
t.Fatalf("GET %s = %d,期望 200,响应:%s",
|
||||
path, response.Code, response.Body.String())
|
||||
}
|
||||
body := response.Body.String()
|
||||
if !strings.Contains(body, `<nav class="pagination" aria-label="分页">`) ||
|
||||
!strings.Contains(body, "首页") || !strings.Contains(body, "末页") {
|
||||
t.Fatalf("GET %s 没有渲染公共分页组件:%s", path, body)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user