Files
any2anexoj/internal/writing/html/fragment_test.go
T
natercio 3dfc7bd6a7
Generate check / check-changes (pull_request) Successful in 26s
Generate check / verify-generate (pull_request) Skipped
Quality / check-changes (pull_request) Successful in 2s
Quality / static-checks (pull_request) Failing after 16s
Quality / run-tests (pull_request) Failing after 56s
better domain isolation
2026-10-05 14:56:27 +01:00

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, "&lt;table") {
t.Errorf("table fragment appears to be HTML-escaped; expected raw <table> markup\nGot:\n%s", got)
}
}