mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
While we try to keep the view's cursor position in sync with the context state's selectedLineIdx (at least when pressing up or down), there are enough situations where the two run out of sync; for example when initially opening the view, or after staging a hunk, or when scrolling the view using the wheel. While it would be possible to fix these situations to keep them always in sync, it doesn't seem worth it, because the view's cursor position isn't really used for anything else. So we rather special-case the SelectedLine/SelectedLineIdx functions of ViewDriver to query the context state's selectedLineIdx directly if it is a patch explorer context.
87 lines
2 KiB
Go
87 lines
2 KiB
Go
package components
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type fakeGuiDriver struct {
|
|
failureMessage string
|
|
pressedKeys []string
|
|
}
|
|
|
|
var _ integrationTypes.GuiDriver = &fakeGuiDriver{}
|
|
|
|
func (self *fakeGuiDriver) PressKey(key string) {
|
|
self.pressedKeys = append(self.pressedKeys, key)
|
|
}
|
|
|
|
func (self *fakeGuiDriver) Keys() config.KeybindingConfig {
|
|
return config.KeybindingConfig{}
|
|
}
|
|
|
|
func (self *fakeGuiDriver) CurrentContext() types.Context {
|
|
return nil
|
|
}
|
|
|
|
func (self *fakeGuiDriver) ContextForView(viewName string) types.Context {
|
|
return nil
|
|
}
|
|
|
|
func (self *fakeGuiDriver) Fail(message string) {
|
|
self.failureMessage = message
|
|
}
|
|
|
|
func (self *fakeGuiDriver) Log(message string) {
|
|
}
|
|
|
|
func (self *fakeGuiDriver) LogUI(message string) {
|
|
}
|
|
|
|
func (self *fakeGuiDriver) CheckedOutRef() *models.Branch {
|
|
return nil
|
|
}
|
|
|
|
func (self *fakeGuiDriver) MainView() *gocui.View {
|
|
return nil
|
|
}
|
|
|
|
func (self *fakeGuiDriver) SecondaryView() *gocui.View {
|
|
return nil
|
|
}
|
|
|
|
func (self *fakeGuiDriver) View(viewName string) *gocui.View {
|
|
return nil
|
|
}
|
|
|
|
func TestManualFailure(t *testing.T) {
|
|
test := NewIntegrationTest(NewIntegrationTestArgs{
|
|
Description: unitTestDescription,
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
|
t.Fail("blah")
|
|
},
|
|
})
|
|
driver := &fakeGuiDriver{}
|
|
test.Run(driver)
|
|
assert.Equal(t, "blah", driver.failureMessage)
|
|
}
|
|
|
|
func TestSuccess(t *testing.T) {
|
|
test := NewIntegrationTest(NewIntegrationTestArgs{
|
|
Description: unitTestDescription,
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
|
t.press("a")
|
|
t.press("b")
|
|
},
|
|
})
|
|
driver := &fakeGuiDriver{}
|
|
test.Run(driver)
|
|
assert.EqualValues(t, []string{"a", "b"}, driver.pressedKeys)
|
|
assert.Equal(t, "", driver.failureMessage)
|
|
}
|