package web

import (
	"bytes"
	"strings"
	"testing"
)

// F5 (2026-07-13): USB drives never show the rotational class hint — the card already carries
// the USB tag, and only Observe-sourced drives ever had class set, so USB cards flapped between
// "lassú" and nothing depending on the data source. The guard is client-side (classTag runs on
// /api/disks JSON), so the pin asserts the rendered page ships the guard FIRST in classTag.
// Companion red-proof: remove the `d.type==='usb'` guard line → FAIL.
func TestStorageTemplate_USBClassBadgeSuppressed(t *testing.T) {
	s := testServer(t)
	s.loadTemplates()
	var buf bytes.Buffer
	if err := s.tmpl.ExecuteTemplate(&buf, "storage", map[string]interface{}{
		"Page": "storage", "Title": "Tárolók",
	}); err != nil {
		t.Fatalf("render storage: %v", err)
	}
	html := buf.String()

	guard := strings.Index(html, `if(d.type==='usb') return '';`)
	slow := strings.Index(html, `tag-off">lassú`)
	if guard < 0 {
		t.Fatal("classTag USB guard missing from the storage page")
	}
	if slow < 0 {
		t.Fatal("classTag slow-branch missing — the guard has nothing to suppress (test needs updating)")
	}
	if guard > slow {
		t.Fatalf("USB guard (at %d) must run BEFORE the class branches (at %d)", guard, slow)
	}
}
