Reviews: T16a–e done. After the cap: a lagging synced chart leaves the shared window alone, and a price step keeps its places by magnitude

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-09-26 00:20:08 -04:00
1 parent 1fe5673de1
commit c229a096ca
4 files changed
+96 -41

No files matched your search

+52 -10
View File
@@ -2,7 +2,7 @@ use std::rc::Rc;
use gpui::{
AppContext as _, Context, Entity, IntoElement, ParentElement, Render, Styled, TestAppContext,
Window, div, px,
VisualTestContext, Window, div, px,
};
use jiff::Timestamp;
@@ -21,7 +21,8 @@ fn candles(count: usize) -> Rc<Vec<Candle>> {
}
struct Pair {
candles: Rc<Vec<Candle>>,
first: Rc<Vec<Candle>>,
second: Rc<Vec<Candle>>,
sync: Entity<ChartSync>,
}
@@ -29,18 +30,19 @@ impl Render for Pair {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
div()
.w(px(800.))
.child(CandlestickChart::new("first", self.candles.clone()).sync(&self.sync))
.child(CandlestickChart::new("second", self.candles.clone()).sync(&self.sync))
.child(CandlestickChart::new("first", self.first.clone()).sync(&self.sync))
.child(CandlestickChart::new("second", self.second.clone()).sync(&self.sync))
}
}
#[gpui::test]
fn synced_charts_move_their_shared_window_once_per_append(cx: &mut TestAppContext) {
/// Two synced charts of 40 candles, their shared window held on the newest 20.
fn held(cx: &mut TestAppContext) -> (Entity<Pair>, Entity<ChartSync>, &mut VisualTestContext) {
cx.update(Theme::init);
let sync = cx.new(|_| ChartSync::default());
let shared = sync.clone();
let (view, cx) = cx.add_window_view(|_, _| Pair {
candles: candles(40),
first: candles(40),
second: candles(40),
sync: shared,
});
cx.run_until_parked();
@@ -53,14 +55,54 @@ fn synced_charts_move_their_shared_window_once_per_append(cx: &mut TestAppContex
});
view.update(cx, |_, cx| cx.notify());
cx.run_until_parked();
(view, sync, cx)
}
fn start(sync: &Entity<ChartSync>, cx: &mut VisualTestContext) -> f64 {
sync.read_with(cx, |sync, _| sync.visible.expect("held").start)
}
#[gpui::test]
fn synced_charts_move_their_shared_window_once_per_append(cx: &mut TestAppContext) {
let (view, sync, cx) = held(cx);
view.update(cx, |pair, cx| {
pair.candles = candles(45);
pair.first = candles(45);
pair.second = candles(45);
cx.notify();
});
cx.run_until_parked();
let start = sync.read_with(cx, |sync, _| sync.visible.expect("held").start);
assert_eq!(
start, 25.0,
start(&sync, cx),
25.0,
"five new candles move the shared window five, not ten"
);
}
#[gpui::test]
fn a_lagging_chart_leaves_the_shared_window_alone(cx: &mut TestAppContext) {
let (view, sync, cx) = held(cx);
view.update(cx, |pair, cx| {
pair.second = candles(45);
cx.notify();
});
cx.run_until_parked();
for _ in 0..2 {
view.update(cx, |_, cx| cx.notify());
cx.run_until_parked();
}
assert_eq!(
(start(&sync, cx), sync.read_with(cx, |sync, _| sync.seen)),
(25.0, 45),
"redraws while the first chart lags move nothing"
);
view.update(cx, |pair, cx| {
pair.first = candles(45);
cx.notify();
});
cx.run_until_parked();
assert_eq!(
start(&sync, cx),
25.0,
"the lagging chart's append is already shown"
);
}