-
Notifications
You must be signed in to change notification settings - Fork 469
/
markup_test.go
65 lines (52 loc) · 1.96 KB
/
markup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package telebot
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBtn(t *testing.T) {
r := &ReplyMarkup{}
assert.Equal(t, &ReplyButton{Text: "T"}, r.Text("T").Reply())
assert.Equal(t, &ReplyButton{Text: "T", Contact: true}, r.Contact("T").Reply())
assert.Equal(t, &ReplyButton{Text: "T", Location: true}, r.Location("T").Reply())
assert.Equal(t, &ReplyButton{Text: "T", Poll: PollAny}, r.Poll("T", PollAny).Reply())
assert.Nil(t, r.Data("T", "u").Reply())
assert.Equal(t, &InlineButton{Unique: "u", Text: "T"}, r.Data("T", "u").Inline())
assert.Equal(t, &InlineButton{Unique: "u", Text: "T", Data: "1|2"}, r.Data("T", "u", "1", "2").Inline())
assert.Equal(t, &InlineButton{Text: "T", URL: "url"}, r.URL("T", "url").Inline())
assert.Equal(t, &InlineButton{Text: "T", InlineQuery: "q"}, r.Query("T", "q").Inline())
assert.Equal(t, &InlineButton{Text: "T", InlineQueryChat: "q"}, r.QueryChat("T", "q").Inline())
assert.Equal(t, &InlineButton{Text: "T", Login: &Login{Text: "T"}}, r.Login("T", &Login{Text: "T"}).Inline())
assert.Equal(t, &InlineButton{Text: "T", WebApp: &WebApp{URL: "url"}}, r.WebApp("T", &WebApp{URL: "url"}).Inline())
}
func TestOptions(t *testing.T) {
r := &ReplyMarkup{}
r.Reply(
r.Row(r.Text("Menu")),
r.Row(r.Text("Settings")),
)
assert.Equal(t, [][]ReplyButton{
{{Text: "Menu"}},
{{Text: "Settings"}},
}, r.ReplyKeyboard)
i := &ReplyMarkup{}
i.Inline(i.Row(
i.Data("Previous", "prev"),
i.Data("Next", "next"),
))
assert.Equal(t, [][]InlineButton{{
{Unique: "prev", Text: "Previous"},
{Unique: "next", Text: "Next"},
}}, i.InlineKeyboard)
assert.Panics(t, func() {
r.Reply(r.Row(r.Data("T", "u")))
i.Inline(i.Row(i.Text("T")))
})
assert.Equal(t, r.copy(), r)
assert.Equal(t, i.copy(), i)
o := &SendOptions{ReplyMarkup: r}
assert.Equal(t, o.copy(), o)
data, err := PollQuiz.MarshalJSON()
require.NoError(t, err)
assert.Equal(t, []byte(`{"type":"quiz"}`), data)
}