package web import ( "bytes" "net/http" "net/http/httptest" "strings" "testing" "gitea.mynodes.xyz/ilker/llmgw/internal/store" ) func TestTheChatPageSpeaksTurkishWhenAsked(t *testing.T) { h := Chat(store.User{Email: "a@example.com"}, []ChatModel{{Name: "qwen"}, {Name: "big-model", Simulated: true}}, nil, "", "v1", ChatKnowledge{Collections: []ChatCollection{{ID: "kb_x", Label: "politikalar"}}, Default: "politikalar"}) r := httptest.NewRequest(http.MethodGet, "http://x/chat", nil) r.Header.Set("Accept-Language", "tr-TR,tr;q=0.9") w := httptest.NewRecorder() h(w, r) if w.Code != http.StatusOK { t.Fatalf("status %d", w.Code) } page := w.Body.String() for _, want := range []string{ ``, "

Sohbet

", ">big-model (benzetim)<", "Yeni sohbet", `placeholder="Bir şey sorun…"`, `0,7`, // The script's own words come from the catalogue too. `"Uzunluk sınırında kesildi — devam etmesini isteyin."`, `decimal: ","`, // The documents picker, with the default named. "Belgeler", ``, ``, ``, `"Kaynaklar:"`, } { if !strings.Contains(page, want) { t.Errorf("the Turkish chat page does not have %q", want) } } for _, not := range []string{"New conversation", "Cut off at the length limit", "Ask something", "Documents", "Sources:"} { if strings.Contains(page, not) { t.Errorf("the Turkish chat page still says %q", not) } } } func TestTheChatDownloadRefusesInTheReadersLanguage(t *testing.T) { r := httptest.NewRequest(http.MethodPost, "/chat/download", strings.NewReader(`{"content":"no code here"}`)) r.AddCookie(&http.Cookie{Name: langCookie, Value: "tr"}) w := httptest.NewRecorder() CodeArchive(1<<20)(w, r) if w.Code != http.StatusBadRequest || !strings.Contains(w.Body.String(), "indirilecek kod yok") { t.Errorf("%d %q", w.Code, w.Body.String()) } } func TestTheAboutPageSpeaksTurkishWhenAsked(t *testing.T) { code, body := get(t, About("v1.2.3"), "http://llmgw.example/about", map[string]string{"Accept-Language": "tr"}) if code != http.StatusOK { t.Fatalf("status %d", code) } for _, want := range []string{ ``, `Bu ağ geçidi`, "Kendi GPU'larınızın önünde tek bir uç nokta.", "Sıfırdan ilk isteğe", "Sağlama toplamları", // The configurations are shown as they are. "reverse_proxy", "proxy_read_timeout", } { if !strings.Contains(body, want) { t.Errorf("the Turkish about page does not have %q", want) } } if strings.Contains(body, "What it does") { t.Error("the Turkish about page still has English headings") } // The published website is English whatever anyone's browser says. d := NewAboutData("v1.2.3") d.Site = true var b bytes.Buffer if err := RenderAbout(&b, d); err != nil { t.Fatal(err) } if !strings.Contains(b.String(), "What it does") || strings.Contains(b.String(), "Ne yapar") { t.Error("the website is not in English") } }