page_data_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package sub
  2. import (
  3. "reflect"
  4. "strings"
  5. "testing"
  6. "github.com/mhsanaei/3x-ui/v3/internal/xray"
  7. )
  8. // A single getSubs entry can hold several links (one per host of an inbound)
  9. // joined by newlines. BuildPageData must split them into one entry per link, with
  10. // the email replicated, so the subpage renders one row per host instead of
  11. // collapsing them onto a single mangled line.
  12. func TestBuildPageData_SplitsMultiHostLinks(t *testing.T) {
  13. s := &SubService{}
  14. subs := []string{
  15. "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",
  16. "vless://b@h:443?type=tcp#FR-alice@x",
  17. }
  18. emails := []string{"john@x", "alice@x"}
  19. page := s.BuildPageData("s1", "", xray.ClientTraffic{}, 0, subs, emails, "", "", "", "/", "", "")
  20. if len(page.Result) != 4 {
  21. t.Fatalf("Result len = %d, want 4 (3 host links + 1 single link)", len(page.Result))
  22. }
  23. for i, link := range page.Result {
  24. if strings.Contains(link, "\n") {
  25. t.Fatalf("Result[%d] still multi-line: %q", i, link)
  26. }
  27. }
  28. wantEmails := []string{"john@x", "john@x", "john@x", "alice@x"}
  29. if !reflect.DeepEqual(page.Emails, wantEmails) {
  30. t.Fatalf("Emails = %v, want %v", page.Emails, wantEmails)
  31. }
  32. }