1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-02 23:27:32 +02:00

Make it mandatory to acknowledge toasts in tests

This commit is contained in:
Stefan Haller 2024-01-13 16:17:41 +01:00
parent 9fa43394fe
commit 8ca8a43968
7 changed files with 44 additions and 0 deletions

View File

@ -26,6 +26,8 @@ type GuiDriver struct {
var _ integrationTypes.GuiDriver = &GuiDriver{} var _ integrationTypes.GuiDriver = &GuiDriver{}
func (self *GuiDriver) PressKey(keyStr string) { func (self *GuiDriver) PressKey(keyStr string) {
self.CheckAllToastsAcknowledged()
key := keybindings.GetKey(keyStr) key := keybindings.GetKey(keyStr)
var r rune var r rune
@ -47,6 +49,8 @@ func (self *GuiDriver) PressKey(keyStr string) {
} }
func (self *GuiDriver) Click(x, y int) { func (self *GuiDriver) Click(x, y int) {
self.CheckAllToastsAcknowledged()
self.gui.g.ReplayedEvents.MouseEvents <- gocui.NewTcellMouseEventWrapper( self.gui.g.ReplayedEvents.MouseEvents <- gocui.NewTcellMouseEventWrapper(
tcell.NewEventMouse(x, y, tcell.ButtonPrimary, 0), tcell.NewEventMouse(x, y, tcell.ButtonPrimary, 0),
0, 0,
@ -59,6 +63,12 @@ func (self *GuiDriver) waitTillIdle() {
<-self.isIdleChan <-self.isIdleChan
} }
func (self *GuiDriver) CheckAllToastsAcknowledged() {
if t := self.NextToast(); t != nil {
self.Fail("Toast not acknowledged: " + *t)
}
}
func (self *GuiDriver) Keys() config.KeybindingConfig { func (self *GuiDriver) Keys() config.KeybindingConfig {
return self.gui.Config.GetUserConfig().Keybinding return self.gui.Config.GetUserConfig().Keybinding
} }

View File

@ -194,6 +194,8 @@ func (self *IntegrationTest) Run(gui integrationTypes.GuiDriver) {
self.run(testDriver, keys) self.run(testDriver, keys)
gui.CheckAllToastsAcknowledged()
if InputDelay() > 0 { if InputDelay() > 0 {
// Clear whatever caption there was so it doesn't linger // Clear whatever caption there was so it doesn't linger
testDriver.SetCaption("") testDriver.SetCaption("")

View File

@ -82,6 +82,8 @@ func (self *fakeGuiDriver) NextToast() *string {
return nil return nil
} }
func (self *fakeGuiDriver) CheckAllToastsAcknowledged() {}
func TestManualFailure(t *testing.T) { func TestManualFailure(t *testing.T) {
test := NewIntegrationTest(NewIntegrationTestArgs{ test := NewIntegrationTest(NewIntegrationTestArgs{
Description: unitTestDescription, Description: unitTestDescription,

View File

@ -101,6 +101,8 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
Select(Contains("File name")). Select(Contains("File name")).
Confirm() Confirm()
t.ExpectToast(Equals("File name copied to clipboard"))
expectClipboard(t, Contains("unstaged_file")) expectClipboard(t, Contains("unstaged_file"))
}) })
@ -113,6 +115,8 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
Select(Contains("Path")). Select(Contains("Path")).
Confirm() Confirm()
t.ExpectToast(Equals("File path copied to clipboard"))
expectClipboard(t, Contains("dir/1-unstaged_file")) expectClipboard(t, Contains("dir/1-unstaged_file"))
}) })
@ -126,6 +130,8 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")). Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
Confirm() Confirm()
t.ExpectToast(Equals("File diff copied to clipboard"))
expectClipboard(t, Contains("+unstaged content (new)")) expectClipboard(t, Contains("+unstaged content (new)"))
}) })
@ -145,6 +151,8 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")). Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
Confirm() Confirm()
t.ExpectToast(Equals("File diff copied to clipboard"))
expectClipboard(t, Contains("+staged content (new)")) expectClipboard(t, Contains("+staged content (new)"))
}) })
@ -158,6 +166,8 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")). Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
Confirm() Confirm()
t.ExpectToast(Equals("All files diff copied to clipboard"))
expectClipboard(t, Contains("+staged content (new)")) expectClipboard(t, Contains("+staged content (new)"))
}) })
@ -179,6 +189,8 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")). Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
Confirm() Confirm()
t.ExpectToast(Equals("All files diff copied to clipboard"))
expectClipboard(t, Contains("+staged content (new)").Contains("+unstaged content (new)")) expectClipboard(t, Contains("+staged content (new)").Contains("+unstaged content (new)"))
}) })
}, },

