Skip to content

Commit

Permalink
migrate discard staged changes test
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Dec 28, 2022
1 parent ae07cf5 commit f2d0f36
Show file tree
Hide file tree
Showing 36 changed files with 76 additions and 71 deletions.
23 changes: 23 additions & 0 deletions pkg/integration/components/file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,26 @@ func (self *FileSystem) PathNotPresent(path string) {
return os.IsNotExist(err), fmt.Sprintf("Expected path '%s' to not exist, but it does", path)
})
}

// Asserts that the file at the given path has the given content
func (self *FileSystem) FileContainsContent(path string, matcher *matcher) {
self.assertWithRetries(func() (bool, string) {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false, fmt.Sprintf("Expected path '%s' to not exist, but it does", path)
}

output, err := os.ReadFile(path)
if err != nil {
return false, fmt.Sprintf("Expected error when reading file content at path '%s': %s", path, err.Error())
}

strOutput := string(output)

if ok, errMsg := matcher.context("").test(strOutput); !ok {
return false, fmt.Sprintf("Unexpected content in file %s: %s", path, errMsg)
}

return true, ""
})
}
52 changes: 52 additions & 0 deletions pkg/integration/tests/file/discard_staged_changes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package file

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var DiscardStagedChanges = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding staged changes",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("fileToRemove", "original content")
shell.CreateFileAndAdd("file2", "original content")
shell.Commit("first commit")

shell.CreateFile("file3", "original content")
shell.UpdateFile("fileToRemove", "new content")
shell.UpdateFile("file2", "new content")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Lines(
Contains(` M file2`).IsSelected(),
Contains(` M fileToRemove`),
Contains(`?? file3`),
).
SelectNextItem().
PressPrimaryAction().
Lines(
Contains(` M file2`),
Contains(`M fileToRemove`).IsSelected(),
Contains(`?? file3`),
).
Press(keys.Files.ViewResetOptions)

t.ExpectPopup().Menu().Title(Equals("")).Select(Contains("discard staged changes")).Confirm()

// staged file has been removed
t.Views().Files().
Lines(
Contains(` M file2`),
Contains(`?? file3`).IsSelected(),
)

// the file should have the same content that it originally had, given that that was committed already
t.FileSystem().FileContainsContent("fileToRemove", Equals("original content"))
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var tests = []*components.IntegrationTest{
custom_commands.MultiplePrompts,
file.DirWithUntrackedFile,
file.DiscardChanges,
file.DiscardStagedChanges,
interactive_rebase.AmendMerge,
interactive_rebase.One,
stash.Rename,
Expand Down

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/discardStagedFiles/expected/repo/file0

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/discardStagedFiles/expected/repo/file1

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/discardStagedFiles/expected/repo/file2

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/discardStagedFiles/expected/repo/file3

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/discardStagedFiles/recording.json

This file was deleted.

26 changes: 0 additions & 26 deletions test/integration/discardStagedFiles/setup.sh

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/discardStagedFiles/test.json

This file was deleted.

0 comments on commit f2d0f36

Please sign in to comment.