use ai_app::ui::fixture::{PHONE_FRAME_MS, PHONE_SCALE, phone_size}; use iris::harness::{Harness, TouchAction, TouchScript}; use iris::prelude::*; fn opened() -> (Harness, ai_app::ui::TranscriptScreen) { let mut h = Harness::new(phone_size(), PHONE_SCALE); let opened = ai_app::ui::fixture::open(&mut h.rsc, &mut h.state).expect("the fixture folds"); h.frame(0); h.frame(PHONE_FRAME_MS); (h, opened.screen) } fn script(name: &str, text: &str) -> TouchScript { TouchScript::parse(text).unwrap_or_else(|e| panic!("{name}: {e}")) } fn tracked_row(h: &mut Harness, screen: &ai_app::ui::TranscriptScreen) -> (RowKey, f32) { let middle = phone_size().y / 2.0; let list = (screen.list)(&mut h.rsc); let key = list.key_at(middle).expect("a row under the viewport"); let (top, _) = list.extent(key).expect("that row has an extent"); (key, top) } fn row_top(h: &mut Harness, screen: &ai_app::ui::TranscriptScreen, key: RowKey) -> f32 { (screen.list)(&mut h.rsc) .extent(key) .expect("the tracked row is still loaded") .0 } #[test] fn a_cancelled_flick_does_not_fling() { let (mut h, screen) = opened(); let flick = script( "flick-cancelled", include_str!("../touch/flick-cancelled.touch"), ); h.replay(&flick); assert_eq!( (screen.list)(&mut h.rsc).fling_velocity(), None, "a gesture the platform took away must not fling" ); let (key, settled) = tracked_row(&mut h, &screen); let end = flick.end_ms() + 1_000; let mut t = flick.end_ms(); while t <= end { h.frame(t); t += PHONE_FRAME_MS; } let now = row_top(&mut h, &screen, key); assert!( (now - settled).abs() < 0.5, "the list kept moving after a cancelled gesture: {settled} -> {now}" ); } #[test] fn a_press_ended_by_a_cancel_leaves_no_origin_for_the_next_one() { let (mut h, screen) = opened(); h.touch(TouchAction::Down, Vec2::new(540.0, 700.0), 0); h.touch(TouchAction::Cancel, Vec2::new(540.0, 700.0), 8); let (key, before) = tracked_row(&mut h, &screen); h.touch(TouchAction::Down, Vec2::new(540.0, 1900.0), 200); h.touch(TouchAction::Up, Vec2::new(540.0, 1900.0), 250); let after = row_top(&mut h, &screen, key); assert!( (after - before).abs() < 0.5, "a tap after a cancelled press panned the list by {}px, the distance between them", after - before ); assert_eq!( (screen.list)(&mut h.rsc).fling_velocity(), None, "and it must not have flung either" ); } #[test] fn panning_a_code_fence_then_tapping_elsewhere_moves_nothing() { use ai_app::client::transcript_fold::{TranscriptItem, TranscriptRow}; let (mut h, mut screen) = opened(); let fence = TranscriptRow::Single(TranscriptItem::AssistantMsg { seq: 9_000_000, text: "```\none two three four five six seven eight nine ten eleven twelve\n\ thirteen fourteen fifteen sixteen seventeen eighteen nineteen\n```" .to_string(), settled: true, }); let para = TranscriptRow::Single(TranscriptItem::AssistantMsg { seq: 9_000_001, text: "A plain paragraph with nothing to tap in it, only words, so that a \ press here is a press on ordinary text and nothing else." .to_string(), settled: true, }); screen.push_row(&mut h.rsc, &fence); screen.push_row(&mut h.rsc, ¶); (screen.list)(&mut h.rsc).jump_to_end(); h.frame(100); h.frame(108); let key = ai_app::ui::row::row_key(&fence.key()); let (top, bottom) = (screen.list)(&mut h.rsc) .extent(key) .expect("the fence row is on screen"); let y = (top + bottom) / 2.0; assert!( y > 0.0 && y < phone_size().y, "the fence row has to be on screen to be pressed: {top}..{bottom}" ); h.touch(TouchAction::Down, Vec2::new(800.0, y), 200); for (i, x) in [760.0, 700.0, 620.0, 540.0].into_iter().enumerate() { h.touch(TouchAction::Move, Vec2::new(x, y), 208 + 8 * i as u64); } h.touch(TouchAction::Up, Vec2::new(540.0, y), 248); let (tracked, before) = tracked_row(&mut h, &screen); let para_key = ai_app::ui::row::row_key(¶.key()); let (ptop, pbottom) = (screen.list)(&mut h.rsc) .extent(para_key) .expect("the paragraph row is on screen"); h.touch( TouchAction::Down, Vec2::new(540.0, (ptop + pbottom) / 2.0), 400, ); h.touch( TouchAction::Up, Vec2::new(540.0, (ptop + pbottom) / 2.0), 450, ); let after = row_top(&mut h, &screen, tracked); assert!( (after - before).abs() < 0.5, "a tap after panning a code fence moved the transcript by {}px", after - before ); }