|
5 | 5 | package integration
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "fmt" |
8 | 9 | "net/http"
|
9 | 10 | "strings"
|
10 | 11 | "testing"
|
@@ -41,3 +42,80 @@ func TestCompareDefault(t *testing.T) {
|
41 | 42 | selection := htmlDoc.doc.Find(".choose.branch .filter.dropdown")
|
42 | 43 | assert.Lenf(t, selection.Nodes, 2, "The template has changed")
|
43 | 44 | }
|
| 45 | + |
| 46 | +// Ensure the comparison matches what we expect |
| 47 | +func inspectCompare(t *testing.T, htmlDoc *HTMLDoc, diffCount int, diffChanges []string) { |
| 48 | + selection := htmlDoc.doc.Find("#diff-file-boxes").Children() |
| 49 | + |
| 50 | + assert.Lenf(t, selection.Nodes, diffCount, "Expected %v diffed files, found: %v", diffCount, len(selection.Nodes)) |
| 51 | + |
| 52 | + for _, diffChange := range diffChanges { |
| 53 | + selection = htmlDoc.doc.Find(fmt.Sprintf("[data-new-filename=\"%s\"]", diffChange)) |
| 54 | + assert.Lenf(t, selection.Nodes, 1, "Expected 1 match for [data-new-filename=\"%s\"], found: %v", diffChange, len(selection.Nodes)) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// Git commit graph for repo20 |
| 59 | +// * 8babce9 (origin/remove-files-b) Add a dummy file |
| 60 | +// * b67e43a Delete test.csv and link_hi |
| 61 | +// | * cfe3b3c (origin/remove-files-a) Delete test.csv and link_hi |
| 62 | +// |/ |
| 63 | +// * c8e31bc (origin/add-csv) Add test csv file |
| 64 | +// * 808038d (HEAD -> master, origin/master, origin/HEAD) Added test links |
| 65 | + |
| 66 | +func TestCompareBranches(t *testing.T) { |
| 67 | + defer tests.PrepareTestEnv(t)() |
| 68 | + |
| 69 | + session := loginUser(t, "user2") |
| 70 | + |
| 71 | + // Inderect compare remove-files-b (head) with add-csv (base) branch |
| 72 | + // |
| 73 | + // 'link_hi' and 'test.csv' are deleted, 'test.txt' is added |
| 74 | + req := NewRequest(t, "GET", "/user2/repo20/compare/add-csv...remove-files-b") |
| 75 | + resp := session.MakeRequest(t, req, http.StatusOK) |
| 76 | + htmlDoc := NewHTMLParser(t, resp.Body) |
| 77 | + |
| 78 | + diffCount := 3 |
| 79 | + diffChanges := []string{"link_hi", "test.csv", "test.txt"} |
| 80 | + |
| 81 | + inspectCompare(t, htmlDoc, diffCount, diffChanges) |
| 82 | + |
| 83 | + // Inderect compare remove-files-b (head) with remove-files-a (base) branch |
| 84 | + // |
| 85 | + // 'link_hi' and 'test.csv' are deleted, 'test.txt' is added |
| 86 | + |
| 87 | + req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-a...remove-files-b") |
| 88 | + resp = session.MakeRequest(t, req, http.StatusOK) |
| 89 | + htmlDoc = NewHTMLParser(t, resp.Body) |
| 90 | + |
| 91 | + diffCount = 3 |
| 92 | + diffChanges = []string{"link_hi", "test.csv", "test.txt"} |
| 93 | + |
| 94 | + inspectCompare(t, htmlDoc, diffCount, diffChanges) |
| 95 | + |
| 96 | + // Inderect compare remove-files-a (head) with remove-files-b (base) branch |
| 97 | + // |
| 98 | + // 'link_hi' and 'test.csv' are deleted |
| 99 | + |
| 100 | + req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b...remove-files-a") |
| 101 | + resp = session.MakeRequest(t, req, http.StatusOK) |
| 102 | + htmlDoc = NewHTMLParser(t, resp.Body) |
| 103 | + |
| 104 | + diffCount = 2 |
| 105 | + diffChanges = []string{"link_hi", "test.csv"} |
| 106 | + |
| 107 | + inspectCompare(t, htmlDoc, diffCount, diffChanges) |
| 108 | + |
| 109 | + // Direct compare remove-files-b (head) with remove-files-a (base) branch |
| 110 | + // |
| 111 | + // 'test.txt' is deleted |
| 112 | + |
| 113 | + req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b..remove-files-a") |
| 114 | + resp = session.MakeRequest(t, req, http.StatusOK) |
| 115 | + htmlDoc = NewHTMLParser(t, resp.Body) |
| 116 | + |
| 117 | + diffCount = 1 |
| 118 | + diffChanges = []string{"test.txt"} |
| 119 | + |
| 120 | + inspectCompare(t, htmlDoc, diffCount, diffChanges) |
| 121 | +} |
0 commit comments