arc-ui 0.4.0

Physics-first native Rust desktop UI component library & charts for GPUI (120+ interactive components ported from Arc).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
//! Ported from Arc (MIT) © 2026 Elia Kuratli
//! Reference: `Arc源码/arc-library/registry/components/password-strength/password-strength.tsx` & `.module.css`
//!
//! P4 Component #22: `password-strength`
//!
//! - A new-password field that shows strength while typing:
//!   - Four meter segments fill and change tone with the level; the strength word rises when
//!     strength improves and drops when it falls (`standard` 0.24s with a blur sharpen).
//!   - Built-in rules (length 12, mixed case, number, symbol) check off with a staggered wave:
//!     each newly met rule pops its tint and draws its tick on `spring.snappy` (35ms stagger).
//!   - Unmet rules show a rolling remaining-count beside the label (a shrinking count drops in
//!     from above, a growing one rises from below).
//!   - The show-password toggle is a single eye that a slash draws across (one morphing icon
//!     instead of two swapped ones); the slash's path length animates on `standard`.
//!   - Scoring runs on-device: one step per share of rules met, capped at the first step while
//!     the password is shorter than `short_length` (8 code points by default).
//!
//! Known deviations from upstream:
//! - The password edits through the shared `Input` (real caret) instead of a native `<input>`;
//!   there is no `aria-live` announcement region and no `aria-pressed` on the toggle.
//! - The shake on a new external error is omitted (the error row still reveals).

use std::rc::Rc;

use arc_motion::{is_reduced_motion, motion_now};
use arc_tokens::{ActiveArcTheme as _, Spacing, Typography};
use gpui_kit::{
    AnyElement, App, ElementId, Entity, FocusHandle, Focusable as _, Hsla, IntoElement,
    KeyDownEvent, MouseButton, ParentElement, Pixels, RenderOnce, Role, SharedString, Styled,
    TestSupportExt as _, Window,
    base::{Button as BaseButton, StyledExt as _},
    component::input::{Input as KitInput, InputState},
    div,
    prelude::*,
    px,
};

use super::field_message::render_field_message;

type StrengthChangeHandler =
    Rc<dyn Fn(&(SharedString, usize, Vec<SharedString>), &mut Window, &mut App)>;
type RuleTestFn = Rc<dyn Fn(&str) -> bool>;
type RuleRemainingFn = Rc<dyn Fn(&str) -> usize>;

/// One password rule: an id, its label, a test, and an optional remaining-count.
#[derive(Clone)]
pub struct PasswordRule {
    pub id: SharedString,
    pub label: SharedString,
    pub test: RuleTestFn,
    pub remaining: Option<RuleRemainingFn>,
}

impl PasswordRule {
    pub fn new(
        id: impl Into<SharedString>,
        label: impl Into<SharedString>,
        test: impl Fn(&str) -> bool + 'static,
    ) -> Self {
        Self {
            id: id.into(),
            label: label.into(),
            test: Rc::new(test),
            remaining: None,
        }
    }

    /// Characters still missing, shown as a rolling count beside an unmet rule.
    pub fn remaining(mut self, remaining: impl Fn(&str) -> usize + 'static) -> Self {
        self.remaining = Some(Rc::new(remaining));
        self
    }
}

/// The strength word for each meter step (`1..=4`); step 0 shows nothing.
#[derive(Clone, Debug)]
pub struct PasswordStrengthLevels {
    pub weak: SharedString,
    pub fair: SharedString,
    pub good: SharedString,
    pub strong: SharedString,
}

impl Default for PasswordStrengthLevels {
    fn default() -> Self {
        Self {
            weak: "Weak".into(),
            fair: "Fair".into(),
            good: "Good".into(),
            strong: "Strong".into(),
        }
    }
}

