file

package
v0.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "The copy menu allows to copy name and diff of selected/all files",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.UserConfig.OS.CopyToClipboardCmd = "echo {{text}} > clipboard"
	},
	SetupRepo: func(shell *Shell) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Files().
			IsEmpty().
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("File name")).
					Tooltip(Equals("Disabled: No item selected")).
					Confirm().
					Tap(func() {
						t.ExpectToast(Equals("Disabled: No item selected"))
					}).
					Cancel()
			})

		t.Shell().
			CreateDir("dir").
			CreateFile("dir/1-unstaged_file", "unstaged content")

		t.Views().Files().
			Press(keys.Universal.Refresh).
			Lines(
				Contains("dir").IsSelected(),
				Contains("unstaged_file"),
			).
			SelectNextItem().
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("Diff of selected file")).
					Tooltip(Contains("Disabled: Nothing to copy")).
					Confirm().
					Tap(func() {
						t.ExpectToast(Equals("Disabled: Nothing to copy"))
					}).
					Cancel()
			}).
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("Diff of all files")).
					Tooltip(Contains("Disabled: Nothing to copy")).
					Confirm().
					Tap(func() {
						t.ExpectToast(Equals("Disabled: Nothing to copy"))
					}).
					Cancel()
			})

		t.Shell().
			GitAdd("dir/1-unstaged_file").
			Commit("commit-unstaged").
			UpdateFile("dir/1-unstaged_file", "unstaged content (new)").
			CreateFileAndAdd("dir/2-staged_file", "staged content").
			Commit("commit-staged").
			UpdateFile("dir/2-staged_file", "staged content (new)").
			GitAdd("dir/2-staged_file")

		t.Views().Files().
			Press(keys.Universal.Refresh).
			Lines(
				Contains("dir"),
				Contains("unstaged_file").IsSelected(),
				Contains("staged_file"),
			).
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("File name")).
					Confirm()

				t.ExpectToast(Equals("File name copied to clipboard"))

				expectClipboard(t, Contains("unstaged_file"))
			})

		t.Views().Files().
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("Path")).
					Confirm()

				t.ExpectToast(Equals("File path copied to clipboard"))

				expectClipboard(t, Contains("dir/1-unstaged_file"))
			})

		t.Views().Files().
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("Diff of selected file")).
					Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
					Confirm()

				t.ExpectToast(Equals("File diff copied to clipboard"))

				expectClipboard(t, Contains("+unstaged content (new)"))
			})

		t.Views().Files().
			SelectPreviousItem().
			Lines(
				Contains("dir").IsSelected(),
				Contains("unstaged_file"),
				Contains("staged_file"),
			).
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("Diff of selected file")).
					Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
					Confirm()

				t.ExpectToast(Equals("File diff copied to clipboard"))

				expectClipboard(t, Contains("+staged content (new)"))
			})

		t.Views().Files().
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("Diff of all files")).
					Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
					Confirm()

				t.ExpectToast(Equals("All files diff copied to clipboard"))

				expectClipboard(t, Contains("+staged content (new)"))
			})

		t.Views().Files().
			SelectNextItem().
			SelectNextItem().
			Lines(
				Contains("dir"),
				Contains("unstaged_file"),
				Contains("staged_file").IsSelected(),
			).
			Press(keys.Universal.Select).
			Press(keys.Files.CopyFileInfoToClipboard).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Copy to clipboard")).
					Select(Contains("Diff of all files")).
					Tooltip(Equals("If there are staged items, this command considers only them. Otherwise, it considers all the unstaged ones.")).
					Confirm()

				t.ExpectToast(Equals("All files diff copied to clipboard"))

				expectClipboard(t, Contains("+staged content (new)").Contains("+unstaged content (new)"))
			})
	},
})
View Source
var DirWithUntrackedFile = NewIntegrationTest(NewIntegrationTestArgs{

	Description:  "When selecting a directory that contains an untracked file, we should not get an error",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFile("dir/file", "foo")
		shell.GitAddAll()
		shell.Commit("first commit")
		shell.CreateFile("dir/untracked", "bar")
		shell.UpdateFile("dir/file", "baz")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Lines(
				Contains("first commit"),
			)

		t.Views().Main().
			Content(DoesNotContain("error: Could not access")).
			Content(Contains("baz"))
	},
})
View Source
var DiscardAllDirChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding all changes in a directory",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {

		shell.CreateDir("dir")

		shell.RunShellCommand(`echo test > dir/both-deleted.txt`)
		shell.RunShellCommand(`git checkout -b conflict && git add dir/both-deleted.txt`)
		shell.RunShellCommand(`echo bothmodded > dir/both-modded.txt && git add dir/both-modded.txt`)
		shell.RunShellCommand(`echo haha > dir/deleted-them.txt && git add dir/deleted-them.txt`)
		shell.RunShellCommand(`echo haha2 > dir/deleted-us.txt && git add dir/deleted-us.txt`)
		shell.RunShellCommand(`echo mod > dir/modded.txt && git add dir/modded.txt`)
		shell.RunShellCommand(`echo mod > dir/modded-staged.txt && git add dir/modded-staged.txt`)
		shell.RunShellCommand(`echo del > dir/deleted.txt && git add dir/deleted.txt`)
		shell.RunShellCommand(`echo del > dir/deleted-staged.txt && git add dir/deleted-staged.txt`)
		shell.RunShellCommand(`echo change-delete > dir/change-delete.txt && git add dir/change-delete.txt`)
		shell.RunShellCommand(`echo delete-change > dir/delete-change.txt && git add dir/delete-change.txt`)
		shell.RunShellCommand(`echo double-modded > dir/double-modded.txt && git add dir/double-modded.txt`)
		shell.RunShellCommand(`echo "renamed\nhaha" > dir/renamed.txt && git add dir/renamed.txt`)
		shell.RunShellCommand(`git commit -m one`)

		shell.RunShellCommand(`git branch conflict_second && git mv dir/both-deleted.txt dir/added-them-changed-us.txt`)
		shell.RunShellCommand(`git commit -m "dir/both-deleted.txt renamed in dir/added-them-changed-us.txt"`)
		shell.RunShellCommand(`echo blah > dir/both-added.txt && git add dir/both-added.txt`)
		shell.RunShellCommand(`echo mod1 > dir/both-modded.txt && git add dir/both-modded.txt`)
		shell.RunShellCommand(`rm dir/deleted-them.txt && git add dir/deleted-them.txt`)
		shell.RunShellCommand(`echo modded > dir/deleted-us.txt && git add dir/deleted-us.txt`)
		shell.RunShellCommand(`git commit -m "two"`)

		shell.RunShellCommand(`git checkout conflict_second`)
		shell.RunShellCommand(`git mv dir/both-deleted.txt dir/changed-them-added-us.txt`)
		shell.RunShellCommand(`git commit -m "both-deleted.txt renamed in dir/changed-them-added-us.txt"`)
		shell.RunShellCommand(`echo mod2 > dir/both-modded.txt && git add dir/both-modded.txt`)
		shell.RunShellCommand(`echo blah2 > dir/both-added.txt && git add dir/both-added.txt`)
		shell.RunShellCommand(`echo modded > dir/deleted-them.txt && git add dir/deleted-them.txt`)
		shell.RunShellCommand(`rm dir/deleted-us.txt && git add dir/deleted-us.txt`)
		shell.RunShellCommand(`git commit -m "three"`)
		shell.RunShellCommand(`git reset --hard conflict_second`)
		shell.RunCommandExpectError([]string{"git", "merge", "conflict"})

		shell.RunShellCommand(`echo "new" > dir/new.txt`)
		shell.RunShellCommand(`echo "new staged" > dir/new-staged.txt && git add dir/new-staged.txt`)
		shell.RunShellCommand(`echo mod2 > dir/modded.txt`)
		shell.RunShellCommand(`echo mod2 > dir/modded-staged.txt && git add dir/modded-staged.txt`)
		shell.RunShellCommand(`rm dir/deleted.txt`)
		shell.RunShellCommand(`rm dir/deleted-staged.txt && git add dir/deleted-staged.txt`)
		shell.RunShellCommand(`echo change-delete2 > dir/change-delete.txt && git add dir/change-delete.txt`)
		shell.RunShellCommand(`rm dir/change-delete.txt`)
		shell.RunShellCommand(`rm dir/delete-change.txt && git add dir/delete-change.txt`)
		shell.RunShellCommand(`echo "changed" > dir/delete-change.txt`)
		shell.RunShellCommand(`echo "change1" > dir/double-modded.txt && git add dir/double-modded.txt`)
		shell.RunShellCommand(`echo "change2" > dir/double-modded.txt`)
		shell.RunShellCommand(`echo before > dir/added-changed.txt && git add dir/added-changed.txt`)
		shell.RunShellCommand(`echo after > dir/added-changed.txt`)
		shell.RunShellCommand(`rm dir/renamed.txt && git add dir/renamed.txt`)
		shell.RunShellCommand(`echo "renamed\nhaha" > dir/renamed2.txt && git add dir/renamed2.txt`)
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("UA").Contains("added-them-changed-us.txt"),
				Contains("AA").Contains("both-added.txt"),
				Contains("DD").Contains("both-deleted.txt"),
				Contains("UU").Contains("both-modded.txt"),
				Contains("AU").Contains("changed-them-added-us.txt"),
				Contains("UD").Contains("deleted-them.txt"),
				Contains("DU").Contains("deleted-us.txt"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			Tap(func() {
				t.Common().ContinueOnConflictsResolved()
			}).
			Lines(
				Contains("dir").IsSelected(),
				Contains(" M").Contains("added-changed.txt"),
				Contains(" D").Contains("change-delete.txt"),
				Contains("??").Contains("delete-change.txt"),
				Contains(" D").Contains("deleted.txt"),
				Contains(" M").Contains("double-modded.txt"),
				Contains(" M").Contains("modded.txt"),
				Contains("??").Contains("new.txt"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			IsEmpty()
	},
})
View Source
var DiscardRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discard a range of files using range select",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("dir2/file-2b", "old content")
		shell.CreateFileAndAdd("dir3/file-3b", "old content")
		shell.Commit("first commit")
		shell.UpdateFile("dir2/file-2b", "new content")
		shell.UpdateFile("dir3/file-3b", "new content")

		shell.CreateFile("dir1/file-1a", "")
		shell.CreateFile("dir1/file-1b", "")
		shell.CreateFile("dir2/file-2a", "")
		shell.CreateFile("dir3/file-3a", "")
		shell.CreateFile("file-a", "")
		shell.CreateFile("file-b", "")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("▼ dir1").IsSelected(),
				Contains("  ??").Contains("file-1a"),
				Contains("  ??").Contains("file-1b"),
				Contains("▼ dir2"),
				Contains("  ??").Contains("file-2a"),
				Contains("   M").Contains("file-2b"),
				Contains("▼ dir3"),
				Contains("  ??").Contains("file-3a"),
				Contains("   M").Contains("file-3b"),
				Contains("??").Contains("file-a"),
				Contains("??").Contains("file-b"),
			).
			NavigateToLine(Contains("file-1b")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file-2a")).
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-1a"),
				Contains("  ??").Contains("file-1b").IsSelected(),
				Contains("▼ dir2").IsSelected(),
				Contains("  ??").Contains("file-2a").IsSelected(),
				Contains("   M").Contains("file-2b"),
				Contains("▼ dir3"),
				Contains("  ??").Contains("file-3a"),
				Contains("   M").Contains("file-3b"),
				Contains("??").Contains("file-a"),
				Contains("??").Contains("file-b"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-1a"),
				Contains("▼ dir3").IsSelected(),
				Contains("  ??").Contains("file-3a"),
				Contains("   M").Contains("file-3b"),
				Contains("??").Contains("file-a"),
				Contains("??").Contains("file-b"),
			).
			PressEnter().
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file-a")).
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-1a"),
				Contains("▶ dir3").IsSelected(),
				Contains("??").Contains("file-a").IsSelected(),
				Contains("??").Contains("file-b"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-1a"),
				Contains("??").Contains("file-b").IsSelected(),
			)
	},
})
View Source
var DiscardStagedChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding staged changes",
	ExtraCmdArgs: []string{},
	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(`?? file3`),
				Contains(` M fileToRemove`),
			).
			NavigateToLine(Contains(`fileToRemove`)).
			PressPrimaryAction().
			Lines(
				Contains(` M file2`),
				Contains(`?? file3`),
				Contains(`M  fileToRemove`).IsSelected(),
			).
			Press(keys.Files.ViewResetOptions)

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

		t.Views().Files().
			Lines(
				Contains(` M file2`),
				Contains(`?? file3`).IsSelected(),
			)

		t.FileSystem().FileContent("fileToRemove", Equals("original content"))
	},
})
View Source
var DiscardUnstagedDirChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding unstaged changes in a directory",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateDir("dir")
		shell.CreateFileAndAdd("dir/file-one", "original content\n")

		shell.Commit("first commit")

		shell.UpdateFileAndAdd("dir/file-one", "original content\nnew content\n")
		shell.UpdateFile("dir/file-one", "original content\nnew content\neven newer content\n")

		shell.CreateDir("dir/subdir")
		shell.CreateFile("dir/subdir/unstaged-file-one", "unstaged file")
		shell.CreateFile("dir/unstaged-file-two", "unstaged file")

		shell.CreateFile("unstaged-file-three", "unstaged file")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("dir").IsSelected(),
				Contains("subdir"),
				Contains("??").Contains("unstaged-file-one"),
				Contains("MM").Contains("file-one"),
				Contains("??").Contains("unstaged-file-two"),
				Contains("??").Contains("unstaged-file-three"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard unstaged changes")).
					Confirm()
			}).
			Lines(
				Contains("dir").IsSelected(),
				Contains("M ").Contains("file-one"),

				Contains("??").Contains("unstaged-file-three"),
			)

		t.FileSystem().FileContent("dir/file-one", Equals("original content\nnew content\n"))
	},
})
View Source
var DiscardUnstagedFileChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding unstaged changes in a file",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file-one", "original content\n")

		shell.Commit("first commit")

		shell.UpdateFileAndAdd("file-one", "original content\nnew content\n")
		shell.UpdateFile("file-one", "original content\nnew content\neven newer content\n")

		shell.CreateFileAndAdd("file-two", "original content\n")
		shell.UpdateFile("file-two", "original content\nnew content\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("MM").Contains("file-one").IsSelected(),
				Contains("AM").Contains("file-two"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard unstaged changes")).
					Confirm()
			}).
			Lines(
				Contains("M ").Contains("file-one").IsSelected(),
				Contains("AM").Contains("file-two"),
			).
			SelectNextItem().
			Lines(
				Contains("M ").Contains("file-one"),
				Contains("AM").Contains("file-two").IsSelected(),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard unstaged changes")).
					Confirm()
			}).
			Lines(
				Contains("M ").Contains("file-one"),
				Contains("A ").Contains("file-two").IsSelected(),
			)

		t.FileSystem().FileContent("file-one", Equals("original content\nnew content\n"))
		t.FileSystem().FileContent("file-two", Equals("original content\n"))
	},
})
View Source
var DiscardUnstagedRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discard unstaged changed in a range of files using range select",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("dir2/file-d", "old content")
		shell.Commit("first commit")
		shell.UpdateFile("dir2/file-d", "new content")

		shell.CreateFile("dir1/file-a", "")
		shell.CreateFile("dir1/file-b", "")
		shell.CreateFileAndAdd("dir2/file-c", "")
		shell.CreateFile("file-e", "")
		shell.CreateFile("file-f", "")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("▼ dir1").IsSelected(),
				Contains("  ??").Contains("file-a"),
				Contains("  ??").Contains("file-b"),
				Contains("▼ dir2"),
				Contains("  A ").Contains("file-c"),
				Contains("   M").Contains("file-d"),
				Contains("??").Contains("file-e"),
				Contains("??").Contains("file-f"),
			).
			NavigateToLine(Contains("file-b")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file-c")).
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-a"),
				Contains("  ??").Contains("file-b").IsSelected(),
				Contains("▼ dir2").IsSelected(),
				Contains("  A ").Contains("file-c").IsSelected(),
				Contains("   M").Contains("file-d"),
				Contains("??").Contains("file-e"),
				Contains("??").Contains("file-f"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard unstaged changes")).
					Confirm()
			}).
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-a"),
				Contains("▼ dir2"),

				Contains("  A ").Contains("file-c").IsSelected(),
				Contains("??").Contains("file-e"),
				Contains("??").Contains("file-f"),
			)
	},
})
View Source
var DiscardVariousChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding all possible permutations of changed files",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		createAllPossiblePermutationsOfChangedFiles(shell)
	},

	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		type statusFile struct {
			status string
			label  string
		}

		discardOneByOne := func(files []statusFile) {
			for _, file := range files {
				t.Views().Files().
					IsFocused().
					SelectedLine(Contains(file.status + " " + file.label)).
					Press(keys.Universal.Remove)

				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			}
		}

		discardOneByOne([]statusFile{
			{status: "UA", label: "added-them-changed-us.txt"},
			{status: "AA", label: "both-added.txt"},
			{status: "DD", label: "both-deleted.txt"},
			{status: "UU", label: "both-modded.txt"},
			{status: "AU", label: "changed-them-added-us.txt"},
			{status: "UD", label: "deleted-them.txt"},
			{status: "DU", label: "deleted-us.txt"},
		})

		t.ExpectPopup().Confirmation().
			Title(Equals("Continue")).
			Content(Contains("All merge conflicts resolved. Continue?")).
			Cancel()

		discardOneByOne([]statusFile{
			{status: "AM", label: "added-changed.txt"},
			{status: "MD", label: "change-delete.txt"},
			{status: "D ", label: "delete-change.txt"},
			{status: "D ", label: "deleted-staged.txt"},
			{status: " D", label: "deleted.txt"},
			{status: "MM", label: "double-modded.txt"},
			{status: "M ", label: "modded-staged.txt"},
			{status: " M", label: "modded.txt"},
			{status: "A ", label: "new-staged.txt"},
			{status: "??", label: "new.txt"},

			{status: "R ", label: "renamed.txt → renamed2.txt"},
		})

		t.Views().Files().IsEmpty()
	},
})
View Source
var DiscardVariousChangesRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discarding all possible permutations of changed files via range select",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		createAllPossiblePermutationsOfChangedFiles(shell)
	},

	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("UA").Contains("added-them-changed-us.txt").IsSelected(),
				Contains("AA").Contains("both-added.txt"),
				Contains("DD").Contains("both-deleted.txt"),
				Contains("UU").Contains("both-modded.txt"),
				Contains("AU").Contains("changed-them-added-us.txt"),
				Contains("UD").Contains("deleted-them.txt"),
				Contains("DU").Contains("deleted-us.txt"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("deleted-us.txt")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()

				t.ExpectPopup().Confirmation().
					Title(Equals("Continue")).
					Content(Contains("All merge conflicts resolved. Continue?")).
					Cancel()
			}).
			Lines(
				Contains("AM").Contains("added-changed.txt").IsSelected(),
				Contains("MD").Contains("change-delete.txt"),
				Contains("D ").Contains("delete-change.txt"),
				Contains("D ").Contains("deleted-staged.txt"),
				Contains(" D").Contains("deleted.txt"),
				Contains("MM").Contains("double-modded.txt"),
				Contains("M ").Contains("modded-staged.txt"),
				Contains(" M").Contains("modded.txt"),
				Contains("A ").Contains("new-staged.txt"),
				Contains("??").Contains("new.txt"),
				Contains("R ").Contains("renamed.txt → renamed2.txt"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("renamed.txt")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			})

		t.Views().Files().IsEmpty()
	},
})
View Source
var Gitignore = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that we can't ignore the .gitignore file, then ignore/exclude other files",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFile(".gitignore", "")
		shell.CreateFile("toExclude", "")
		shell.CreateFile("toIgnore", "")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains(`?? .gitignore`).IsSelected(),
				Contains(`?? toExclude`),
				Contains(`?? toIgnore`),
			).
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .git/info/exclude")).Confirm()

				t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot exclude .gitignore")).Confirm()
			}).
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .gitignore")).Confirm()

				t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot ignore .gitignore")).Confirm()

				t.FileSystem().FileContent(".gitignore", Equals(""))
				t.FileSystem().FileContent(".git/info/exclude", DoesNotContain(".gitignore"))
			}).
			SelectNextItem().
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .git/info/exclude")).Confirm()

				t.FileSystem().FileContent(".gitignore", Equals(""))
				t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
			}).
			SelectNextItem().
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .gitignore")).Confirm()

				t.FileSystem().FileContent(".gitignore", Equals("toIgnore\n"))
				t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
			})
	},
})
View Source
var RememberCommitMessageAfterFail = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that the commit message is remembered after a failed attempt at committing",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFile(".git/hooks/pre-commit", preCommitHook)
		shell.MakeExecutable(".git/hooks/pre-commit")

		shell.CreateFileAndAdd("one", "one")

		shell.CreateFile("bad", "bad")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("bad"),
				Contains("one"),
			).
			Press(keys.Files.CommitChanges).
			Tap(func() {
				t.ExpectPopup().CommitMessagePanel().Type("my message").Confirm()

				t.ExpectPopup().Alert().Title(Equals("Error")).Content(Contains("Git command failed")).Confirm()
			}).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			Lines(
				Contains("one"),
			).
			Press(keys.Files.CommitChanges).
			Tap(func() {
				t.ExpectPopup().CommitMessagePanel().
					InitialText(Equals("my message")).
					Confirm()

				t.Views().Commits().
					Lines(
						Contains("my message"),
					)
			})
	},
})
View Source
var StageRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage/unstage a range of files using range select",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("dir2/file-d", "old content")
		shell.Commit("first commit")
		shell.UpdateFile("dir2/file-d", "new content")

		shell.CreateFile("dir1/file-a", "")
		shell.CreateFile("dir1/file-b", "")
		shell.CreateFile("dir2/file-c", "")
		shell.CreateFile("file-e", "")
		shell.CreateFile("file-f", "")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("▼ dir1").IsSelected(),
				Contains("  ??").Contains("file-a"),
				Contains("  ??").Contains("file-b"),
				Contains("▼ dir2"),
				Contains("  ??").Contains("file-c"),
				Contains("   M").Contains("file-d"),
				Contains("??").Contains("file-e"),
				Contains("??").Contains("file-f"),
			).
			NavigateToLine(Contains("file-b")).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file-c")).
			PressPrimaryAction().
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-a"),
				Contains("  A ").Contains("file-b").IsSelected(),
				Contains("▼ dir2").IsSelected(),
				Contains("  A ").Contains("file-c").IsSelected(),

				Contains("  M ").Contains("file-d"),
				Contains("??").Contains("file-e"),
				Contains("??").Contains("file-f"),
			).
			PressPrimaryAction().
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-a"),
				Contains("  ??").Contains("file-b").IsSelected(),
				Contains("▼ dir2").IsSelected(),
				Contains("  ??").Contains("file-c").IsSelected(),
				Contains("   M").Contains("file-d"),
				Contains("??").Contains("file-e"),
				Contains("??").Contains("file-f"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("dir2")).
			PressEnter().
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-a"),
				Contains("  ??").Contains("file-b"),
				Contains("▶ dir2").IsSelected(),
				Contains("??").Contains("file-e"),
				Contains("??").Contains("file-f"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("file-e")).
			PressPrimaryAction().
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-a"),
				Contains("  ??").Contains("file-b"),
				Contains("▶ dir2").IsSelected(),
				Contains("A ").Contains("file-e").IsSelected(),
				Contains("??").Contains("file-f"),
			).
			Press(keys.Universal.ToggleRangeSelect).
			NavigateToLine(Contains("dir2")).
			PressEnter().
			Lines(
				Contains("▼ dir1"),
				Contains("  ??").Contains("file-a"),
				Contains("  ??").Contains("file-b"),
				Contains("▼ dir2").IsSelected(),
				Contains("  A ").Contains("file-c"),
				Contains("  M ").Contains("file-d"),
				Contains("A ").Contains("file-e"),
				Contains("??").Contains("file-f"),
			)
	},
})

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL