migrate stash tests

This commit is contained in:
Jesse Duffield
2023-02-20 21:52:27 +11:00
parent e1c376ef54
commit 2b6a109e38
290 changed files with 452 additions and 582 deletions

View File

@@ -0,0 +1,43 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Apply = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Apply a stash entry",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.CreateFile("file", "content")
shell.GitAddAll()
shell.Stash("stash one")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().IsEmpty()
t.Views().Stash().
Focus().
Lines(
Contains("stash one").IsSelected(),
).
PressPrimaryAction().
Tap(func() {
t.ExpectPopup().Confirmation().
Title(Equals("Stash apply")).
Content(Contains("Are you sure you want to apply this stash entry?")).
Confirm()
}).
Lines(
Contains("stash one").IsSelected(),
)
t.Views().Files().
Lines(
Contains("file"),
)
},
})

View File

@@ -0,0 +1,53 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Restore part of a stash entry via applying a custom patch",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.CreateFile("myfile", "content")
shell.CreateFile("myfile2", "content")
shell.GitAddAll()
shell.Stash("stash one")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().IsEmpty()
t.Views().Stash().
Focus().
Lines(
Contains("stash one").IsSelected(),
).
PressEnter().
Tap(func() {
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("myfile").IsSelected(),
Contains("myfile2"),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Views().
CommitFiles().
Press(keys.Universal.CreatePatchOptionsMenu)
t.ExpectPopup().Menu().
Title(Equals("Patch Options")).
Select(MatchesRegexp(`apply patch$`)).Confirm()
})
t.Views().Files().Lines(
Contains("myfile"),
)
},
})

View File

@@ -0,0 +1,54 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var CreateBranch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Create a branch from a stash entry",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.CreateFile("myfile", "content")
shell.GitAddAll()
shell.Stash("stash one")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().IsEmpty()
t.Views().Stash().
Focus().
Lines(
Contains("stash one").IsSelected(),
).
Press(keys.Universal.New).
Tap(func() {
t.ExpectPopup().Prompt().
Title(Contains("New Branch Name (Branch is off of 'stash@{0}: On master: stash one'")).
Type("new_branch").
Confirm()
})
t.Views().Files().IsEmpty()
t.Views().Branches().
IsFocused().
Lines(
Contains("new_branch").IsSelected(),
Contains("master"),
).
PressEnter()
t.Views().SubCommits().
Lines(
Contains("On master: stash one").IsSelected(),
MatchesRegexp(`index on master:.*initial commit`),
Contains("initial commit"),
)
t.Views().Main().Content(Contains("myfile | 1 +"))
},
})

View File

@@ -0,0 +1,38 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Drop = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Drop a stash entry",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.CreateFile("file", "content")
shell.GitAddAll()
shell.Stash("stash one")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().IsEmpty()
t.Views().Stash().
Focus().
Lines(
Contains("stash one").IsSelected(),
).
Press(keys.Universal.Remove).
Tap(func() {
t.ExpectPopup().Confirmation().
Title(Equals("Stash drop")).
Content(Contains("Are you sure you want to drop this stash entry?")).
Confirm()
}).
IsEmpty()
t.Views().Files().IsEmpty()
},
})

View File

@@ -0,0 +1,41 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Pop = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Pop a stash entry",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.CreateFile("file", "content")
shell.GitAddAll()
shell.Stash("stash one")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().IsEmpty()
t.Views().Stash().
Focus().
Lines(
Contains("stash one").IsSelected(),
).
Press(keys.Stash.PopStash).
Tap(func() {
t.ExpectPopup().Confirmation().
Title(Equals("Stash pop")).
Content(Contains("Are you sure you want to pop this stash entry?")).
Confirm()
}).
IsEmpty()
t.Views().Files().
Lines(
Contains("file"),
)
},
})

View File

@@ -6,7 +6,7 @@ import (
)
var Stash = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Stashing files",
Description: "Stashing files directly (not going through the stash menu)",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
@@ -23,9 +23,7 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{
Lines(
Contains("file"),
).
Press(keys.Files.ViewStashOptions)
t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm()
Press(keys.Files.StashAllChanges)
t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()

View File

@@ -0,0 +1,40 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StashAll = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Stashing all changes (via the menu)",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.CreateFile("file", "content")
shell.GitAddAll()
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Stash().
IsEmpty()
t.Views().Files().
Lines(
Contains("file"),
).
Press(keys.Files.ViewStashOptions)
t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm()
t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
t.Views().Stash().
Lines(
Contains("my stashed file"),
)
t.Views().Files().
IsEmpty()
},
})

View File

@@ -0,0 +1,56 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StashAndKeepIndex = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Stash staged changes",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file-staged", "content")
shell.CreateFileAndAdd("file-unstaged", "content")
shell.EmptyCommit("initial commit")
shell.UpdateFileAndAdd("file-staged", "new content")
shell.UpdateFile("file-unstaged", "new content")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Stash().
IsEmpty()
t.Views().Files().
Lines(
Contains("file-staged"),
Contains("file-unstaged"),
).
Press(keys.Files.ViewStashOptions)
t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(Contains("stash all changes and keep index")).Confirm()
t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
t.Views().Stash().
Lines(
Contains("my stashed file"),
)
t.Views().Files().
Lines(
Contains("file-staged"),
)
t.Views().Stash().
Focus().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file-staged"),
Contains("file-unstaged"),
)
},
})

View File

@@ -0,0 +1,55 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StashStaged = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Stash staged changes",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file-staged", "content")
shell.CreateFileAndAdd("file-unstaged", "content")
shell.EmptyCommit("initial commit")
shell.UpdateFileAndAdd("file-staged", "new content")
shell.UpdateFile("file-unstaged", "new content")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Stash().
IsEmpty()
t.Views().Files().
Lines(
Contains("file-staged"),
Contains("file-unstaged"),
).
Press(keys.Files.ViewStashOptions)
t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash staged changes$")).Confirm()
t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
t.Views().Stash().
Lines(
Contains("my stashed file"),
)
t.Views().Files().
Lines(
Contains("file-unstaged"),
)
t.Views().Stash().
Focus().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file-staged").IsSelected(),
)
},
})

View File

@@ -0,0 +1,55 @@
package stash
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StashUnstaged = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Stash unstaged changes",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file-staged", "content")
shell.CreateFileAndAdd("file-unstaged", "content")
shell.EmptyCommit("initial commit")
shell.UpdateFileAndAdd("file-staged", "new content")
shell.UpdateFile("file-unstaged", "new content")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Stash().
IsEmpty()
t.Views().Files().
Lines(
Contains("file-staged"),
Contains("file-unstaged"),
).
Press(keys.Files.ViewStashOptions)
t.ExpectPopup().Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash unstaged changes$")).Confirm()
t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
t.Views().Stash().
Lines(
Contains("my stashed file"),
)
t.Views().Files().
Lines(
Contains("file-staged"),
)
t.Views().Stash().
Focus().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file-unstaged").IsSelected(),
)
},
})