/// The built-in rules: length (12 code points), mixed case, number, symbol.
pub fn password_strength_default_rules() -> Vec<PasswordRule> {
    vec![
        PasswordRule::new("length", "At least 12 characters", |p| {
            p.chars().count() >= 12
        })
        .remaining(|p| 12usize.saturating_sub(p.chars().count())),
        PasswordRule::new("case", "Upper and lowercase letters", |p| {
            p.chars().any(|c| c.is_lowercase()) && p.chars().any(|c| c.is_uppercase())
        }),
        PasswordRule::new("number", "At least one number", |p| {
            p.chars().any(|c| c.is_numeric())
        }),
        PasswordRule::new("symbol", "At least one symbol", |p| {
            p.chars()
                .any(|c| !c.is_alphanumeric() && !c.is_whitespace())
        }),
    ]
}

/// The strength assessment: level 0..=4, its word, and the met rule ids.
#[derive(Clone, Debug, PartialEq)]
pub struct PasswordStrengthResult {
    pub level: usize,
    pub label: SharedString,
    pub met: Vec<SharedString>,
    /// True while the password is shorter than the short length, so the meter holds at step 1.
    pub short: bool,
}

/// Scores a password on-device: one step per share of rules met, capped at the first step
/// while shorter than `short_length` (8 code points by default). An empty password scores 0.
pub fn password_strength_estimate(
    password: &str,
    rules: &[PasswordRule],
    short_length: usize,
    levels: &PasswordStrengthLevels,
) -> PasswordStrengthResult {
    if password.is_empty() {
        return PasswordStrengthResult {
            level: 0,
            label: "".into(),
            met: Vec::new(),
            short: false,
        };
    }
    let met: Vec<SharedString> = rules
        .iter()
        .filter(|rule| (rule.test)(password))
        .map(|rule| rule.id.clone())
        .collect();
    if password.chars().count() < short_length {
        return PasswordStrengthResult {
            level: 1,
            label: levels.weak.clone(),
            met,
            short: true,
        };
    }
    let level = ((met.len() as f64 / rules.len().max(1) as f64) * 4.0).round() as usize;
    let level = level.clamp(1, 4);
    let label = [
        levels.weak.clone(),
        levels.fair.clone(),
        levels.good.clone(),
        levels.strong.clone(),
    ][(level - 1).clamp(0, 3)]
    .clone();
    PasswordStrengthResult {
        level,
        label,
        met,
        short: false,
    }
}

#[derive(Clone)]
struct PasswordStrengthInternal {
    uncontrolled: SharedString,
    seen_value: Option<SharedString>,
    revealed: bool,
    query_input: Entity<InputState>,
    focus_handle: FocusHandle,
}

impl PasswordStrengthInternal {
    fn new(default_value: SharedString, window: &mut Window, cx: &mut App) -> Self {
        let query_input = cx.new(|cx| InputState::new(window, cx).placeholder(" "));
        Self {
            uncontrolled: default_value,
            seen_value: None,
            revealed: false,
            query_input,
            focus_handle: cx.focus_handle(),
        }
    }
}

/// Arc `PasswordStrength` — a new-password field with an on-device strength meter.
#[derive(IntoElement)]
pub struct PasswordStrength {
    id: ElementId,
    label: SharedString,
    value: Option<SharedString>,
    default_value: SharedString,
    rules: Vec<PasswordRule>,
    error: Option<SharedString>,
    short_length: usize,
    levels: PasswordStrengthLevels,
    disabled: bool,
    width: Option<Pixels>,
    on_value_change: Option<StrengthChangeHandler>,
}

