Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
settings_ui: Fix layout issues with recently created GitHub accounts (#63630)
tidely59b0c714ff05
diff --git a/Cargo.lock b/Cargo.lockindex 717553b4059..eec537b2dfa 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -16575,6 +16575,7 @@ dependencies = ["itertools 0.14.0","language","language_model",+ "language_models","log","menu","paths",diff --git a/crates/language_models/Cargo.toml b/crates/language_models/Cargo.tomlindex d24f757f8e5..b055aa9ee44 100644--- a/crates/language_models/Cargo.toml+++ b/crates/language_models/Cargo.toml@@ -11,6 +11,9 @@ workspace = true[lib]path = "src/language_models.rs"+[features]+test-support = []+[dependencies]ai_onboarding.workspace = trueasync-lock.workspace = truediff --git a/crates/language_models/src/provider/cloud.rs b/crates/language_models/src/provider/cloud.rsindex 06131314eef..74d71d1ba95 100644--- a/crates/language_models/src/provider/cloud.rs+++ b/crates/language_models/src/provider/cloud.rs@@ -436,6 +436,24 @@ struct ZedAiConfiguration {sign_in_callback: Arc<dyn Fn(&mut Window, &mut App) + Send + Sync>,}+#[cfg(any(test, feature = "test-support"))]+pub mod test_support {+ use super::*;++ pub fn young_account_configuration() -> AnyElement {+ ZedAiConfiguration {+ is_connected: true,+ plan: Some(Plan::ZedBusiness),+ is_zed_model_provider_enabled: true,+ eligible_for_trial: false,+ account_too_young: true,+ compact: true,+ sign_in_callback: Arc::new(|_, _| {}),+ }+ .into_any_element()+ }+}+fn zed_ai_description(is_connected: bool,plan: Option<Plan>,@@ -538,7 +556,10 @@ impl RenderOnce for ZedAiConfiguration {v_flex().gap_2()- .when(!self.compact, |this| this.w_full())+ .debug_selector(|| "zed-ai-configuration".into())+ .when(!self.compact || self.account_too_young, |this| {+ this.w_full()+ }).map(|this| {if self.account_too_young {this.child(YoungAccountBanner).child(diff --git a/crates/settings_ui/Cargo.toml b/crates/settings_ui/Cargo.tomlindex b3e7acd324d..b854811fcdf 100644--- a/crates/settings_ui/Cargo.toml+++ b/crates/settings_ui/Cargo.toml@@ -78,6 +78,7 @@ zed_credentials_provider.workspace = truefs = { workspace = true, features = ["test-support"] }futures.workspace = truegpui = { workspace = true, features = ["test-support"] }+language_models = { workspace = true, features = ["test-support"] }paths.workspace = truepretty_assertions.workspace = trueproject = { workspace = true, features = ["test-support"] }diff --git a/crates/settings_ui/src/pages/llm_providers_page.rs b/crates/settings_ui/src/pages/llm_providers_page.rsindex bac9b7abb06..2717d1cd591 100644--- a/crates/settings_ui/src/pages/llm_providers_page.rs+++ b/crates/settings_ui/src/pages/llm_providers_page.rs@@ -324,8 +324,10 @@ fn render_inline_body(provider_name: SharedString,title: Option<SharedString>,description: Option<InlineDescription>,- view: AnyView,+ view: impl IntoElement,) -> AnyElement {+ let view = view.into_any_element();+if title.is_none() && description.is_none() {return v_flex().pt_1()@@ -346,12 +348,20 @@ fn render_inline_body(.w_full().min_w_0().max_w_1_2()+ .debug_selector(|| "inline-provider-description".into()).when_some(title, |this, title| this.child(Label::new(title))).when_some(description, |this, description| {this.child(render_inline_description(provider_name, description))}),)- .child(h_flex().flex_none().child(view))+ .child(+ h_flex()+ .min_w_0()+ .max_w_1_2()+ .flex_1()+ .justify_end()+ .child(view),+ ).into_any_element()}@@ -1314,3 +1324,74 @@ fn parse_u64_field(value: &str, name: &str) -> Result<u64, SharedString> {.parse::<u64>().map_err(|_| format!("{name} must be a number").into())}++#[cfg(test)]+mod tests {+ use gpui::{TestAppContext, VisualTestContext, size};+ use language_models::provider::cloud;+ use settings::SettingsStore;++ use super::*;++ struct YoungAccountProviderRow;++ impl Render for YoungAccountProviderRow {+ fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {+ div().size_full().p_4().child(+ div()+ .w_full()+ .debug_selector(|| "provider-row".into())+ .child(render_inline_body(+ "Zed".into(),+ Some("Subscribed to Business".into()),+ Some(InlineDescription::Text(+ "You have access to Zed's hosted models through your organization."+ .into(),+ )),+ cloud::test_support::young_account_configuration(),+ )),+ )+ }+ }++ #[gpui::test]+ fn young_account_configuration_stays_within_provider_row(cx: &mut TestAppContext) {+ cx.update(|cx| {+ let settings_store = SettingsStore::test(cx);+ cx.set_global(settings_store);+ theme::init(theme::LoadThemes::JustBase, cx);+ theme_settings::init(theme::LoadThemes::JustBase, cx);+ });++ for width in [500., 600., 800.] {+ let window = cx.open_window(size(px(width), px(400.)), |_window, _cx| {+ YoungAccountProviderRow+ });+ cx.run_until_parked();++ let mut visual_context = VisualTestContext::from_window(window.into(), cx);+ let provider_row_bounds = visual_context+ .debug_bounds("provider-row")+ .expect("provider row should be rendered");+ let description_bounds = visual_context+ .debug_bounds("inline-provider-description")+ .expect("provider description should be rendered");+ let configuration_bounds = visual_context+ .debug_bounds("zed-ai-configuration")+ .expect("Zed AI configuration should be rendered");++ assert!(+ configuration_bounds.right() <= provider_row_bounds.right(),+ "young account configuration extends past the provider row at {width}px"+ );+ assert!(+ configuration_bounds.size.height >= px(80.),+ "young account warning does not wrap at {width}px"+ );+ assert!(+ description_bounds.size.width >= px(width / 3.),+ "provider description collapsed at {width}px"+ );+ }+ }+}