Skip to content

Commit 56d2535

Browse files
committed
improve test for exporting of issues: check content of excel file
1 parent 7f7ddff commit 56d2535

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tests/integration/issue_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package integration
55

66
import (
7+
"bytes"
78
"fmt"
89
"html/template"
910
"net/http"
@@ -29,6 +30,7 @@ import (
2930

3031
"github.com/PuerkitoBio/goquery"
3132
"github.com/stretchr/testify/assert"
33+
"github.com/xuri/excelize/v2"
3234
)
3335

3436
func getIssuesSelection(t testing.TB, htmlDoc *HTMLDoc) *goquery.Selection {
@@ -374,7 +376,7 @@ func TestIssueReaction(t *testing.T) {
374376
func TestIssueListExport(t *testing.T) {
375377
defer tests.PrepareTestEnv(t)()
376378
session := loginUser(t, "user2")
377-
_ = testNewIssue(t, session, "user2", "repo1", "Title", "Description")
379+
_ = testNewIssue(t, session, "user2", "repo1", "Title1", "Description1")
378380
_ = testNewIssue(t, session, "user2", "repo1", "Title2", "Description2")
379381
_ = testNewIssue(t, session, "user2", "repo1", "Title3", "Description3")
380382

@@ -390,6 +392,41 @@ func TestIssueListExport(t *testing.T) {
390392
cd := resp.Header().Get("Content-Disposition")
391393
assert.Contains(t, cd, "attachment")
392394
assert.True(t, strings.Contains(cd, ".xlsx"))
395+
396+
// open bytes as XLSX with excelize
397+
data := resp.Body.Bytes()
398+
f, err := excelize.OpenReader(bytes.NewReader(data))
399+
assert.NoError(t, err)
400+
defer func() { _ = f.Close() }()
401+
402+
// get first sheet and rows
403+
sheets := f.GetSheetList()
404+
assert.NotEmpty(t, sheets)
405+
rows, err := f.GetRows(sheets[0])
406+
assert.NoError(t, err)
407+
// there should be at least a header row + our three issues
408+
assert.GreaterOrEqual(t, len(rows), 4)
409+
410+
// ensure header has some cells and that our created titles appear somewhere
411+
foundTitle1, foundTitle2, foundTitle3 := false, false, false
412+
if len(rows) > 0 {
413+
for _, row := range rows {
414+
for _, cell := range row {
415+
if strings.Contains(cell, "Title1") {
416+
foundTitle1 = true
417+
}
418+
if strings.Contains(cell, "Title2") {
419+
foundTitle2 = true
420+
}
421+
if strings.Contains(cell, "Title3") {
422+
foundTitle3 = true
423+
}
424+
}
425+
}
426+
}
427+
assert.True(t, foundTitle1, "Exported XLSX should contain Title1")
428+
assert.True(t, foundTitle2, "Exported XLSX should contain Title2")
429+
assert.True(t, foundTitle3, "Exported XLSX should contain Title3")
393430
}
394431

395432
func TestIssueCrossReference(t *testing.T) {

0 commit comments

Comments
 (0)