View File

@ -27,6 +27,8 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
). ).
Press(keys.Universal.CopyToClipboard) Press(keys.Universal.CopyToClipboard)
t.ExpectToast(Equals("'branch-a' Copied to clipboard"))
t.Views().Files(). t.Views().Files().
Focus() Focus()

View File

@ -62,6 +62,9 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
Contains(` 6a`), Contains(` 6a`),
). ).
Press(keys.Universal.IncreaseContextInDiffView). Press(keys.Universal.IncreaseContextInDiffView).
Tap(func() {
t.ExpectToast(Equals("Changed diff context size to 4"))
}).
SelectedLines( SelectedLines(
Contains(`@@ -1,7 +1,7 @@`), Contains(`@@ -1,7 +1,7 @@`),
Contains(` 1a`), Contains(` 1a`),
@ -74,6 +77,9 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
Contains(` 7a`), Contains(` 7a`),
). ).
Press(keys.Universal.DecreaseContextInDiffView). Press(keys.Universal.DecreaseContextInDiffView).
Tap(func() {
t.ExpectToast(Equals("Changed diff context size to 3"))
}).
SelectedLines( SelectedLines(
Contains(`@@ -1,6 +1,6 @@`), Contains(`@@ -1,6 +1,6 @@`),
Contains(` 1a`), Contains(` 1a`),
@ -85,6 +91,9 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
Contains(` 6a`), Contains(` 6a`),
). ).
Press(keys.Universal.DecreaseContextInDiffView). Press(keys.Universal.DecreaseContextInDiffView).
Tap(func() {
t.ExpectToast(Equals("Changed diff context size to 2"))
}).
SelectedLines( SelectedLines(
Contains(`@@ -1,5 +1,5 @@`), Contains(`@@ -1,5 +1,5 @@`),
Contains(` 1a`), Contains(` 1a`),
@ -95,6 +104,9 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
Contains(` 5a`), Contains(` 5a`),
). ).
Press(keys.Universal.DecreaseContextInDiffView). Press(keys.Universal.DecreaseContextInDiffView).
Tap(func() {
t.ExpectToast(Equals("Changed diff context size to 1"))
}).
SelectedLines( SelectedLines(
Contains(`@@ -2,3 +2,3 @@`), Contains(`@@ -2,3 +2,3 @@`),
Contains(` 2a`), Contains(` 2a`),
@ -116,6 +128,9 @@ var DiffContextChange = NewIntegrationTest(NewIntegrationTestArgs{
Contains(` 4a`), Contains(` 4a`),
). ).
Press(keys.Universal.IncreaseContextInDiffView). Press(keys.Universal.IncreaseContextInDiffView).
Tap(func() {
t.ExpectToast(Equals("Changed diff context size to 2"))
}).
SelectedLines( SelectedLines(
Contains(`@@ -1,5 +1,5 @@`), Contains(`@@ -1,5 +1,5 @@`),
Contains(` 1a`), Contains(` 1a`),

View File

@ -45,4 +45,5 @@ type GuiDriver interface {
SetCaptionPrefix(prefix string) SetCaptionPrefix(prefix string)
// Pop the next toast that was displayed; returns nil if there was none // Pop the next toast that was displayed; returns nil if there was none
NextToast() *string NextToast() *string
CheckAllToastsAcknowledged()
} }