1package component
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7)
8
9func TestOmniboxFavoriteStarSize(t *testing.T) {
10 assert.Equal(t, 18, favoriteStarSize(1.0))
11 assert.Equal(t, 27, favoriteStarSize(1.5))
12}
13
14func TestOmniboxFavoriteStarVisibility(t *testing.T) {
15 assert.True(t, shouldShowFavoriteStar(Suggestion{IsFavorite: true}))
16 assert.False(t, shouldShowFavoriteStar(Suggestion{IsFavorite: false}))
17}
18
19func TestShouldApplyEmptyResultsState(t *testing.T) {
20 tests := []struct {
21 name string
22 rowCount int
23 visible bool
24 want bool
25 }{
26 {name: "negative rows uses empty state", rowCount: -1, visible: false, want: true},
27 {name: "zero rows uses empty state", rowCount: 0, visible: false, want: true},
28 {name: "positive rows clears empty state", rowCount: 2, visible: true, want: false},
29 }
30
31 for _, tt := range tests {
32 t.Run(tt.name, func(t *testing.T) {
33 assert.Equal(t, tt.want, shouldApplyEmptyResultsState(tt.rowCount, tt.visible))
34 })
35 }
36}
37
38func TestResolveFavoriteRowIndicatorUpdate(t *testing.T) {
39 tests := []struct {
40 name string
41 mode ViewMode
42 index int
43 expectedURL string
44 suggestions []Suggestion
45 isFavorite bool
46 want favoriteRowIndicatorUpdate
47 }{
48 {
49 name: "matching history row keeps update and shows star",
50 mode: ViewModeHistory,
51 index: 0,
52 expectedURL: "https://example.com",
53 suggestions: []Suggestion{{URL: "https://example.com"}},
54 isFavorite: true,
55 want: favoriteRowIndicatorUpdate{Apply: true, ShowStarSlot: true},
56 },
57 {
58 name: "matching history row keeps update and hides star when removed",
59 mode: ViewModeHistory,
60 index: 0,
61 expectedURL: "https://example.com",
62 suggestions: []Suggestion{{URL: "https://example.com"}},
63 isFavorite: false,
64 want: favoriteRowIndicatorUpdate{Apply: true, ShowStarSlot: false},
65 },
66 {
67 name: "mismatched URL skips stale row update",
68 mode: ViewModeHistory,
69 index: 0,
70 expectedURL: "https://expected.example.com",
71 suggestions: []Suggestion{{URL: "https://current.example.com"}},
72 isFavorite: true,
73 want: favoriteRowIndicatorUpdate{},
74 },
75 {
76 name: "favorites mode never applies history row update",
77 mode: ViewModeFavorites,
78 index: 0,
79 expectedURL: "https://example.com",
80 suggestions: []Suggestion{{URL: "https://example.com"}},
81 isFavorite: true,
82 want: favoriteRowIndicatorUpdate{},
83 },
84 {
85 name: "out of range index skips update",
86 mode: ViewModeHistory,
87 index: 1,
88 expectedURL: "https://example.com",
89 suggestions: []Suggestion{{URL: "https://example.com"}},
90 isFavorite: true,
91 want: favoriteRowIndicatorUpdate{},
92 },
93 }
94
95 for _, tt := range tests {
96 t.Run(tt.name, func(t *testing.T) {
97 got := resolveFavoriteRowIndicatorUpdate(tt.mode, tt.index, tt.expectedURL, tt.suggestions, tt.isFavorite)
98 assert.Equal(t, tt.want, got)
99 })
100 }
101}