- 集成 tauri-plugin-opener:Cargo/lib.rs/capabilities/npm 四处接线,新增 src/openExternal.ts(桌面走 opener,浏览器回退 window.open,相对路径绝对化) - 关于页 4 个链接、活动栏官网菜单、代理错误横幅 2 处健康检查链接全部改走 openExternal,桌面端可正常跳转 - 设置→外观 主题顺序调整为 深色/浅色/跟随系统 - release 二进制重编并验证(浏览器实测关于页链接可开文档页) - 附带工作区中未提交的扁平化重构现状(另一会话进行中) - homepage 落地页与文档终检通过(8787 / 与 /docs 双 200)
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package site
|
||
|
||
import (
|
||
"net/http"
|
||
"net/http/httptest"
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
func newTestRouter(t *testing.T) *gin.Engine {
|
||
t.Helper()
|
||
gin.SetMode(gin.TestMode)
|
||
r := gin.New()
|
||
New().Register(r)
|
||
return r
|
||
}
|
||
|
||
func TestSitePageRender(t *testing.T) {
|
||
r := newTestRouter(t)
|
||
for _, path := range []string{"/", "/home", "/index.html"} {
|
||
w := httptest.NewRecorder()
|
||
r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
|
||
if w.Code != http.StatusOK {
|
||
t.Fatalf("%s: expect 200, got %d", path, w.Code)
|
||
}
|
||
body := w.Body.String()
|
||
for _, want := range []string{
|
||
"<title>OpsxAPI", // 标题
|
||
`id="features"`, // 功能区
|
||
`id="pricing"`, // 定价区
|
||
"¥99", // 入门价
|
||
"¥8,000", // 企业档标价
|
||
"¥30,000", // 买断标价
|
||
"¥5,000–8,000", // 成交区间
|
||
"永久买断", // 买断 FAQ
|
||
"早鸟创始价", // 让利策略
|
||
"Socket.IO", // 协议覆盖
|
||
"hello@opsxapi.dev", // 联系方式
|
||
`href="/docs"`, // 文档互链
|
||
`href="/site/assets/site.css"`, // 样式资源
|
||
} {
|
||
if !strings.Contains(body, want) {
|
||
t.Fatalf("%s: missing %q", path, want)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestSiteAsset(t *testing.T) {
|
||
r := newTestRouter(t)
|
||
w := httptest.NewRecorder()
|
||
r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/site/assets/site.css", nil))
|
||
if w.Code != http.StatusOK || !strings.Contains(w.Header().Get("Content-Type"), "text/css") {
|
||
t.Fatalf("css: %d %s", w.Code, w.Header().Get("Content-Type"))
|
||
}
|
||
w = httptest.NewRecorder()
|
||
r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/site/assets/../template.html", nil))
|
||
if w.Code != http.StatusBadRequest && w.Code != http.StatusNotFound {
|
||
t.Fatalf("path traversal should be rejected, got %d", w.Code)
|
||
}
|
||
}
|