aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration
diff options
context:
space:
mode:
authorKyle D <kdumontnu@gmail.com>2023-02-19 20:56:07 -0700
committerGitHub <noreply@github.com>2023-02-20 11:56:07 +0800
commit2b3f12f6fd12afebb3b8397dc612621df6c730e2 (patch)
tree427e05fe61548413bac83ddde088f368e8f967e7 /tests/integration
parent6840a8ccfcdbdcc352eac40a5c9beabf6e7c54ff (diff)
downloadgitea-2b3f12f6fd12afebb3b8397dc612621df6c730e2.tar.gz
gitea-2b3f12f6fd12afebb3b8397dc612621df6c730e2.zip
Use beforeCommit instead of baseCommit (#22949)
Replaces: https://github.com/go-gitea/gitea/pull/22947 Fixes https://github.com/go-gitea/gitea/issues/22946 Probably related to https://github.com/go-gitea/gitea/issues/19530 Basically, many of the diffs were broken because they were comparing to the base commit, where a 3-dot diff should be comparing to the [last common ancestor](https://matthew-brett.github.io/pydagogue/git_diff_dots.html). This should have an integration test so that we don’t run into this issue again. --------- Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/compare_test.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go
index dc2bff89fd..509524ca56 100644
--- a/tests/integration/compare_test.go
+++ b/tests/integration/compare_test.go
@@ -4,6 +4,7 @@
package integration
import (
+ "fmt"
"net/http"
"strings"
"testing"
@@ -40,3 +41,80 @@ func TestCompareDefault(t *testing.T) {
selection := htmlDoc.doc.Find(".choose.branch .filter.dropdown")
assert.Lenf(t, selection.Nodes, 2, "The template has changed")
}
+
+// Ensure the comparison matches what we expect
+func inspectCompare(t *testing.T, htmlDoc *HTMLDoc, diffCount int, diffChanges []string) {
+ selection := htmlDoc.doc.Find("#diff-file-boxes").Children()
+
+ assert.Lenf(t, selection.Nodes, diffCount, "Expected %v diffed files, found: %v", diffCount, len(selection.Nodes))
+
+ for _, diffChange := range diffChanges {
+ selection = htmlDoc.doc.Find(fmt.Sprintf("[data-new-filename=\"%s\"]", diffChange))
+ assert.Lenf(t, selection.Nodes, 1, "Expected 1 match for [data-new-filename=\"%s\"], found: %v", diffChange, len(selection.Nodes))
+ }
+}
+
+// Git commit graph for repo20
+// * 8babce9 (origin/remove-files-b) Add a dummy file
+// * b67e43a Delete test.csv and link_hi
+// | * cfe3b3c (origin/remove-files-a) Delete test.csv and link_hi
+// |/
+// * c8e31bc (origin/add-csv) Add test csv file
+// * 808038d (HEAD -> master, origin/master, origin/HEAD) Added test links
+
+func TestCompareBranches(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ session := loginUser(t, "user2")
+
+ // Inderect compare remove-files-b (head) with add-csv (base) branch
+ //
+ // 'link_hi' and 'test.csv' are deleted, 'test.txt' is added
+ req := NewRequest(t, "GET", "/user2/repo20/compare/add-csv...remove-files-b")
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
+
+ diffCount := 3
+ diffChanges := []string{"link_hi", "test.csv", "test.txt"}
+
+ inspectCompare(t, htmlDoc, diffCount, diffChanges)
+
+ // Inderect compare remove-files-b (head) with remove-files-a (base) branch
+ //
+ // 'link_hi' and 'test.csv' are deleted, 'test.txt' is added
+
+ req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-a...remove-files-b")
+ resp = session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc = NewHTMLParser(t, resp.Body)
+
+ diffCount = 3
+ diffChanges = []string{"link_hi", "test.csv", "test.txt"}
+
+ inspectCompare(t, htmlDoc, diffCount, diffChanges)
+
+ // Inderect compare remove-files-a (head) with remove-files-b (base) branch
+ //
+ // 'link_hi' and 'test.csv' are deleted
+
+ req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b...remove-files-a")
+ resp = session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc = NewHTMLParser(t, resp.Body)
+
+ diffCount = 2
+ diffChanges = []string{"link_hi", "test.csv"}
+
+ inspectCompare(t, htmlDoc, diffCount, diffChanges)
+
+ // Direct compare remove-files-b (head) with remove-files-a (base) branch
+ //
+ // 'test.txt' is deleted
+
+ req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b..remove-files-a")
+ resp = session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc = NewHTMLParser(t, resp.Body)
+
+ diffCount = 1
+ diffChanges = []string{"test.txt"}
+
+ inspectCompare(t, htmlDoc, diffCount, diffChanges)
+}