[UI] Adjust trailing EOL behavior for empty file
- Follow up #4835 - Currently for empty files (file size is shown in the file header) the "No EOL" information is being shown, even though it doesn't really make sense to show that for empty files. - Add integration test. - Ref: https://codeberg.org/Codeberg/Community/issues/1612#issuecomment-2169437
This commit is contained in:
parent
3b8ac4388a
commit
e9a89a188e
3 changed files with 33 additions and 28 deletions
|
@ -179,43 +179,47 @@ func TestRepoViewFileLines(t *testing.T) {
|
|||
TreePath: "test-4",
|
||||
ContentReader: strings.NewReader("Really two\nlines\n"),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "empty",
|
||||
ContentReader: strings.NewReader(""),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "seemingly-empty",
|
||||
ContentReader: strings.NewReader("\n"),
|
||||
},
|
||||
})
|
||||
defer f()
|
||||
|
||||
t.Run("No EOL", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", repo.Link()+"/src/branch/main/test-1")
|
||||
testEOL := func(t *testing.T, filename string, hasEOL bool) {
|
||||
t.Helper()
|
||||
req := NewRequestf(t, "GET", "%s/src/branch/main/%s", repo.Link(), filename)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
fileInfo := htmlDoc.Find(".file-info").Text()
|
||||
assert.Contains(t, fileInfo, "No EOL")
|
||||
if hasEOL {
|
||||
assert.NotContains(t, fileInfo, "No EOL")
|
||||
} else {
|
||||
assert.Contains(t, fileInfo, "No EOL")
|
||||
}
|
||||
}
|
||||
|
||||
req = NewRequest(t, "GET", repo.Link()+"/src/branch/main/test-3")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
t.Run("No EOL", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
fileInfo = htmlDoc.Find(".file-info").Text()
|
||||
assert.Contains(t, fileInfo, "No EOL")
|
||||
testEOL(t, "test-1", false)
|
||||
testEOL(t, "test-3", false)
|
||||
})
|
||||
|
||||
t.Run("With EOL", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", repo.Link()+"/src/branch/main/test-2")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
fileInfo := htmlDoc.Find(".file-info").Text()
|
||||
assert.NotContains(t, fileInfo, "No EOL")
|
||||
|
||||
req = NewRequest(t, "GET", repo.Link()+"/src/branch/main/test-4")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
|
||||
fileInfo = htmlDoc.Find(".file-info").Text()
|
||||
assert.NotContains(t, fileInfo, "No EOL")
|
||||
testEOL(t, "test-2", true)
|
||||
testEOL(t, "test-4", true)
|
||||
testEOL(t, "empty", true)
|
||||
testEOL(t, "seemingly-empty", true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue