Badges / coveralls (push) Successful in 1m1s
Reviewed-on: #33 Co-authored-by: Natercio Moniz <[email protected]>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package html_test
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/nmoniz/any2anexoj/internal/writing"
|
|
htmlwriter "github.com/nmoniz/any2anexoj/internal/writing/html"
|
|
)
|
|
|
|
// TestWriter_RenderTableFragment renders a Portuguese document and asserts
|
|
// the embedded report table fragment carries the shared structure: the
|
|
// translated headers, the totals footer, and the strictly proportional
|
|
// colgroup that keeps HTML columns in the same relation to each other as
|
|
// the terminal layout.
|
|
func TestWriter_RenderTableFragment(t *testing.T) {
|
|
aw := buildTestAggregator(t)
|
|
|
|
localizer, err := writing.NewLocalizer("pt")
|
|
if err != nil {
|
|
t.Fatalf("failed to create localizer: %v", err)
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
hw := htmlwriter.NewWriter(&buf, localizer, "pt")
|
|
|
|
if err := hw.Render(aw); err != nil {
|
|
t.Fatalf("Render returned an error: %v", err)
|
|
}
|
|
got := buf.String()
|
|
|
|
wantSubstrings := []string{
|
|
`<table class="table table-striped table-hover table-bordered" style="table-layout: fixed">`,
|
|
`<colgroup>`,
|
|
`</colgroup>`,
|
|
`<col style="width: 3.03%">`,
|
|
`<col style="width: 12.12%">`,
|
|
`</table>`,
|
|
`<thead>`,
|
|
`</thead>`,
|
|
`<tbody>`,
|
|
`</tbody>`,
|
|
`<tfoot>`,
|
|
`</tfoot>`,
|
|
"Realização",
|
|
"Aquisição",
|
|
"Soma",
|
|
}
|
|
for _, s := range wantSubstrings {
|
|
if !strings.Contains(got, s) {
|
|
t.Errorf("rendered document missing expected substring %q\nGot:\n%s", s, got)
|
|
}
|
|
}
|
|
|
|
// The fragment must be embedded raw, not HTML-escaped.
|
|
if strings.Contains(got, "<table") {
|
|
t.Errorf("table fragment appears to be HTML-escaped; expected raw <table> markup\nGot:\n%s", got)
|
|
}
|
|
}
|