diff --git a/internal/rpc/convert_markup_test.go b/internal/rpc/convert_markup_test.go index 0757a3af..d2636264 100644 --- a/internal/rpc/convert_markup_test.go +++ b/internal/rpc/convert_markup_test.go @@ -9,6 +9,11 @@ import ( ) func TestReplyKeyboardTLDomainRoundTrip(t *testing.T) { + statusButton := tg.KeyboardButton{Text: "Status"} + style := tg.KeyboardButtonStyle{} + style.SetBgPrimary(true) + style.SetIcon(123456) + statusButton.SetStyle(style) in := &tg.ReplyKeyboardMarkup{ Resize: true, SingleUse: true, @@ -16,15 +21,8 @@ func TestReplyKeyboardTLDomainRoundTrip(t *testing.T) { Persistent: true, Placeholder: "Choose", Rows: []tg.KeyboardButtonRow{{Buttons: []tg.KeyboardButton{ - {Text: "Help", Type: &tg.ButtonTypeDefault{}}, - func() tg.KeyboardButton { - button := tg.KeyboardButton{Text: "Status", Type: &tg.ButtonTypeDefault{}} - style := tg.KeyboardButtonStyle{} - style.SetBgPrimary(true) - style.SetIcon(123456) - button.SetStyle(style) - return button - }(), + {Text: "Help"}, + statusButton, }}}, } got, err := domainOutgoingReplyMarkupForSender(in, true) @@ -43,9 +41,9 @@ func TestReplyKeyboardTLDomainRoundTrip(t *testing.T) { if !ok || len(wire.Rows) != 1 || len(wire.Rows[0].Buttons) != 2 { t.Fatalf("wire markup = %#v", wire) } - button := &wire.Rows[0].Buttons[1] + button := wire.Rows[0].Buttons[1] if button.Text != "Status" { - t.Fatalf("second button = %#v", wire.Rows[0].Buttons[1]) + t.Fatalf("second button = %#v", button) } else if style, ok := button.GetStyle(); !ok || !style.GetBgPrimary() || style.Icon != 123456 { t.Fatalf("second button style = %#v ok=%v", style, ok) } @@ -70,12 +68,13 @@ func TestInlineButtonStyleTLDomainRoundTrip(t *testing.T) { if roundTrip, ok := wire.GetStyle(); !ok || !roundTrip.GetBgDanger() { t.Fatalf("wire style = %#v ok=%v", roundTrip, ok) } + if _, ok := wire.Type.(*tg.InlineButtonTypeCallback); !ok { + t.Fatalf("wire type = %#v", wire.Type) + } } func TestLoginURLButtonTLDomainProjection(t *testing.T) { - buttonType := &tg.InputInlineButtonTypeURLAuth{ - URL: "https://example.com/login", Bot: &tg.InputUser{UserID: 9001, AccessHash: 77}, - } + buttonType := &tg.InputInlineButtonTypeURLAuth{URL: "https://example.com/login", Bot: &tg.InputUser{UserID: 9001, AccessHash: 77}} buttonType.SetRequestWriteAccess(true) buttonType.SetFwdText("Open login") button := tg.KeyboardInlineButton{Text: "Log in", Type: buttonType} @@ -180,10 +179,13 @@ func TestReplyKeyboardRequestPeerFiltersTLDomainRoundTrip(t *testing.T) { } func TestInputRequestPeerButtonPreservesRequestedMetadata(t *testing.T) { - button := tg.KeyboardButton{Text: "Share", Type: &tg.InputButtonTypeRequestPeer{ - NameRequested: true, UsernameRequested: true, PhotoRequested: true, - ButtonID: 99, PeerType: &tg.RequestPeerTypeUser{}, MaxQuantity: 3, - }} + button := tg.KeyboardButton{ + Text: "Share", + Type: &tg.InputButtonTypeRequestPeer{ + NameRequested: true, UsernameRequested: true, PhotoRequested: true, + ButtonID: 99, PeerType: &tg.RequestPeerTypeUser{}, MaxQuantity: 3, + }, + } got, err := domainRequestedButtonFromTG(1001, nil, button) if err != nil { t.Fatal(err)