2022-08-13 05:50:38 +02:00
|
|
|
package components
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-14 12:13:39 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
2022-08-13 05:50:38 +02:00
|
|
|
"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) 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
|
|
|
|
}
|
|
|
|
|
2022-08-14 12:13:39 +02:00
|
|
|
func (self *fakeGuiDriver) MainView() *gocui.View {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *fakeGuiDriver) SecondaryView() *gocui.View {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-10 06:11:05 +02:00
|
|
|
func (self *fakeGuiDriver) View(viewName string) *gocui.View {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-13 05:50:38 +02:00
|
|
|
func TestManualFailure(t *testing.T) {
|
|
|
|
test := NewIntegrationTest(NewIntegrationTestArgs{
|
|
|
|
Description: unitTestDescription,
|
2022-12-27 12:47:37 +02:00
|
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
2022-12-27 12:35:36 +02:00
|
|
|
t.Fail("blah")
|
2022-08-13 05:50:38 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
driver := &fakeGuiDriver{}
|
|
|
|
test.Run(driver)
|
|
|
|
assert.Equal(t, "blah", driver.failureMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSuccess(t *testing.T) {
|
|
|
|
test := NewIntegrationTest(NewIntegrationTestArgs{
|
|
|
|
Description: unitTestDescription,
|
2022-12-27 12:47:37 +02:00
|
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
2022-12-27 12:35:36 +02:00
|
|
|
t.press("a")
|
|
|
|
t.press("b")
|
2022-08-13 05:50:38 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
driver := &fakeGuiDriver{}
|
|
|
|
test.Run(driver)
|
|
|
|
assert.EqualValues(t, []string{"a", "b"}, driver.pressedKeys)
|
|
|
|
assert.Equal(t, "", driver.failureMessage)
|
|
|
|
}
|