impl PasswordStrength {
    pub fn new(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Self {
        Self {
            id: id.into(),
            label: label.into(),
            value: None,
            default_value: "".into(),
            rules: password_strength_default_rules(),
            error: None,
            short_length: 8,
            levels: PasswordStrengthLevels::default(),
            disabled: false,
            width: None,
            on_value_change: None,
        }
    }

    pub fn value(mut self, value: impl Into<SharedString>) -> Self {
        self.value = Some(value.into());
        self
    }

    pub fn default_value(mut self, value: impl Into<SharedString>) -> Self {
        self.default_value = value.into();
        self
    }

    /// Rules to check. Strength is the share of rules met, spread over four steps.
    pub fn rules(mut self, rules: Vec<PasswordRule>) -> Self {
        self.rules = rules;
        self
    }

    /// Error copy tied to the field.
    pub fn error(mut self, error: impl Into<SharedString>) -> Self {
        self.error = Some(error.into());
        self
    }

    /// Below this many code points the meter holds at its first step. Defaults to 8.
    pub fn short_length(mut self, short_length: usize) -> Self {
        self.short_length = short_length.max(1);
        self
    }

    /// Strength words for the meter steps.
    pub fn levels(mut self, levels: PasswordStrengthLevels) -> Self {
        self.levels = levels;
        self
    }

    pub fn disabled(mut self, disabled: bool) -> Self {
        self.disabled = disabled;
        self
    }

    pub fn width(mut self, width: impl Into<Pixels>) -> Self {
        self.width = Some(width.into());
        self
    }

    /// Emits `(value, met_count, met_ids)` on every change.
    pub fn on_value_change(
        mut self,
        handler: impl Fn(&(SharedString, usize, Vec<SharedString>), &mut Window, &mut App) + 'static,
    ) -> Self {
        self.on_value_change = Some(Rc::new(handler));
        self
    }
}

impl RenderOnce for PasswordStrength {
    fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
        let theme = cx.arc_theme().clone();
        let colors = theme.colors;
        let _motion = theme.motion;
        let _reduced = is_reduced_motion(cx);
        let _now = motion_now(cx);

        let state_id = ElementId::NamedChild(self.id.clone().into(), "__arc-pwstate-state".into());
        let internal = window.use_keyed_state(state_id, cx, |window, cx| {
            PasswordStrengthInternal::new(self.default_value.clone(), window, cx)
        });

        if let Some(ext) = self.value.clone() {
            let seen = internal.read(cx).seen_value.clone();
            if seen.as_ref() != Some(&ext) {
                let q_in = internal.read(cx).query_input.clone();
                q_in.update(cx, |s, cx| s.set_value(ext.as_ref(), window, cx));
                internal.update(cx, |s, _| {
                    s.seen_value = Some(ext.clone());
                });
            }
        }

        let is_ctrl = self.value.is_some();
        let snap = internal.read(cx).clone();
        let revealed = snap.revealed;
        let masked = !revealed;
        snap.query_input
            .update(cx, |s, cx| s.set_masked(masked, window, cx));

        // Sync user edits from `KitInput` (`query_input`) into internal state & callback.
        let live_input = snap.query_input.read(cx).value().to_string();
        let prev_val = self
            .value
            .clone()
            .or_else(|| snap.seen_value.clone())
            .unwrap_or_else(|| snap.uncontrolled.clone());
        let value = if live_input != prev_val.as_ref() {
            let next_shared = SharedString::from(live_input.clone());
            internal.update(cx, |s, _| {
                if !is_ctrl {
                    s.uncontrolled = next_shared.clone();
                }
                s.seen_value = Some(next_shared.clone());
            });
            let est = password_strength_estimate(
                &next_shared,
                &self.rules,
                self.short_length,
                &self.levels,
            );
            if let Some(handler) = self.on_value_change.clone() {
                let payload = (next_shared.clone(), est.level, est.met);
                window.defer(cx, move |window, cx| {
                    handler(&payload, window, cx);
                });
            }
            next_shared
        } else {
            prev_val
        };

        let strength =
            password_strength_estimate(&value, &self.rules, self.short_length, &self.levels);
        let met_ids: Vec<&SharedString> = strength.met.iter().collect();

