1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/context_test.go
DerTeta 3e3151f86a Fix: Don't access a view if it's nil
The way the `if` expression in `deactivateContext` was composed,
it was possible to have it to evaluate to `true` even though the
`view` variable was `nil`.

As far as I can tell, this seems to be only possible during tests.
Nonetheless, I think the expression looks more "correct" this way.
2021-12-06 22:37:28 +11:00

41 lines
1.1 KiB
Go

package gui
import (
"testing"
"github.com/jesseduffield/gocui"
"github.com/stretchr/testify/assert"
)
func TestCanDeactivatePopupContextsWithoutViews(t *testing.T) {
contexts := []func(gui *Gui) Context {
func(gui *Gui) Context { return gui.State.Contexts.Credentials },
func(gui *Gui) Context { return gui.State.Contexts.Confirmation },
func(gui *Gui) Context { return gui.State.Contexts.CommitMessage },
func(gui *Gui) Context { return gui.State.Contexts.Search },
}
for _, c := range contexts {
gui := NewDummyGui()
context := c(gui)
gui.g = &gocui.Gui{}
gui.deactivateContext(context)
// This really only checks a prerequisit, not the effect of deactivateContext
view, _ := gui.g.View(context.GetViewName())
assert.Nil(t, view, string(context.GetKey()))
}
}
func TestCanDeactivateCommitFilesContextsWithoutViews(t *testing.T) {
gui := NewDummyGui()
gui.g = &gocui.Gui{}
gui.deactivateContext(gui.State.Contexts.CommitFiles)
// This really only checks a prerequisite, not the effect of deactivateContext
view, _ := gui.g.View(gui.State.Contexts.CommitFiles.GetViewName())
assert.Nil(t, view)
}