summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context_test.go
blob: 3a0aa120af01fd99da65cdf3fb12ef5b961ad596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gui

import (
	"testing"

	"github.com/jesseduffield/gocui"
	"github.com/jesseduffield/lazygit/pkg/gui/types"
	"github.com/stretchr/testify/assert"
)

func TestCanDeactivatePopupContextsWithoutViews(t *testing.T) {
	contexts := []func(gui *Gui) types.Context{
		func(gui *Gui) types.Context { return gui.State.Contexts.Credentials },
		func(gui *Gui) types.Context { return gui.State.Contexts.Confirmation },
		func(gui *Gui) types.Context { return gui.State.Contexts.CommitMessage },
		func(gui *Gui) types.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)
}