refactor(viewer): consolidate rendering and harden uploads
This commit is contained in:
+52
-17
@@ -125,8 +125,11 @@ func TestCollectColumnsOrdersStatusThenLocationThenIdentity(t *testing.T) {
|
||||
"vendor",
|
||||
"model",
|
||||
"serial_number",
|
||||
"ven:dev",
|
||||
"vendor_id",
|
||||
"device_id",
|
||||
"firmware",
|
||||
"status_at_collection",
|
||||
"status_checked_at",
|
||||
"temperature_c",
|
||||
}
|
||||
|
||||
@@ -170,7 +173,7 @@ func TestCollectColumnsOrdersCPUFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHTMLHidesStatusAtCollection(t *testing.T) {
|
||||
func TestRenderHTMLPreservesStatusMetadata(t *testing.T) {
|
||||
snapshot := []byte(`{
|
||||
"target_host": "hidden-field-host",
|
||||
"hardware": {
|
||||
@@ -198,18 +201,16 @@ func TestRenderHTMLHidesStatusAtCollection(t *testing.T) {
|
||||
}
|
||||
|
||||
text := string(html)
|
||||
if strings.Contains(text, "status_at_collection") {
|
||||
t.Fatalf("expected status_at_collection to be hidden from rendered output")
|
||||
if !strings.Contains(text, "status_at_collection") {
|
||||
t.Fatalf("expected status_at_collection to remain visible")
|
||||
}
|
||||
if !strings.Contains(text, "<th>status_checked_at</th>") {
|
||||
t.Fatalf("expected status_checked_at to remain visible in object sections")
|
||||
}
|
||||
if strings.Contains(text, "<thead>\n <tr>\n <th>status_checked_at</th>") {
|
||||
t.Fatalf("expected status_checked_at to be hidden from table headers")
|
||||
if !strings.Contains(text, "<th>status_checked_at</th>") ||
|
||||
!strings.Contains(text, `<th data-col="status_checked_at">status_checked_at</th>`) {
|
||||
t.Fatal("expected status_checked_at in both object and filterable table")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHTMLCombinesVendorAndDeviceID(t *testing.T) {
|
||||
func TestRenderHTMLPreservesVendorAndDeviceID(t *testing.T) {
|
||||
snapshot := []byte(`{
|
||||
"target_host": "pci-host",
|
||||
"hardware": {
|
||||
@@ -232,14 +233,14 @@ func TestRenderHTMLCombinesVendorAndDeviceID(t *testing.T) {
|
||||
}
|
||||
|
||||
text := string(html)
|
||||
if !strings.Contains(text, "ven:dev") {
|
||||
t.Fatalf("expected combined vendor/device id column to be rendered")
|
||||
if !strings.Contains(text, `<th data-col="vendor_id">vendor_id</th>`) || !strings.Contains(text, `<th data-col="device_id">device_id</th>`) {
|
||||
t.Fatalf("expected source vendor_id and device_id columns to be rendered")
|
||||
}
|
||||
if !strings.Contains(text, "8086:1234") {
|
||||
t.Fatalf("expected vendor/device id value to be rendered as ven:dev")
|
||||
if !strings.Contains(text, "8086") || !strings.Contains(text, "1234") {
|
||||
t.Fatalf("expected source vendor_id and device_id values to be rendered")
|
||||
}
|
||||
if strings.Contains(text, "<th>vendor_id</th>") || strings.Contains(text, "<th>device_id</th>") {
|
||||
t.Fatalf("expected raw vendor_id and device_id columns to be hidden")
|
||||
if strings.Contains(text, "ven:dev") || strings.Contains(text, "8086:1234") {
|
||||
t.Fatalf("expected no synthetic vendor/device field")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +327,7 @@ func TestRenderHTMLAddsSeverityFilterForEventLogs(t *testing.T) {
|
||||
`<span class="status-badge severity-info" role="img" aria-label="Info" title="Info"></span>`,
|
||||
`<span class="status-badge severity-critical" role="img" aria-label="Critical" title="Critical"></span>`,
|
||||
`<th data-col="severity">severity</th>`,
|
||||
"/static/view.js",
|
||||
"static/view.js",
|
||||
} {
|
||||
if !strings.Contains(text, needle) {
|
||||
t.Fatalf("expected rendered html to contain %q", needle)
|
||||
@@ -414,3 +415,37 @@ func TestRenderHTMLDisplaysHardwareContract210Fields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHTMLPreservesUnknownSensorSectionsAndMixedArrays(t *testing.T) {
|
||||
snapshot := []byte(`{
|
||||
"hardware": {
|
||||
"sensors": {
|
||||
"humidity": [{"percent": 41}],
|
||||
"vendor_extension": "raw-sensor-value"
|
||||
},
|
||||
"future_array": [{"known": "object-value"}, "scalar-value", 17]
|
||||
}
|
||||
}`)
|
||||
|
||||
html, err := RenderHTML(snapshot, "Reanimator Chart")
|
||||
if err != nil {
|
||||
t.Fatalf("RenderHTML() error = %v", err)
|
||||
}
|
||||
text := string(html)
|
||||
for _, want := range []string{"Sensors / Humidity", "percent", "41", "Sensors / Vendor Extension", "raw-sensor-value", "Future Array", "known: object-value", "scalar-value", "17"} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("expected rendered HTML to preserve %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHTMLPreservesNonObjectHardwareValue(t *testing.T) {
|
||||
html, err := RenderHTML([]byte(`{"hardware":"unparsed-hardware-value"}`), "Reanimator Chart")
|
||||
if err != nil {
|
||||
t.Fatalf("RenderHTML() error = %v", err)
|
||||
}
|
||||
text := string(html)
|
||||
if !strings.Contains(text, "<th>hardware</th>") || !strings.Contains(text, "unparsed-hardware-value") {
|
||||
t.Fatalf("expected non-object hardware value to remain visible: %s", text)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user