fix(prefs): persist favicon choice and apply to HTML results
- Save favicon cookie on POST /preferences; reflect selection in template - Add getFaviconService helper; pass favicon service into FromResponse - Compute ResultView.FaviconIconURL (none/google/duckduckgo/self proxy) - Update result_item and video_item templates; add httpapi/views tests Made-with: Cursor
This commit is contained in:
parent
518215f62e
commit
90ea4c9f56
7 changed files with 171 additions and 43 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package views
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/metamorphosis-dev/samsa/internal/contracts"
|
||||
|
|
@ -37,7 +38,7 @@ func mockEmptyResponse() contracts.SearchResponse {
|
|||
|
||||
func TestFromResponse_Basic(t *testing.T) {
|
||||
resp := mockSearchResponse("samsa trial", 42)
|
||||
data := FromResponse(resp, "samsa trial", 1, "", "", "")
|
||||
data := FromResponse(resp, "samsa trial", 1, "", "", "", "none")
|
||||
|
||||
if data.Query != "samsa trial" {
|
||||
t.Errorf("expected query 'samsa trial', got %q", data.Query)
|
||||
|
|
@ -55,7 +56,7 @@ func TestFromResponse_Basic(t *testing.T) {
|
|||
|
||||
func TestFromResponse_Pagination(t *testing.T) {
|
||||
resp := mockSearchResponse("test", 100)
|
||||
data := FromResponse(resp, "test", 3, "", "", "")
|
||||
data := FromResponse(resp, "test", 3, "", "", "", "none")
|
||||
|
||||
if data.PrevPage != 2 {
|
||||
t.Errorf("expected PrevPage 2, got %d", data.PrevPage)
|
||||
|
|
@ -80,7 +81,7 @@ func TestFromResponse_Pagination(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFromResponse_Empty(t *testing.T) {
|
||||
data := FromResponse(mockEmptyResponse(), "", 1, "", "", "")
|
||||
data := FromResponse(mockEmptyResponse(), "", 1, "", "", "", "none")
|
||||
|
||||
if data.NumberOfResults != 0 {
|
||||
t.Errorf("expected 0 results, got %d", data.NumberOfResults)
|
||||
|
|
@ -90,6 +91,31 @@ func TestFromResponse_Empty(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFromResponse_FaviconIconURL(t *testing.T) {
|
||||
u := "https://example.com/path"
|
||||
resp := contracts.SearchResponse{
|
||||
Query: "q",
|
||||
NumberOfResults: 1,
|
||||
Results: []contracts.MainResult{{Title: "t", URL: &u, Engine: "bing"}},
|
||||
Answers: []map[string]any{},
|
||||
Corrections: []string{},
|
||||
Infoboxes: []map[string]any{},
|
||||
Suggestions: []string{},
|
||||
UnresponsiveEngines: [][2]string{},
|
||||
}
|
||||
data := FromResponse(resp, "q", 1, "", "", "", "google")
|
||||
if len(data.Results) != 1 {
|
||||
t.Fatalf("expected 1 result, got %d", len(data.Results))
|
||||
}
|
||||
got := data.Results[0].FaviconIconURL
|
||||
if got == "" || !strings.Contains(got, "google.com/s2/favicons") {
|
||||
t.Fatalf("expected google favicon URL, got %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "example.com") {
|
||||
t.Fatalf("expected domain in favicon URL, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsHTMXRequest(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue