@@ -0,0 +1,40 @@
|
||||
package configser
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBuildHomeRoadPageVMUsesDynamicConfig(t *testing.T) {
|
||||
cfg := AppConfigVM{
|
||||
NewURLAddr: "https://main.example.com",
|
||||
NewURLAddr1: "https://relay.example.com",
|
||||
NewURLAddr2: "https://latest.example.com",
|
||||
ForeverURLAddr: "https://forever.example.com",
|
||||
PDFAddr: "https://publish.example.com",
|
||||
GmailAddr: "home@example.com",
|
||||
TGGroup: "https://t.me/example",
|
||||
Telegram: "https://t.me/business-example",
|
||||
CustomerServiceHost: "https://service.example.com",
|
||||
TwitterAddr: "https://x.com/example",
|
||||
NavPageList: []NavPageItem{
|
||||
{Line: 1, URL: "https://line1.example.com"},
|
||||
{Line: 2, URL: "https://line2.example.com"},
|
||||
{Line: 3, URL: "https://line3.example.com"},
|
||||
},
|
||||
}
|
||||
vm := BuildHomeRoadPageVM(cfg)
|
||||
if vm.MainURL != cfg.NewURLAddr || len(vm.Routes) != 3 || vm.Routes[1].URL != "https://line2.example.com" {
|
||||
t.Fatalf("unexpected route VM: %#v", vm)
|
||||
}
|
||||
if len(vm.Permanent) != 3 || vm.Permanent[1].URL != cfg.NewURLAddr || vm.Permanent[2].URL != cfg.NewURLAddr1 {
|
||||
t.Fatalf("unexpected permanent links: %#v", vm.Permanent)
|
||||
}
|
||||
if len(vm.Contacts) != 4 || vm.Contacts[0].URL != "mailto:home@example.com" || vm.Contacts[2].URL != cfg.Telegram {
|
||||
t.Fatalf("unexpected contacts: %#v", vm.Contacts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildHomeRoadPageVMSkipsEmptyPermanentAddresses(t *testing.T) {
|
||||
vm := BuildHomeRoadPageVM(AppConfigVM{NewURLAddr: "https://relay.example.com"})
|
||||
if len(vm.Permanent) != 1 || vm.Permanent[0].Label != "永久中转页" {
|
||||
t.Fatalf("unexpected permanent links: %#v", vm.Permanent)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user