@@ -5,6 +5,87 @@ import (
55 "testing"
66)
77
8+ func TestNewOnetimeKeyboard (t * testing.T ) {
9+ tests := []struct {
10+ name string
11+ buttons [][]Button
12+ want * MessageKeyboard
13+ }{
14+ {
15+ name : "Empty onetime keyboard" ,
16+ buttons : [][]Button {},
17+ want : & MessageKeyboard {
18+ kbType : KeyboardTypeBottom ,
19+ isOneTime : true ,
20+ Buttons : [][]Button {},
21+ },
22+ },
23+ {
24+ name : "Onetime keyboard with one row of data buttons" ,
25+ buttons : [][]Button {
26+ {
27+ & DataButton {Text : "Button 1" , Data : "data1" },
28+ & DataButton {Text : "Button 2" , Data : "data2" },
29+ },
30+ },
31+ want : & MessageKeyboard {
32+ kbType : KeyboardTypeBottom ,
33+ isOneTime : true ,
34+ Buttons : [][]Button {
35+ {
36+ & DataButton {Text : "Button 1" , Data : "data1" },
37+ & DataButton {Text : "Button 2" , Data : "data2" },
38+ },
39+ },
40+ },
41+ },
42+ {
43+ name : "Onetime keyboard with multiple rows of mixed buttons" ,
44+ buttons : [][]Button {
45+ {
46+ & DataButton {Text : "Button 1" , Data : "data1" },
47+ & UrlButton {Text : "URL 1" , URL : "https://example.com" },
48+ },
49+ {
50+ & DataButton {Text : "Button 2" , Data : "data2" },
51+ },
52+ },
53+ want : & MessageKeyboard {
54+ kbType : KeyboardTypeBottom ,
55+ isOneTime : true ,
56+ Buttons : [][]Button {
57+ {
58+ & DataButton {Text : "Button 1" , Data : "data1" },
59+ & UrlButton {Text : "URL 1" , URL : "https://example.com" },
60+ },
61+ {
62+ & DataButton {Text : "Button 2" , Data : "data2" },
63+ },
64+ },
65+ },
66+ },
67+ }
68+
69+ for _ , tt := range tests {
70+ t .Run (tt .name , func (t * testing.T ) {
71+ got := NewOnetimeKeyboard (tt .buttons ... )
72+ if ! reflect .DeepEqual (got , tt .want ) {
73+ t .Errorf ("NewOnetimeKeyboard() = %v, want %v" , got , tt .want )
74+ }
75+
76+ // Test the KeyboardType method
77+ if got .KeyboardType () != KeyboardTypeBottom {
78+ t .Errorf ("MessageKeyboard.KeyboardType() = %v, want %v" , got .KeyboardType (), KeyboardTypeBottom )
79+ }
80+
81+ // Test the IsOneTime method
82+ if ! got .IsOneTime () {
83+ t .Errorf ("MessageKeyboard.IsOneTime() = %v, want true" , got .IsOneTime ())
84+ }
85+ })
86+ }
87+ }
88+
889func TestNewMessageKeyboard (t * testing.T ) {
990 tests := []struct {
1091 name string
0 commit comments