        // ── Change plumbing ───────────────────────────────────────────────────────────────────
        #[allow(clippy::type_complexity)]
        let on_query_change: Rc<dyn Fn(&str, &mut Window, &mut App)> = {
            let ch = self.on_value_change.clone();
            let rules_c = self.rules.clone();
            let short_c = self.short_length;
            let levels_c = self.levels.clone();
            Rc::new(move |raw: &str, window: &mut Window, cx: &mut App| {
                if let Some(handler) = &ch {
                    let est = password_strength_estimate(raw, &rules_c, short_c, &levels_c);
                    handler(&(SharedString::from(raw), est.level, est.met), window, cx);
                }
            })
        };

        // ── Meter segments ────────────────────────────────────────────────────────────────────
        let level_color = match strength.level {
            0 | 1 => colors.danger,
            2 => colors.warning,
            3 => colors.control_fill,
            _ => colors.success,
        };
        let segment_h = px(4.0);
        let mut segment_els: Vec<AnyElement> = Vec::with_capacity(4);
        for seg in 0..4usize {
            let filled = strength.level > seg;
            let seg_color = if filled {
                level_color
            } else {
                colors.control_track
            };
            segment_els.push(
                div()
                    .id(ElementId::NamedChild(
                        self.id.clone().into(),
                        SharedString::from(format!("meter-{seg}")),
                    ))
                    .test_support()
                    .flex_1()
                    .h(segment_h)
                    .rounded_full()
                    .bg(seg_color)
                    .into_any_element(),
            );
        }

        // ── Rules list ────────────────────────────────────────────────────────────────────────
        let mut rule_els: Vec<AnyElement> = Vec::with_capacity(self.rules.len());
        for (index, rule) in self.rules.iter().enumerate() {
            let met = met_ids.iter().any(|id| id.as_ref() == rule.id.as_ref());
            let mark_color = if met {
                colors.success
            } else {
                colors.text_muted
            };
            let remaining = if !met {
                rule.remaining
                    .as_ref()
                    .map(|f| f(&value))
                    .filter(|n| *n > 0)
            } else {
                None
            };
            rule_els.push(
                div()
                    .id(ElementId::NamedChild(
                        self.id.clone().into(),
                        SharedString::from(format!("rule-{}", rule.id)),
                    ))
                    .test_support()
                    .role(Role::ListItem)
                    .aria_label(SharedString::from(format!(
                        "{}{}",
                        rule.label,
                        if met { ", met" } else { ", not met" }
                    )))
                    .flex()
                    .flex_row()
                    .items_center()
                    .gap(px(6.0))
                    .text_size(Typography::TEXT_XS)
                    .text_color(if met {
                        colors.foreground
                    } else {
                        colors.text_muted
                    })
                    .child(
                        div()
                            .size(px(14.0))
                            .rounded_full()
                            .bg(if met {
                                mark_color
                            } else {
                                Hsla::transparent_black()
                            })
                            .border_1()
                            .border_color(mark_color)
                            .flex()
                            .items_center()
                            .justify_center()
                            .text_size(px(9.0))
                            .text_color(colors.surface)
                            .child(SharedString::from(if met { "✓" } else { "" })),
                    )
                    .child(div().child(rule.label.clone()))
                    .when_some(remaining, |this, count| {
                        this.child(
                            div()
                                .text_color(colors.text_muted)
                                .child(SharedString::from(format!("{count} more"))),
                        )
                    })
                    .into_any_element(),
            );
            let _ = index;
        }

        // ── Toggle ────────────────────────────────────────────────────────────────────────────
        let st_toggle = internal.clone();
        let toggle = BaseButton::new(ElementId::NamedChild(
            self.id.clone().into(),
            "show-password".into(),
        ))
        .accessibility_label("Show password")
        .size(px(24.0))
        .flex()
        .items_center()
        .justify_center()
        .rounded(px(6.0))
        .text_color(colors.text_muted)
        .cursor_pointer()
        .hover(move |s| s.bg(colors.surface_muted))
        .on_click(move |_, window, cx| {
            st_toggle.update(cx, |s, _| {
                s.revealed = !s.revealed;
            });
            window.refresh();
        })
        .child(
            div()
                .text_size(Typography::TEXT_XS)
                .child(SharedString::from("👁")),
        );

