wbutton_test.go 844 B

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