mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #717 from hemu/add-view-tests
Add keyboard widget tests
This commit is contained in:
commit
dd4438d4a9
@ -51,7 +51,7 @@ func newTestGraph(graphStars int, graphIcon string) *BarGraph {
|
|||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewBarGraph(t *testing.T) {
|
func Test_NewBarGraph(t *testing.T) {
|
||||||
widget := newTestGraph(15, "|")
|
widget := newTestGraph(15, "|")
|
||||||
|
|
||||||
assert.NotNil(t, widget.View)
|
assert.NotNil(t, widget.View)
|
||||||
@ -59,7 +59,7 @@ func TestNewBarGraph(t *testing.T) {
|
|||||||
assert.Equal(t, "|", widget.starChar)
|
assert.Equal(t, "|", widget.starChar)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildBars(t *testing.T) {
|
func Test_BuildBars(t *testing.T) {
|
||||||
widget := newTestGraph(15, "|")
|
widget := newTestGraph(15, "|")
|
||||||
|
|
||||||
before := widget.View.GetText(false)
|
before := widget.View.GetText(false)
|
||||||
@ -69,13 +69,13 @@ func TestBuildBars(t *testing.T) {
|
|||||||
assert.NotEqual(t, before, after)
|
assert.NotEqual(t, before, after)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTextView(t *testing.T) {
|
func Test_TextView(t *testing.T) {
|
||||||
widget := newTestGraph(15, "|")
|
widget := newTestGraph(15, "|")
|
||||||
|
|
||||||
assert.NotNil(t, widget.TextView())
|
assert.NotNil(t, widget.TextView())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildStars(t *testing.T) {
|
func Test_BuildStars(t *testing.T) {
|
||||||
result := BuildStars(makeData(), 20, "*")
|
result := BuildStars(makeData(), 20, "*")
|
||||||
assert.Equal(t,
|
assert.Equal(t,
|
||||||
"Jun 27, 2018[[default]****[default] ] 20\nJul 09, 2018[[red]****************[default] ] 80\nJul 09, 2018[[green]****************[default] ] 80\n",
|
"Jun 27, 2018[[default]****[default] ] 20\nJul 09, 2018[[red]****************[default] ] 80\nJul 09, 2018[[green]****************[default] ] 80\n",
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func test() {}
|
func test() {}
|
||||||
@ -13,7 +15,12 @@ func testKeyboardWidget() KeyboardWidget {
|
|||||||
keyWid := NewKeyboardWidget(
|
keyWid := NewKeyboardWidget(
|
||||||
tview.NewApplication(),
|
tview.NewApplication(),
|
||||||
tview.NewPages(),
|
tview.NewPages(),
|
||||||
nil,
|
&cfg.Common{
|
||||||
|
Module: cfg.Module{
|
||||||
|
Name: "testWidget",
|
||||||
|
Type: "testType",
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
return keyWid
|
return keyWid
|
||||||
}
|
}
|
||||||
@ -128,7 +135,7 @@ func Test_InputCapture(t *testing.T) {
|
|||||||
expected: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
|
expected: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with defined event",
|
name: "with defined event and char handler",
|
||||||
before: func(keyWid KeyboardWidget) KeyboardWidget {
|
before: func(keyWid KeyboardWidget) KeyboardWidget {
|
||||||
keyWid.SetKeyboardChar("a", test, "help")
|
keyWid.SetKeyboardChar("a", test, "help")
|
||||||
return keyWid
|
return keyWid
|
||||||
@ -136,6 +143,15 @@ func Test_InputCapture(t *testing.T) {
|
|||||||
event: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
|
event: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
|
||||||
expected: nil,
|
expected: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with defined event and key handler",
|
||||||
|
before: func(keyWid KeyboardWidget) KeyboardWidget {
|
||||||
|
keyWid.SetKeyboardKey(tcell.KeyRune, test, "help")
|
||||||
|
return keyWid
|
||||||
|
},
|
||||||
|
event: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -157,3 +173,43 @@ func Test_InputCapture(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_InitializeCommonControls(t *testing.T) {
|
||||||
|
t.Run("nil refreshFunc", func(t *testing.T) {
|
||||||
|
keyWid := testKeyboardWidget()
|
||||||
|
keyWid.InitializeCommonControls(nil)
|
||||||
|
|
||||||
|
assert.NotNil(t, keyWid.charMap["/"])
|
||||||
|
assert.Nil(t, keyWid.charMap["r"])
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("non-nil refreshFunc", func(t *testing.T) {
|
||||||
|
keyWid := testKeyboardWidget()
|
||||||
|
keyWid.InitializeCommonControls(func() {})
|
||||||
|
|
||||||
|
assert.NotNil(t, keyWid.charMap["r"])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_HelpText(t *testing.T) {
|
||||||
|
keyWid := testKeyboardWidget()
|
||||||
|
keyWid.SetKeyboardChar("a", test, "a help")
|
||||||
|
keyWid.SetKeyboardKey(tcell.KeyCtrlO, test, "keyCtrlO help")
|
||||||
|
|
||||||
|
assert.NotNil(t, keyWid.HelpText())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_SetView(t *testing.T) {
|
||||||
|
keyWid := testKeyboardWidget()
|
||||||
|
assert.Nil(t, keyWid.view)
|
||||||
|
|
||||||
|
view := &tview.TextView{}
|
||||||
|
keyWid.SetView(view)
|
||||||
|
assert.Equal(t, view, keyWid.view)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_ShowHelp(t *testing.T) {
|
||||||
|
keyWid := testKeyboardWidget()
|
||||||
|
|
||||||
|
assert.NotPanics(t, func() { keyWid.ShowHelp() })
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user