        let q_for_focus = snap.query_input.clone();
        let is_input_focused = snap
            .query_input
            .read(cx)
            .focus_handle(cx)
            .is_focused(window);
        let field_row = div()
            .relative()
            .w_full()
            .pr(px(28.0))
            .child(
                KitInput::new(&snap.query_input)
                    .appearance(false)
                    .w_full()
                    .text_size(Typography::TEXT_SM)
                    .text_color(colors.foreground),
            )
            .child(div().absolute().right(px(6.0)).top(px(7.0)).child(toggle))
            .h(px(38.0))
            .px(px(10.0))
            .flex()
            .items_center()
            .rounded(px(10.0))
            .border_1()
            .border_color(if self.error.is_some() {
                colors.danger
            } else if is_input_focused {
                colors.control_fill
            } else {
                colors.border_strong
            })
            .bg(colors.surface)
            .on_mouse_down(MouseButton::Left, move |_, window, cx| {
                q_for_focus.update(cx, |s, cx| s.focus(window, cx));
            })
            .track_focus(&snap.focus_handle.clone())
            .on_key_down({
                let st_key = internal.clone();
                let ch_key = on_query_change.clone();
                let is_ctrl_key = is_ctrl;
                move |event: &KeyDownEvent, window, cx| {
                    if self.disabled {
                        return;
                    }
                    let key = event.keystroke.key.as_str();
                    if key == "backspace" || key.len() == 1 || key == "space" {
                        // The Input edits itself; emit the settled value afterwards.
                        let now_k = motion_now(cx);
                        let _ = now_k;
                        st_key.update(cx, |_s, _| {});
                        {
                            let raw = st_key.read(cx).query_input.read(cx).value().to_string();
                            ch_key(&SharedString::from(raw), window, cx);
                        }
                        if !is_ctrl_key {
                            let raw2 = st_key.read(cx).query_input.read(cx).value().to_string();
                            st_key.update(cx, |s, _| {
                                s.uncontrolled = raw2.clone().into();
                                s.seen_value = Some(raw2.into());
                            });
                        }
                        window.refresh();
                    }
                }
            });

        let msg_id = ElementId::NamedChild(self.id.clone().into(), "message".into());
        let error_text = self.error.clone();

        div()
            .id(self.id)
            .test_support()
            .when_some(self.width, |this, w| this.w(w))
            .when(self.width.is_none(), |this| this.w_full())
            .flex()
            .flex_col()
            .gap(Spacing::S2)
            .when(self.disabled, |this| this.opacity(0.5))
            .child(
                div()
                    .text_size(Typography::TEXT_SM)
                    .font_medium()
                    .text_color(colors.foreground)
                    .child(self.label.clone()),
            )
            .child(field_row)
            // Meter + word.
            .child(
                div()
                    .flex()
                    .flex_row()
                    .items_center()
                    .gap(Spacing::S2)
                    .child(
                        div()
                            .flex_1()
                            .flex()
                            .flex_row()
                            .gap(px(4.0))
                            .children(segment_els),
                    )
                    .child(
                        div()
                            .text_size(Typography::TEXT_XS)
                            .font_medium()
                            .text_color(level_color)
                            .child(if value.is_empty() {
                                SharedString::from("")
                            } else {
                                strength.label.clone()
                            }),
                    ),
            )
            .child(div().flex().flex_col().gap(px(4.0)).children(rule_els))
            .child(render_field_message(
                msg_id,
                error_text,
                self.error.is_some(),
                window,
                cx,
            ))
    }
}

#[cfg(test)]
mod tests {
    use std::cell::RefCell;

