Files
3x-ui/internal/sub/page_data_test.go
MHSanaei b0c1156dd6 fix(sub): drive display remarks from the template and split multi-host subpage links
Unify remark generation around the Remark Template. Display contexts (Clients-page QR/Info modals and the HTML sub info page) now render the template name-only client/identity part instead of a hardcoded fallback; the subscription body keeps the full template on a client first link and name-only thereafter. The default template gains the email token so the client email shows by default again (#5532).

BuildPageData now splits each multi-link entry (one link per host of an inbound) into a separate row, so the sub page no longer collapses several host links onto a single mangled line. QR captions on the Clients QR modal and the sub page reuse the link fragment remark.
2026-06-24 16:45:23 +02:00

38 lines
1.2 KiB
Go

package sub
import (
"reflect"
"strings"
"testing"
"github.com/mhsanaei/3x-ui/v3/internal/xray"
)
// A single getSubs entry can hold several links (one per host of an inbound)
// joined by newlines. BuildPageData must split them into one entry per link, with
// the email replicated, so the subpage renders one row per host instead of
// collapsing them onto a single mangled line.
func TestBuildPageData_SplitsMultiHostLinks(t *testing.T) {
s := &SubService{}
subs := []string{
"vless://a@h1:443?type=tcp#DE-john@x\nvless://a@h2:443?type=tcp#DE-john@x\nvless://a@h3:443?type=tcp#DE-john@x",
"vless://b@h:443?type=tcp#FR-alice@x",
}
emails := []string{"john@x", "alice@x"}
page := s.BuildPageData("s1", "", xray.ClientTraffic{}, 0, subs, emails, "", "", "", "/", "", "")
if len(page.Result) != 4 {
t.Fatalf("Result len = %d, want 4 (3 host links + 1 single link)", len(page.Result))
}
for i, link := range page.Result {
if strings.Contains(link, "\n") {
t.Fatalf("Result[%d] still multi-line: %q", i, link)
}
}
wantEmails := []string{"john@x", "john@x", "john@x", "alice@x"}
if !reflect.DeepEqual(page.Emails, wantEmails) {
t.Fatalf("Emails = %v, want %v", page.Emails, wantEmails)
}
}