Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
edaa60c13a | |||
631dc539f2 |
6
main.go
6
main.go
@ -294,7 +294,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.state = "Focus"
|
m.state = "Focus"
|
||||||
m.startCommands(m.onFocusStart)
|
m.startCommands(m.onFocusStart)
|
||||||
|
|
||||||
cmds = append(cmds, tick())
|
cmds = append(cmds, tea.SetWindowTitle(fmt.Sprintf("Gomodoro - %s", m.state)), tick())
|
||||||
|
|
||||||
case timeMsg:
|
case timeMsg:
|
||||||
// Handle timer update for each second
|
// Handle timer update for each second
|
||||||
@ -326,6 +326,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
// Run onFocusStart commands
|
// Run onFocusStart commands
|
||||||
m.startCommands(m.onFocusStart)
|
m.startCommands(m.onFocusStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmds = append(cmds, tea.SetWindowTitle(fmt.Sprintf("Gomodoro - %s", m.state)))
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds = append(cmds, tick())
|
cmds = append(cmds, tick())
|
||||||
@ -335,8 +337,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.height = msg.Height
|
m.height = msg.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds = append(cmds, tea.SetWindowTitle(fmt.Sprintf("Gomodoro - %s", m.state)))
|
|
||||||
|
|
||||||
// Get errors from shellrunner
|
// Get errors from shellrunner
|
||||||
for {
|
for {
|
||||||
result := m.shellrunner.GetResults()
|
result := m.shellrunner.GetResults()
|
||||||
|
65
main_test.go
65
main_test.go
@ -43,38 +43,7 @@ func assertNotEqual(t *testing.T, actual, expected interface{}, msg string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestParseDuration tests the parseDuration function
|
// keyMsgs converts a series of strings or KeyTypes into a slice of KeyMsgs
|
||||||
func TestParseDuration(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
input string
|
|
||||||
expected time.Duration
|
|
||||||
hasError bool
|
|
||||||
}{
|
|
||||||
{"10", 10 * time.Minute, false},
|
|
||||||
{"1h", 1 * time.Hour, false},
|
|
||||||
{"invalid", 0, true},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
result, err := parseDuration(test.input)
|
|
||||||
if test.hasError {
|
|
||||||
assertNotEqual(t, err, nil, "Expected an error for input "+test.input)
|
|
||||||
} else {
|
|
||||||
assertEqual(t, err, nil, "Did not expect an error for input "+test.input)
|
|
||||||
assertEqual(t, result, test.expected, "Expected duration for input "+test.input)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestRunCommands tests the runCommands function
|
|
||||||
func TestRunCommands(t *testing.T) {
|
|
||||||
m := newModelBasic(false, "#ffdd57", "#57ddff")
|
|
||||||
m.onFocusStart = []string{"echo Focus Start"}
|
|
||||||
|
|
||||||
m.Init()
|
|
||||||
m.startCommands(m.onFocusStart)
|
|
||||||
}
|
|
||||||
|
|
||||||
func keyMsgs(keys ...interface{}) []tea.KeyMsg {
|
func keyMsgs(keys ...interface{}) []tea.KeyMsg {
|
||||||
keyMessages := []tea.KeyMsg{}
|
keyMessages := []tea.KeyMsg{}
|
||||||
|
|
||||||
@ -239,6 +208,38 @@ func TestSendKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestParseDuration tests the parseDuration function
|
||||||
|
func TestParseDuration(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
expected time.Duration
|
||||||
|
hasError bool
|
||||||
|
}{
|
||||||
|
{"10", 10 * time.Minute, false},
|
||||||
|
{"1h", 1 * time.Hour, false},
|
||||||
|
{"invalid", 0, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
result, err := parseDuration(test.input)
|
||||||
|
if test.hasError {
|
||||||
|
assertNotEqual(t, err, nil, "Expected an error for input "+test.input)
|
||||||
|
} else {
|
||||||
|
assertEqual(t, err, nil, "Did not expect an error for input "+test.input)
|
||||||
|
assertEqual(t, result, test.expected, "Expected duration for input "+test.input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRunCommands tests the runCommands function
|
||||||
|
func TestRunCommands(t *testing.T) {
|
||||||
|
m := newModelBasic(false, "#ffdd57", "#57ddff")
|
||||||
|
m.onFocusStart = []string{"echo Focus Start"}
|
||||||
|
|
||||||
|
m.Init()
|
||||||
|
m.startCommands(m.onFocusStart)
|
||||||
|
}
|
||||||
|
|
||||||
// TestInputView tests the Update method of the model for the input view
|
// TestInputView tests the Update method of the model for the input view
|
||||||
func TestInputView(t *testing.T) {
|
func TestInputView(t *testing.T) {
|
||||||
m := newModel(false, "#ffdd57", "#57ddff", 0, 0, 0, []string{}, []string{}, []string{})
|
m := newModel(false, "#ffdd57", "#57ddff", 0, 0, 0, []string{}, []string{}, []string{})
|
||||||
|
Loading…
Reference in New Issue
Block a user