test(omnibox): harden follow-up assertions
Stabilize the new omnibox tests after final review by using cleanup hooks, avoiding whitespace-fragile CSS checks, and keeping gateway test mutation behind a helper.
- commit
- 5d3e5a8c5bbc382e1391c3a62a3aa887bca51949
- author
- brice · · 2026-04-12 04:20 UTC
- parent
- 7e507f9
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +16 -5
M internal/infrastructure/config/omnibox_preferences_gateway_test.go +11 -1
| @@ -24,7 +24,7 @@ func TestOmniboxPreferencesGateway_SaveOmniboxInitialBehavior_UpdatesBehavior(t | |||
| 24 | 24 | func TestOmniboxPreferencesGateway_SaveOmniboxInitialBehavior_PreservesDefaultSearchEngine(t *testing.T) { | |
| 25 | 25 | configHome := t.TempDir() | |
| 26 | 26 | mgr := newTestOmniboxPreferencesGatewayManager(t, configHome) | |
| 27 | - | mgr.config.DefaultSearchEngine = "https://example.com/search?q=%s" | |
| 27 | + | setTestManagerDefaultSearchEngine(t, mgr, "https://example.com/search?q=%s") | |
| 28 | 28 | gateway := NewOmniboxPreferencesGateway(mgr) | |
| 29 | 29 | ||
| 30 | 30 | require.NoError(t, gateway.SaveOmniboxInitialBehavior(context.Background(), entity.OmniboxInitialBehaviorMostVisited)) | |
| @@ -48,3 +48,13 @@ func newTestOmniboxPreferencesGatewayManager(t *testing.T, configHome string) *M | |||
| 48 | 48 | ||
| 49 | 49 | return mgr | |
| 50 | 50 | } | |
| 51 | + | ||
| 52 | + | func setTestManagerDefaultSearchEngine(t *testing.T, mgr *Manager, value string) { | |
| 53 | + | t.Helper() | |
| 54 | + | ||
| 55 | + | mgr.mu.Lock() | |
| 56 | + | defer mgr.mu.Unlock() | |
| 57 | + | ||
| 58 | + | require.NotNil(t, mgr.config) | |
| 59 | + | mgr.config.DefaultSearchEngine = value | |
| 60 | + | } | |
| @@ -24,7 +24,7 @@ func TestOmniboxPreferencesGateway_SaveOmniboxInitialBehavior_UpdatesBehavior(t | |||||
| 24 | func TestOmniboxPreferencesGateway_SaveOmniboxInitialBehavior_PreservesDefaultSearchEngine(t *testing.T) { | 24 | func TestOmniboxPreferencesGateway_SaveOmniboxInitialBehavior_PreservesDefaultSearchEngine(t *testing.T) { | ||
| 25 | configHome := t.TempDir() | 25 | configHome := t.TempDir() | ||
| 26 | mgr := newTestOmniboxPreferencesGatewayManager(t, configHome) | 26 | mgr := newTestOmniboxPreferencesGatewayManager(t, configHome) | ||
| 27 | - | mgr.config.DefaultSearchEngine = "https://example.com/search?q=%s" | 27 | + | setTestManagerDefaultSearchEngine(t, mgr, "https://example.com/search?q=%s") |
| 28 | gateway := NewOmniboxPreferencesGateway(mgr) | 28 | gateway := NewOmniboxPreferencesGateway(mgr) | ||
| 29 | 29 | ||||
| 30 | require.NoError(t, gateway.SaveOmniboxInitialBehavior(context.Background(), entity.OmniboxInitialBehaviorMostVisited)) | 30 | require.NoError(t, gateway.SaveOmniboxInitialBehavior(context.Background(), entity.OmniboxInitialBehaviorMostVisited)) | ||
| @@ -48,3 +48,13 @@ func newTestOmniboxPreferencesGatewayManager(t *testing.T, configHome string) *M | |||||
| 48 | 48 | ||||
| 49 | return mgr | 49 | return mgr | ||
| 50 | } | 50 | } | ||
| 51 | + | ||||
| 52 | + | func setTestManagerDefaultSearchEngine(t *testing.T, mgr *Manager, value string) { | |||
| 53 | + | t.Helper() | |||
| 54 | + | ||||
| 55 | + | mgr.mu.Lock() | |||
| 56 | + | defer mgr.mu.Unlock() | |||
| 57 | + | ||||
| 58 | + | require.NotNil(t, mgr.config) | |||
| 59 | + | mgr.config.DefaultSearchEngine = value | |||
| 60 | + | } | |||
M internal/ui/component/omnibox_initial_behavior_toggle_test.go +2 -2
| @@ -21,9 +21,9 @@ func TestHandleKeyPress_CtrlRTriggersInitialBehaviorToggle(t *testing.T) { | |||
| 21 | 21 | loadInitialHistoryFn = func(*Omnibox, uint64) { | |
| 22 | 22 | refreshCalls++ | |
| 23 | 23 | } | |
| 24 | - | defer func() { | |
| 24 | + | t.Cleanup(func() { | |
| 25 | 25 | loadInitialHistoryFn = origLoadInitialHistoryFn | |
| 26 | - | }() | |
| 26 | + | }) | |
| 27 | 27 | ||
| 28 | 28 | if got := o.handleKeyPress(uint(gdk.KEY_r), 0, gdk.ControlMaskValue); !got { | |
| 29 | 29 | t.Fatalf("handleKeyPress Ctrl+R = false, want true") | |
| @@ -21,9 +21,9 @@ func TestHandleKeyPress_CtrlRTriggersInitialBehaviorToggle(t *testing.T) { | |||||
| 21 | loadInitialHistoryFn = func(*Omnibox, uint64) { | 21 | loadInitialHistoryFn = func(*Omnibox, uint64) { | ||
| 22 | refreshCalls++ | 22 | refreshCalls++ | ||
| 23 | } | 23 | } | ||
| 24 | - | defer func() { | 24 | + | t.Cleanup(func() { |
| 25 | loadInitialHistoryFn = origLoadInitialHistoryFn | 25 | loadInitialHistoryFn = origLoadInitialHistoryFn | ||
| 26 | - | }() | 26 | + | }) |
| 27 | 27 | ||||
| 28 | if got := o.handleKeyPress(uint(gdk.KEY_r), 0, gdk.ControlMaskValue); !got { | 28 | if got := o.handleKeyPress(uint(gdk.KEY_r), 0, gdk.ControlMaskValue); !got { | ||
| 29 | t.Fatalf("handleKeyPress Ctrl+R = false, want true") | 29 | t.Fatalf("handleKeyPress Ctrl+R = false, want true") | ||
M internal/ui/theme/css_test.go +3 -2
| @@ -58,10 +58,11 @@ func TestGenerateCSS_OmniboxHeaderBadgeUsesPassiveNeutralChipStyling(t *testing. | |||
| 58 | 58 | t.Fatalf("expected omnibox header badge hover styling to stay neutral while hinting interactivity") | |
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | - | if strings.Contains(css, ".omnibox-header-badge {\n\tbackground-color: alpha(var(--accent),") { | |
| 61 | + | badgeBlock := regexp.MustCompile(`(?s)\.omnibox-header-badge\s*\{[^}]*\}`).FindString(css) | |
| 62 | + | if strings.Contains(badgeBlock, "background-color: alpha(var(--accent)") { | |
| 62 | 63 | t.Fatalf("expected omnibox header badge resting state to avoid accent-based styling") | |
| 63 | 64 | } | |
| 64 | - | if strings.Contains(css, ".omnibox-header-badge {\n\tcolor: var(--accent);") { | |
| 65 | + | if strings.Contains(badgeBlock, "color: var(--accent)") { | |
| 65 | 66 | t.Fatalf("expected omnibox header badge resting text to avoid accent color") | |
| 66 | 67 | } | |
| 67 | 68 | } | |
| @@ -58,10 +58,11 @@ func TestGenerateCSS_OmniboxHeaderBadgeUsesPassiveNeutralChipStyling(t *testing. | |||||
| 58 | t.Fatalf("expected omnibox header badge hover styling to stay neutral while hinting interactivity") | 58 | t.Fatalf("expected omnibox header badge hover styling to stay neutral while hinting interactivity") | ||
| 59 | } | 59 | } | ||
| 60 | 60 | ||||
| 61 | - | if strings.Contains(css, ".omnibox-header-badge {\n\tbackground-color: alpha(var(--accent),") { | 61 | + | badgeBlock := regexp.MustCompile(`(?s)\.omnibox-header-badge\s*\{[^}]*\}`).FindString(css) |
| 62 | + | if strings.Contains(badgeBlock, "background-color: alpha(var(--accent)") { | |||
| 62 | t.Fatalf("expected omnibox header badge resting state to avoid accent-based styling") | 63 | t.Fatalf("expected omnibox header badge resting state to avoid accent-based styling") | ||
| 63 | } | 64 | } | ||
| 64 | - | if strings.Contains(css, ".omnibox-header-badge {\n\tcolor: var(--accent);") { | 65 | + | if strings.Contains(badgeBlock, "color: var(--accent)") { |
| 65 | t.Fatalf("expected omnibox header badge resting text to avoid accent color") | 66 | t.Fatalf("expected omnibox header badge resting text to avoid accent color") | ||
| 66 | } | 67 | } | ||
| 67 | } | 68 | } | ||