wui_button_test.go 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package wui_button
  2. import (
  3. "testing"
  4. mL0 "gitp78su.ipnodns.ru/svi/kern/v4/lev0"
  5. )
  6. type tester struct {
  7. t *testing.T
  8. chCall chan string
  9. }
  10. func TestWuiButton(t *testing.T) {
  11. sf := &tester{
  12. t: t,
  13. chCall: make(chan string, 2),
  14. }
  15. sf.new()
  16. }
  17. // Создание кнопки.
  18. func (sf *tester) new() {
  19. sf.t.Log("new")
  20. btn := NewWuiButton("test_val", sf.fnBack).Hassert("new()")
  21. if btn == nil {
  22. sf.t.Fatalf("new(): WuiButton==nil")
  23. }
  24. if txt := btn.Text(); txt == nil {
  25. sf.t.Fatalf("new(): IWuiText==nil")
  26. }
  27. if html := btn.Html(); html == "" {
  28. sf.t.Fatalf("new(): html is empty")
  29. }
  30. if hx := btn.Hx(); hx == nil {
  31. sf.t.Fatalf("new(): IWuiHx==nil")
  32. }
  33. btn.Click(map[string]string{}).Hassert("new()")
  34. if str := <-sf.chCall; str != "test" {
  35. sf.t.Fatalf("new(): bad called")
  36. }
  37. }
  38. // Функция обратного вызова.
  39. func (sf *tester) fnBack(dict map[string]string) *mL0.Result[string] {
  40. sf.chCall <- "test"
  41. return mL0.NewRes("test_click")
  42. }