From ed104ec5e01b4efaafd4073973cffebf04ec0515 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Wed, 30 Jul 2025 21:52:02 -0400 Subject: [PATCH] Ensure settings are being adjusted via settings profile selector (#35382) This PR just pins down the behavior of the settings profile selector by checking a single setting, `buffer_font_size`, as options in the selector are changed / selected. Release Notes: - N/A --- Cargo.lock | 2 + crates/settings_profile_selector/Cargo.toml | 2 + .../src/settings_profile_selector.rs | 89 +++++++++++++------ 3 files changed, 67 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 755f1ef55b..7d7e230591 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14709,6 +14709,7 @@ dependencies = [ name = "settings_profile_selector" version = "0.1.0" dependencies = [ + "client", "editor", "fuzzy", "gpui", @@ -14718,6 +14719,7 @@ dependencies = [ "project", "serde_json", "settings", + "theme", "ui", "workspace", "workspace-hack", diff --git a/crates/settings_profile_selector/Cargo.toml b/crates/settings_profile_selector/Cargo.toml index 969fa7be9c..189272e54b 100644 --- a/crates/settings_profile_selector/Cargo.toml +++ b/crates/settings_profile_selector/Cargo.toml @@ -23,6 +23,7 @@ workspace.workspace = true zed_actions.workspace = true [dev-dependencies] +client = { workspace = true, features = ["test-support"] } editor = { workspace = true, features = ["test-support"] } gpui = { workspace = true, features = ["test-support"] } language = { workspace = true, features = ["test-support"] } @@ -30,4 +31,5 @@ menu.workspace = true project = { workspace = true, features = ["test-support"] } serde_json.workspace = true settings = { workspace = true, features = ["test-support"] } +theme = { workspace = true, features = ["test-support"] } workspace = { workspace = true, features = ["test-support"] } diff --git a/crates/settings_profile_selector/src/settings_profile_selector.rs b/crates/settings_profile_selector/src/settings_profile_selector.rs index c7239ad434..698733c010 100644 --- a/crates/settings_profile_selector/src/settings_profile_selector.rs +++ b/crates/settings_profile_selector/src/settings_profile_selector.rs @@ -283,12 +283,15 @@ fn display_name(profile_name: &Option) -> String { #[cfg(test)] mod tests { use super::*; + use client; use editor; use gpui::{TestAppContext, UpdateGlobal, VisualTestContext}; use language; use menu::{Cancel, Confirm, SelectNext, SelectPrevious}; use project::{FakeFs, Project}; use serde_json::json; + use settings::Settings; + use theme::{self, ThemeSettings}; use workspace::{self, AppState}; use zed_actions::settings_profile_selector; @@ -298,6 +301,12 @@ mod tests { ) -> (Entity, &mut VisualTestContext) { cx.update(|cx| { let state = AppState::test(cx); + let settings_store = SettingsStore::test(cx); + cx.set_global(settings_store); + settings::init(cx); + theme::init(theme::LoadThemes::JustBase, cx); + ThemeSettings::register(cx); + client::init_settings(cx); language::init(cx); super::init(cx); editor::init(cx); @@ -309,7 +318,8 @@ mod tests { cx.update(|cx| { SettingsStore::update_global(cx, |store, cx| { let settings_json = json!({ - "profiles": profiles_json + "buffer_font_size": 10.0, + "profiles": profiles_json, }); store @@ -325,6 +335,8 @@ mod tests { cx.update(|_, cx| { assert!(!cx.has_global::()); + let theme_settings = ThemeSettings::get_global(cx); + assert_eq!(theme_settings.buffer_font_size(cx).0, 10.0); }); (workspace, cx) @@ -347,32 +359,37 @@ mod tests { #[gpui::test] async fn test_settings_profile_selector_state(cx: &mut TestAppContext) { + let demo_videos_profile_name = "Demo Videos".to_string(); + let classroom_and_streaming_profile_name = "Classroom / Streaming".to_string(); + let profiles_json = json!({ - "Demo Videos": { - "buffer_font_size": 14 + demo_videos_profile_name.clone(): { + "buffer_font_size": 15.0 }, - "Classroom / Streaming": { - "buffer_font_size": 16, - "vim_mode": true + classroom_and_streaming_profile_name.clone(): { + "buffer_font_size": 20.0, } }); let (workspace, cx) = init_test(profiles_json.clone(), cx).await; cx.dispatch_action(settings_profile_selector::Toggle); - let picker = active_settings_profile_picker(&workspace, cx); picker.read_with(cx, |picker, cx| { assert_eq!(picker.delegate.matches.len(), 3); - assert_eq!(picker.delegate.matches[0].string, "Disabled"); - assert_eq!(picker.delegate.matches[1].string, "Classroom / Streaming"); - assert_eq!(picker.delegate.matches[2].string, "Demo Videos"); + assert_eq!(picker.delegate.matches[0].string, display_name(&None)); + assert_eq!( + picker.delegate.matches[1].string, + classroom_and_streaming_profile_name + ); + assert_eq!(picker.delegate.matches[2].string, demo_videos_profile_name); assert_eq!(picker.delegate.matches.get(3), None); assert_eq!(picker.delegate.selected_index, 0); assert_eq!(picker.delegate.selected_profile_name, None); assert_eq!(cx.try_global::(), None); + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0); }); cx.dispatch_action(Confirm); @@ -389,20 +406,23 @@ mod tests { assert_eq!(picker.delegate.selected_index, 1); assert_eq!( picker.delegate.selected_profile_name, - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name.clone()) ); assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name.clone()) ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0); }); cx.dispatch_action(Cancel); cx.update(|_, cx| { assert_eq!(cx.try_global::(), None); + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0); }); cx.dispatch_action(settings_profile_selector::Toggle); @@ -414,14 +434,16 @@ mod tests { assert_eq!(picker.delegate.selected_index, 1); assert_eq!( picker.delegate.selected_profile_name, - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name.clone()) ); assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name.clone()) ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0); }); cx.dispatch_action(SelectNext); @@ -430,14 +452,16 @@ mod tests { assert_eq!(picker.delegate.selected_index, 2); assert_eq!( picker.delegate.selected_profile_name, - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name.clone()) ); assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name.clone()) ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0); }); cx.dispatch_action(Confirm); @@ -446,8 +470,9 @@ mod tests { assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name.clone()) ); + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0); }); cx.dispatch_action(settings_profile_selector::Toggle); @@ -457,14 +482,15 @@ mod tests { assert_eq!(picker.delegate.selected_index, 2); assert_eq!( picker.delegate.selected_profile_name, - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name.clone()) ); assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name.clone()) ); + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0); }); cx.dispatch_action(SelectPrevious); @@ -473,14 +499,16 @@ mod tests { assert_eq!(picker.delegate.selected_index, 1); assert_eq!( picker.delegate.selected_profile_name, - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name.clone()) ); assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name.clone()) ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0); }); cx.dispatch_action(Cancel); @@ -489,8 +517,10 @@ mod tests { assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name.clone()) ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0); }); cx.dispatch_action(settings_profile_selector::Toggle); @@ -500,14 +530,16 @@ mod tests { assert_eq!(picker.delegate.selected_index, 2); assert_eq!( picker.delegate.selected_profile_name, - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name.clone()) ); assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Demo Videos".to_string()) + Some(demo_videos_profile_name) ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 15.0); }); cx.dispatch_action(SelectPrevious); @@ -516,14 +548,16 @@ mod tests { assert_eq!(picker.delegate.selected_index, 1); assert_eq!( picker.delegate.selected_profile_name, - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name.clone()) ); assert_eq!( cx.try_global::() .map(|p| p.0.clone()), - Some("Classroom / Streaming".to_string()) + Some(classroom_and_streaming_profile_name) ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 20.0); }); cx.dispatch_action(SelectPrevious); @@ -537,12 +571,15 @@ mod tests { .map(|p| p.0.clone()), None ); + + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0); }); cx.dispatch_action(Confirm); cx.update(|_, cx| { assert_eq!(cx.try_global::(), None); + assert_eq!(ThemeSettings::get_global(cx).buffer_font_size(cx).0, 10.0); }); } }