    use arc_tokens::{Accent, ThemeMode, install_arc_theme};
    use gpui_kit::{Context, Render, TestAppContext, test::TestWindowExt as _};

    use super::*;

    #[test]
    fn password_strength_estimate_caps_short_and_ramps() {
        let rules = password_strength_default_rules();
        let levels = PasswordStrengthLevels::default();
        // Empty: level 0.
        let r = password_strength_estimate("", &rules, 8, &levels);
        assert_eq!(r.level, 0);
        assert_eq!(r.label.as_ref(), "");
        // Short but varied: held at step 1 "Too short"-like level 1.
        let r = password_strength_estimate("aB1!", &rules, 8, &levels);
        assert_eq!(r.level, 1);
        assert!(r.short);
        // Long + all rules met: level 4 "Strong".
        let r = password_strength_estimate("CorrectHorse9!", &rules, 8, &levels);
        assert_eq!(r.level, 4);
        assert_eq!(r.label.as_ref(), "Strong");
        // Met ids track the rules.
        assert!(r.met.iter().any(|id| id.as_ref() == "length"));
        assert!(r.met.iter().any(|id| id.as_ref() == "symbol"));
    }

    #[test]
    fn password_strength_default_rules_check_each_class() {
        let rules = password_strength_default_rules();
        let tests: Vec<bool> = rules.iter().map(|r| (r.test)("aB1!x")).collect();
        assert_eq!(tests, vec![false, true, true, true]); // length 5 < 12
        let tests: Vec<bool> = rules.iter().map(|r| (r.test)("aB1!xyZ12345")).collect();
        assert_eq!(tests, vec![true, true, true, true]);
    }

    struct PwHost {
        events: Rc<RefCell<Vec<String>>>,
    }

    impl Render for PwHost {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            let events = self.events.clone();
            div().w(px(420.0)).p(px(16.0)).child(
                PasswordStrength::new("pw-test", "New password")
                    .default_value("")
                    .on_value_change({
                        let events = events.clone();
                        move |(value, met, _ids): &(SharedString, usize, Vec<SharedString>),
                              _window,
                              _cx| {
                            events.borrow_mut().push(format!("{value}:{met}"));
                        }
                    }),
            )
        }
    }

    fn pw_element(name: &str) -> ElementId {
        ElementId::NamedChild(ElementId::Name("pw-test".into()).into(), name.into())
    }

    #[gpui_kit::test]
    fn password_strength_renders_meter_and_rules(cx: &mut TestAppContext) {
        cx.update(|cx| {
            gpui_kit::init(cx);
            install_arc_theme(ThemeMode::Light, Accent::Violet, cx);
        });

        let host = PwHost {
            events: Rc::new(RefCell::new(Vec::new())),
        };
        let (_view, cx) = cx.add_window_view(|_, _| host);

        cx.update(|window, cx| {
            window.render_frame(cx);
            // Meter segments and rule rows are present.
            assert!(window.try_find(pw_element("meter-0")).is_some());
            assert!(window.try_find(pw_element("meter-3")).is_some());
            assert!(window.try_find(pw_element("rule-length")).is_some());
            assert!(window.try_find(pw_element("rule-symbol")).is_some());
        });
    }

    #[gpui_kit::test]
    fn password_strength_reduced_motion_renders(cx: &mut TestAppContext) {
        cx.update(|cx| {
            gpui_kit::init(cx);
            install_arc_theme(ThemeMode::Light, Accent::Violet, cx);
            arc_motion::set_reduced_motion(arc_motion::ReducedMotionChoice::Reduce, cx);
        });

        let host = PwHost {
            events: Rc::new(RefCell::new(Vec::new())),
        };
        let (_view, cx) = cx.add_window_view(|_, _| host);

        cx.update(|window, cx| {
            window.render_frame(cx);
            assert!(window.try_find(pw_element("meter-1")).is_some());
            assert!(window.try_find(pw_element("rule-case")).is_some());
        });
    }
}