package webserver
import (
"io/fs"
"strings"
"testing"
"testing/fstest"
)
func TestEmbeddedWebClientRoot(t *testing.T) {
content, err := fs.Sub(webFS, "chess-client-web")
if err != nil {
t.Fatal(err)
}
for _, name := range []string{"index.html", "app.js", "style.css"} {
data, err := fs.ReadFile(content, name)
if err != nil {
t.Errorf("read embedded %s: %v", name, err)
}
if len(data) == 0 {
t.Errorf("embedded %s is empty", name)
}
}
}
func TestIndexHTMLSetsAPIBase(t *testing.T) {
content, err := fs.Sub(webFS, "chess-client-web")
if err != nil {
t.Fatal(err)
}
for apiURL, want := range map[string]string{
"http://localhost:8080": ``,
"twice": ``,
} {
content := fstest.MapFS{"index.html": {Data: []byte(page)}}
if _, err := indexHTML(content, "http://localhost:8080"); err == nil {
t.Errorf("%s: no error", name)
}
}
}