2020-09-05 22:29:24 +00:00
|
|
|
package layout
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
tele "gopkg.in/tucnak/telebot.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLayout(t *testing.T) {
|
|
|
|
os.Setenv("TOKEN", "TEST")
|
|
|
|
|
|
|
|
lt, err := New("example.yml")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
pref := lt.Settings()
|
|
|
|
assert.Equal(t, "TEST", pref.Token)
|
|
|
|
assert.Equal(t, "html", pref.ParseMode)
|
|
|
|
assert.Equal(t, &tele.LongPoller{}, pref.Poller)
|
|
|
|
|
2020-10-08 19:37:57 +00:00
|
|
|
assert.Equal(t, "string", lt.String("str"))
|
2020-09-05 22:29:24 +00:00
|
|
|
assert.Equal(t, 123, lt.Int("num"))
|
|
|
|
assert.Equal(t, int64(123), lt.Int64("num"))
|
|
|
|
assert.Equal(t, float64(123), lt.Float("num"))
|
|
|
|
assert.Equal(t, 10*time.Minute, lt.Duration("dur"))
|
|
|
|
|
2021-07-25 11:15:42 +00:00
|
|
|
assert.Equal(t, &tele.Btn{
|
|
|
|
Unique: "pay",
|
|
|
|
Text: "Pay",
|
|
|
|
Data: "1|100.00|USD",
|
|
|
|
}, lt.ButtonLocale("en", "pay", struct {
|
|
|
|
UserID int
|
|
|
|
Amount string
|
|
|
|
Currency string
|
|
|
|
}{
|
|
|
|
UserID: 1,
|
|
|
|
Amount: "100.00",
|
|
|
|
Currency: "USD",
|
|
|
|
}))
|
|
|
|
|
2020-09-05 22:29:24 +00:00
|
|
|
assert.Equal(t, &tele.ReplyMarkup{
|
|
|
|
ReplyKeyboard: [][]tele.ReplyButton{
|
|
|
|
{{Text: "Help"}},
|
|
|
|
{{Text: "Settings"}},
|
|
|
|
},
|
2020-09-26 15:48:49 +00:00
|
|
|
ResizeKeyboard: true,
|
2020-10-22 13:14:30 +00:00
|
|
|
}, lt.MarkupLocale("en", "reply_shortened"))
|
2020-09-26 15:48:49 +00:00
|
|
|
|
|
|
|
assert.Equal(t, &tele.ReplyMarkup{
|
|
|
|
ReplyKeyboard: [][]tele.ReplyButton{{{Text: "Send a contact", Contact: true}}},
|
|
|
|
ResizeKeyboard: true,
|
|
|
|
OneTimeKeyboard: true,
|
2020-10-22 13:14:30 +00:00
|
|
|
}, lt.MarkupLocale("en", "reply_extended"))
|
2020-09-05 22:29:24 +00:00
|
|
|
|
|
|
|
assert.Equal(t, &tele.ReplyMarkup{
|
2020-09-26 15:48:49 +00:00
|
|
|
InlineKeyboard: [][]tele.InlineButton{{{Unique: "stop", Text: "Stop", Data: "1"}}},
|
2020-10-22 13:14:30 +00:00
|
|
|
}, lt.MarkupLocale("en", "inline", 1))
|
2021-07-07 10:16:38 +00:00
|
|
|
|
2021-07-25 11:15:42 +00:00
|
|
|
assert.Equal(t, &tele.ArticleResult{
|
|
|
|
ResultBase: tele.ResultBase{
|
|
|
|
ID: "1853",
|
|
|
|
Type: "article",
|
|
|
|
},
|
|
|
|
Title: "Some title",
|
|
|
|
Description: "Some description",
|
|
|
|
Text: "The text of the article",
|
|
|
|
ThumbURL: "https://preview.picture",
|
|
|
|
}, lt.ResultLocale("en", "article", struct {
|
|
|
|
ID int
|
|
|
|
Title string
|
|
|
|
Description string
|
|
|
|
Content string
|
|
|
|
PreviewURL string
|
2021-07-07 10:16:38 +00:00
|
|
|
}{
|
2021-07-25 11:15:42 +00:00
|
|
|
ID: 1853,
|
|
|
|
Title: "Some title",
|
|
|
|
Description: "Some description",
|
|
|
|
Content: "The text of the article",
|
|
|
|
PreviewURL: "https://preview.picture",
|
2021-07-07 10:16:38 +00:00
|
|
|
}))
|
2020-09-05 22:29:24 +00:00
|
|
|
}
|