app_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package app
  2. import (
  3. "encoding/json"
  4. "strings"
  5. "testing"
  6. )
  7. func TestNewState(t *testing.T) {
  8. s := NewService()
  9. st := s.State()
  10. if st.Name != DefaultName || st.Dirty || st.SampleCount != 0 {
  11. t.Errorf("state %q dirty %v samples %d", st.Name, st.Dirty, st.SampleCount)
  12. }
  13. if len(st.Pads) != 128 || st.Pads[0].Label != "A01" || st.Pads[17].Label != "B02" || st.Pads[127].Label != "H16" {
  14. t.Fatalf("pads: %d", len(st.Pads))
  15. }
  16. for _, p := range st.Pads {
  17. if p.File != "" || p.HasNotes {
  18. t.Fatalf("pad %s not empty", p.Label)
  19. }
  20. }
  21. if st.SequenceCount != 1 || st.Sequences[0] != (Sequence{Slot: 0, Label: "A01", Name: "Sequence 01", BPM: 128, Bars: 2}) {
  22. t.Errorf("sequences %+v", st.Sequences)
  23. }
  24. if st.Limits.MaxMuteGroup != 16 || st.Limits.MinBPM != 20 || st.Limits.MaxBPM != 999 || st.Limits.MinCoarse != -24 {
  25. t.Errorf("limits %+v", st.Limits)
  26. }
  27. if st2 := s.New(); st2.Name != DefaultName || len(st2.Pads) != 128 {
  28. t.Error("New")
  29. }
  30. }
  31. func TestStateJSON(t *testing.T) {
  32. b, err := json.Marshal(NewService().State())
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. for _, key := range []string{`"name":"NewKit"`, `"pads":[{"slot":0,"label":"A01"`, `"sequences":[{"slot":0`, `"limits":{`, `"muteGroup":0`} {
  37. if !strings.Contains(string(b), key) {
  38. t.Errorf("JSON lacks %s", key)
  39. }
  40. }
  41. }
  42. func TestAbout(t *testing.T) {
  43. a := NewService().About()
  44. if a.Version != Version || !strings.Contains(a.License, "2026 bajdev") || !strings.HasPrefix(a.Repo, "https://") {
  45. t.Errorf("%+v", a)
  46. }
  47. }