广告添加
This commit is contained in:
@@ -18,8 +18,7 @@ func TestBuildAppConfigVMIncludesValidAdvertisements(t *testing.T) {
|
||||
NewAddressInfo: NewAddressInfo{Telegram: " https://t.me/business ", QQ: " 2168045324 ", OfficialAppAddr: " https://app.example.com/download\\ "},
|
||||
Config: ConfigInfo{PotaoGroup: " https://potato.example.com/group\\ "},
|
||||
Advitise: AdvitiseData{
|
||||
HomeList: []Advertisement{{ID: "home", Images: "https://cdn.example.com/home.gif"}},
|
||||
DetailTopList: []Advertisement{{ID: "top", Images: " https://cdn.example.com/top.gif "}},
|
||||
HomeList: []Advertisement{{ID: "home", Images: "https://cdn.example.com/home.gif"}},
|
||||
NineGridList: []Advertisement{
|
||||
{ID: "banner-1", Images: "https://cdn.example.com/banner-1.gif"},
|
||||
{ID: "banner-empty", Images: " "},
|
||||
@@ -27,10 +26,13 @@ func TestBuildAppConfigVMIncludesValidAdvertisements(t *testing.T) {
|
||||
{ID: "banner-3", Images: "https://cdn.example.com/banner-3.gif"},
|
||||
},
|
||||
DetailBannerList: []Advertisement{{ID: "detail", Images: "https://cdn.example.com/detail.gif"}},
|
||||
BottomBanner: []Advertisement{
|
||||
{ID: " bottom ", Images: " https://cdn.example.com/bottom.gif ", Link: " https://example.com/bottom "},
|
||||
{ID: "bottom-empty", Images: " "},
|
||||
VideoTopList: []Advertisement{
|
||||
{ID: " video-top ", Images: " https://cdn.example.com/video-top.gif ", Link: " https://example.com/top "},
|
||||
{ID: "video-top-empty", Images: " "},
|
||||
},
|
||||
AList: []Advertisement{{ID: "a-legacy", Images: "https://cdn.example.com/a.gif"}},
|
||||
AppInfoAList: []Advertisement{{ID: "a", Images: "https://cdn.example.com/app-a.gif"}},
|
||||
BList: []Advertisement{{ID: "b", Images: "https://cdn.example.com/b.gif"}},
|
||||
DialogList: []Advertisement{
|
||||
{ID: " 1 ", Images: " https://cdn.example.com/ad.webp\\ ", Link: " https://example.com ", Title: " 广告一 "},
|
||||
{ID: "2", Images: " ", Title: "无图广告"},
|
||||
@@ -56,17 +58,19 @@ func TestBuildAppConfigVMIncludesValidAdvertisements(t *testing.T) {
|
||||
if len(vm.Advitise.NineGridList) != 4 {
|
||||
t.Fatalf("Advitise.NineGridList length = %d, want raw length 4", len(vm.Advitise.NineGridList))
|
||||
}
|
||||
if len(vm.DetailTopList) != 1 || vm.DetailTopList[0].ID != "top" {
|
||||
t.Fatalf("DetailTopList = %#v", vm.DetailTopList)
|
||||
}
|
||||
if len(vm.NineGridList) != 3 {
|
||||
t.Fatalf("NineGridList length = %d, want 3", len(vm.NineGridList))
|
||||
}
|
||||
if len(vm.DetailBannerList) != 1 || vm.DetailBannerList[0].ID != "detail" {
|
||||
// 详情横幅优先 videoTopList(本站后台字段),无效图片被过滤
|
||||
if len(vm.DetailBannerList) != 1 || vm.DetailBannerList[0].ID != "video-top" || vm.DetailBannerList[0].Images != "https://cdn.example.com/video-top.gif" {
|
||||
t.Fatalf("DetailBannerList = %#v", vm.DetailBannerList)
|
||||
}
|
||||
if len(vm.BottomBanner) != 1 || vm.BottomBanner[0].ID != "bottom" || vm.BottomBanner[0].Images != "https://cdn.example.com/bottom.gif" {
|
||||
t.Fatalf("BottomBanner = %#v", vm.BottomBanner)
|
||||
// 播放页小图标优先 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)
|
||||
}
|
||||
if len(vm.DialogList) != 1 {
|
||||
t.Fatalf("DialogList length = %d, want 1", len(vm.DialogList))
|
||||
@@ -77,15 +81,26 @@ func TestBuildAppConfigVMIncludesValidAdvertisements(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNineGridRowReturnsTwoItemsPerRow(t *testing.T) {
|
||||
cfg := AppConfigVM{NineGridList: []Advertisement{{ID: "1"}, {ID: "2"}, {ID: "3"}}}
|
||||
if got := cfg.NineGridRow(0); len(got) != 2 || got[0].ID != "1" || got[1].ID != "2" {
|
||||
t.Fatalf("NineGridRow(0) = %#v", got)
|
||||
func TestAdvertisementClickTrackable(t *testing.T) {
|
||||
cases := []struct {
|
||||
ad Advertisement
|
||||
wantID int64
|
||||
trackable bool
|
||||
}{
|
||||
{Advertisement{ID: "1138200002", Location: 2}, 1138200002, true},
|
||||
{Advertisement{ID: " 1138200012 ", Location: 12}, 1138200012, true},
|
||||
{Advertisement{ID: "1138200003", Location: 0}, 1138200003, false},
|
||||
{Advertisement{ID: "", Location: 3}, 0, false},
|
||||
{Advertisement{ID: "0", Location: 3}, 0, false},
|
||||
{Advertisement{ID: "-5", Location: 3}, 0, false},
|
||||
{Advertisement{ID: "abc", Location: 3}, 0, false},
|
||||
}
|
||||
if got := cfg.NineGridRow(1); len(got) != 1 || got[0].ID != "3" {
|
||||
t.Fatalf("NineGridRow(1) = %#v", got)
|
||||
}
|
||||
if got := cfg.NineGridRow(2); len(got) != 0 {
|
||||
t.Fatalf("NineGridRow(2) = %#v, want empty", got)
|
||||
for _, tc := range cases {
|
||||
if got := tc.ad.ClickID(); got != tc.wantID {
|
||||
t.Fatalf("ClickID(%q) = %d, want %d", tc.ad.ID, got, tc.wantID)
|
||||
}
|
||||
if got := tc.ad.ClickTrackable(); got != tc.trackable {
|
||||
t.Fatalf("ClickTrackable(%q, %d) = %v, want %v", tc.ad.ID, tc.ad.Location, got, tc.trackable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user