Files
Ely-GPUI-Components/src/theme/tests.rs
T
ZacharyZhang-NY 84bc45df5f Theme · Editing: segments that give way, every color named
SegmentedControl's segments now give way when narrow, their labels
ending in an ellipsis, down to twice a control's height each; past
that the strip scrolls as before. The pill's border and padding moved
onto the scrolling strip, and the row inside it takes that floor as its
least width, so the strip scrolls exactly to its last segment. The
palette macro now writes each color's name from its field: Palette and
Syntax gain NAMES and token_mut for every color, the quiet fills too.
Tests press a density segment and each slider, and fit the density
strip in 280px with the text a step and a half larger.
2026-09-27 16:48:07 -04:00

53 lines
1.9 KiB
Rust

use gpui::{TestAppContext, hsla};
use super::{ActiveTheme, Mode, Palette, Syntax, Theme};
/// An owner's palette serves its own mode; the other keeps Ely's, and none brings Ely's back.
#[gpui::test]
fn an_owners_palette_serves_its_mode_alone(cx: &mut TestAppContext) {
cx.update(Theme::init);
let mut own = Palette::light(false);
own.accent = hsla(0.6, 0.5, 0.5, 1.0);
cx.update(|cx| Theme::set_palette(Mode::Light, Some(own.clone()), cx));
assert_eq!(cx.read(|cx| cx.theme().palette()), own);
cx.update(|cx| Theme::set_mode(Mode::Dark, cx));
assert_eq!(cx.read(|cx| cx.theme().palette()), Palette::dark(false));
cx.update(|cx| {
Theme::set_mode(Mode::Light, cx);
Theme::set_palette(Mode::Light, None, cx);
});
assert_eq!(cx.read(|cx| cx.theme().palette()), Palette::light(false));
}
/// Every color of the palette and of code answers to its field's name, the quiet fills too.
#[test]
fn every_color_answers_to_its_name() {
let mut palette = Palette::light(false);
for (ix, name) in Palette::NAMES.iter().enumerate() {
*palette.token_mut(name) = hsla(ix as f32 / 64.0, 0.5, 0.5, 1.0);
}
assert_eq!(Palette::NAMES.len(), 35, "every color of the palette");
let at = |name: &str| {
Palette::NAMES
.iter()
.position(|each| *each == name)
.expect("a name")
};
assert_eq!(
palette.success_subtle,
hsla(at("success_subtle") as f32 / 64.0, 0.5, 0.5, 1.0)
);
assert_eq!(palette.ink, hsla(at("ink") as f32 / 64.0, 0.5, 0.5, 1.0));
for name in Syntax::NAMES {
*palette.syntax.token_mut(name) = hsla(0.4, 0.2, 0.3, 1.0);
}
assert_eq!(Syntax::NAMES.len(), 13, "every color of code");
assert_eq!(palette.syntax.comment, hsla(0.4, 0.2, 0.3, 1.0));
}
#[test]
#[should_panic(expected = "no palette color glow")]
fn an_unknown_color_fails() {
Palette::light(false).token_mut("glow");
}