BlueGit

ict rusty-teams

Files

rusty-teams / vendor / gpui-component / tests / legacy_controls_compat.rs

legacy_controls_compat.rs

legacy_controls_compat.rs 2.7 KiB Download Raw
1use gpui::{
2 InteractiveElement as _, ParentElement as _, StatefulInteractiveElement as _, Styled as _,
3 blue, green, px, red,
4};
5use gpui_component::{
6 Disableable as _, Selectable as _, Sizable as _, Size,
7 checkbox::Checkbox,
8 radio::{Radio, RadioGroup},
9 switch::Switch,
10};
11
12#[test]
13fn legacy_checkbox_builder_and_traits_remain_available() {
14 let checkbox = Checkbox::new("legacy-checkbox")
15 .label("Remember me")
16 .tooltip("Stored on this device")
17 .checked(true)
18 .selected(false)
19 .disabled(false)
20 .with_size(Size::Small)
21 .tab_index(2)
22 .tab_stop(true)
23 .on_click(|next, _, _| {
24 let _: &bool = next;
25 })
26 .child("application child")
27 .bg(red())
28 .hover(|style| style.bg(green()))
29 .active(|style| style.bg(blue()))
30 .focus_visible(|style| style.border_1());
31
32 assert!(!checkbox.is_selected());
33}
34
35#[test]
36fn legacy_radio_and_radio_group_paths_remain_available() {
37 let first = Radio::new("legacy-radio-a")
38 .label("Alpha")
39 .tooltip("Choose alpha")
40 .checked(true)
41 .disabled(false)
42 .with_size(px(18.))
43 .tab_index(0)
44 .tab_stop(true)
45 .on_click(|next, _, _| {
46 let _: &bool = next;
47 })
48 .child("application child")
49 .bg(red())
50 .hover(|style| style.bg(green()))
51 .active(|style| style.bg(blue()))
52 .focus_visible(|style| style.border_1());
53
54 let second = Radio::new("legacy-radio-b").label("Beta");
55 let _vertical = RadioGroup::vertical("legacy-radio-group")
56 .selected_index(Some(0))
57 .disabled(false)
58 .on_click(|index, _, _| {
59 let _: &usize = index;
60 })
61 .child(first)
62 .child(second)
63 .bg(red());
64
65 let _horizontal = RadioGroup::horizontal("legacy-radio-group-horizontal")
66 .children([Radio::new("one"), Radio::new("two")]);
67}
68
69#[test]
70fn legacy_switch_builder_and_trait_methods_remain_available() {
71 let _switch = Switch::new("legacy-switch")
72 .label("Airplane mode")
73 .tooltip("Disable wireless radios")
74 .checked(true)
75 .disabled(false)
76 .with_size(Size::Large)
77 .color(green())
78 .on_click(|next, _, _| {
79 let _: &bool = next;
80 })
81 .bg(red());
82}
83
84#[test]
85fn base_controls_do_not_replace_legacy_module_paths() {
86 fn legacy_checkbox(_: Checkbox) {}
87 fn legacy_switch(_: Switch) {}
88 fn base_checkbox(_: gpui_base::Checkbox) {}
89 fn base_switch(_: gpui_base::Switch) {}
90
91 legacy_checkbox(Checkbox::new("legacy"));
92 legacy_switch(Switch::new("legacy"));
93 base_checkbox(gpui_base::Checkbox::new("base"));
94 base_switch(gpui_base::Switch::new("base"));
95}