75 lines
3.2 KiB
Go
75 lines
3.2 KiB
Go
package configser
|
|
|
|
import "testing"
|
|
|
|
func TestBuildAppConfigVMMapsSiteAdSlots(t *testing.T) {
|
|
vm := BuildAppConfigVM(&ConfigInfoResp{
|
|
Advitise: AdvitiseData{
|
|
DialogList: []Advertisement{{ID: "dialog", Images: "https://cdn.example.com/dialog.gif"}},
|
|
NineGridList: []Advertisement{{ID: "grid", Images: "https://cdn.example.com/grid.gif"}, {ID: "grid-empty", Images: " "}},
|
|
VideoTopList: []Advertisement{
|
|
{ID: " top ", Images: " https://cdn.example.com/top.gif ", Link: " https://example.com/top "},
|
|
{ID: "top-empty", Images: " "},
|
|
},
|
|
DetailBannerList: []Advertisement{{ID: "legacy-banner", Images: "https://cdn.example.com/legacy.gif"}},
|
|
AppInfoAList: []Advertisement{{ID: "a", Images: "https://cdn.example.com/a.gif"}},
|
|
AList: []Advertisement{{ID: "legacy-a", Images: "https://cdn.example.com/legacy-a.gif"}},
|
|
BList: []Advertisement{{ID: "b", Images: "https://cdn.example.com/b.gif"}},
|
|
},
|
|
})
|
|
|
|
if len(vm.DialogList) != 1 || vm.DialogList[0].ID != "dialog" {
|
|
t.Fatalf("DialogList = %#v", vm.DialogList)
|
|
}
|
|
if len(vm.NineGridList) != 1 || vm.NineGridList[0].ID != "grid" {
|
|
t.Fatalf("NineGridList = %#v, want images-only items", vm.NineGridList)
|
|
}
|
|
// 详情横幅优先本站后台字段 videoTopList,并清洗空格 / 过滤无图
|
|
if len(vm.DetailBannerList) != 1 || vm.DetailBannerList[0].ID != "top" || vm.DetailBannerList[0].Link != "https://example.com/top" {
|
|
t.Fatalf("DetailBannerList = %#v", vm.DetailBannerList)
|
|
}
|
|
// 播放页小图标优先 appInfoAList;首页小图标无 appInfoBList 时回退 BList
|
|
if len(vm.AList) != 1 || vm.AList[0].ID != "a" {
|
|
t.Fatalf("AList = %#v", vm.AList)
|
|
}
|
|
if len(vm.BList) != 1 || vm.BList[0].ID != "b" {
|
|
t.Fatalf("BList = %#v", vm.BList)
|
|
}
|
|
}
|
|
|
|
func TestBuildAppConfigVMFallsBackToLegacyBannerField(t *testing.T) {
|
|
vm := BuildAppConfigVM(&ConfigInfoResp{
|
|
Advitise: AdvitiseData{DetailBannerList: []Advertisement{{ID: "banner", Images: "https://cdn.example.com/banner.gif"}}},
|
|
})
|
|
if len(vm.DetailBannerList) != 1 || vm.DetailBannerList[0].ID != "banner" {
|
|
t.Fatalf("DetailBannerList = %#v, want detailbannerList fallback", vm.DetailBannerList)
|
|
}
|
|
}
|
|
|
|
func TestBuildAppConfigVMParsesAdsClickID(t *testing.T) {
|
|
vm := BuildAppConfigVM(&ConfigInfoResp{
|
|
Advitise: AdvitiseData{
|
|
NineGridList: []Advertisement{
|
|
{ID: " 1138200002 ", Location: 2, Images: "https://cdn.example.com/a.gif"},
|
|
{ID: "1138200003", Location: 2, AdvertiseCode: "code-x", Images: "https://cdn.example.com/b.gif"},
|
|
{ID: "abc", Location: 2, Images: "https://cdn.example.com/c.gif"},
|
|
{ID: "1138200004", Location: 0, Images: "https://cdn.example.com/d.gif"},
|
|
},
|
|
},
|
|
})
|
|
got := vm.NineGridList
|
|
if len(got) != 4 {
|
|
t.Fatalf("NineGridList = %#v", got)
|
|
}
|
|
if got[0].AdsID != 1138200002 || !got[0].CanReportClick() {
|
|
t.Fatalf("item0 = %#v, want reportable id 1138200002", got[0])
|
|
}
|
|
// advertiseCode 覆盖展示 ID,但点击上报仍用上游原始 id
|
|
if got[1].ID != "code-x" || got[1].AdsID != 1138200003 {
|
|
t.Fatalf("item1 = %#v, want AdsID from raw id", got[1])
|
|
}
|
|
if got[2].CanReportClick() || got[3].CanReportClick() {
|
|
t.Fatalf("invalid id/location must not report: %#v %#v", got[2], got[3])
|
|
}
|
|
}
|