better domain isolation
Generate check / check-changes (pull_request) Successful in 2s
Generate check / verify-generate (pull_request) Skipped
Quality / check-changes (pull_request) Successful in 2s
Quality / static-checks (pull_request) Failing after 13s
Quality / run-tests (pull_request) Failing after 54s
Generate check / check-changes (pull_request) Successful in 2s
Generate check / verify-generate (pull_request) Skipped
Quality / check-changes (pull_request) Successful in 2s
Quality / static-checks (pull_request) Failing after 13s
Quality / run-tests (pull_request) Failing after 54s
This commit is contained in:
1 parent
e167627ac3
commit
5c146ad60f
10 files changed
+342
-242
No files matched your search
@@ -0,0 +1,60 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user