mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-12-05 11:15:01 +03:00
3153 lines
114 KiB
Rust
3153 lines
114 KiB
Rust
//! End-to-end headless integration tests verifying real `.on_click(cx.listener(...))`
|
||
//! dispatch, multi-workspace isolation, Explorer drill-down & ancestor breadcrumbs,
|
||
//! `d0 -> cur` location pick + `Return to Trail`, Search focus + keyboard + IME commit,
|
||
//! live frame-1 `published_a11y_tree` Dialog children + focus restoration, closing-sheet
|
||
//! content retention & click-through, compact `568x320` landscape sheet reachability, editor
|
||
//! write gates, `Experimental` and `View Info` sheets, the journal week strip, and the typed
|
||
//! drawer filter.
|
||
|
||
use std::{
|
||
cell::RefCell,
|
||
rc::Rc,
|
||
sync::{Arc, Mutex},
|
||
time::Duration,
|
||
};
|
||
|
||
use affine_client::{ContextState, DirectKind, NavTarget, Origin};
|
||
use affine_mobile::{
|
||
BackOutcome, InMemoryPlatformAccessibility, MobileA11yAction, MobileBackCoordinator,
|
||
MobileLocale, MobileRoute, MobileSheet, MobileShellView, NativeSelectionUi,
|
||
register_mobile_fonts, seed_showcase_state, validate_accessibility_tree,
|
||
};
|
||
use ui::{
|
||
Application, Bounds, Edges, EntityInputHandler, HeadlessPlatform, KeyDownEvent, Keystroke,
|
||
PlatformInput, WindowBounds, WindowHandle, WindowInsets, WindowOptions, point, prelude::*, px,
|
||
size,
|
||
};
|
||
use ui_tokens::ThemeMode;
|
||
|
||
struct TestApp {
|
||
platform: Rc<HeadlessPlatform>,
|
||
app: ui::ApplicationHandle,
|
||
window_handle: WindowHandle<MobileShellView>,
|
||
headless_win: ui::HeadlessWindow,
|
||
}
|
||
|
||
impl TestApp {
|
||
fn launch(width: u32, height: u32, locale: MobileLocale) -> Self {
|
||
Self::launch_with_state(
|
||
width,
|
||
height,
|
||
seed_showcase_state(locale, ThemeMode::Light, "2026-11-25"),
|
||
)
|
||
}
|
||
|
||
fn launch_with_state(width: u32, height: u32, state: affine_mobile::MobileAppState) -> Self {
|
||
let platform = HeadlessPlatform::new(width, height, 1.0);
|
||
let handle_cell: Rc<RefCell<Option<WindowHandle<MobileShellView>>>> =
|
||
Rc::new(RefCell::new(None));
|
||
let handle_out = handle_cell.clone();
|
||
|
||
let app = Application::with_platform(platform.clone()).run_embedded(move |cx| {
|
||
register_mobile_fonts(cx).expect("register mobile fonts");
|
||
let win = cx
|
||
.open_window(
|
||
WindowOptions {
|
||
window_bounds: Some(WindowBounds::Windowed(Bounds::new(
|
||
point(px(0.0), px(0.0)),
|
||
size(px(width as f32), px(height as f32)),
|
||
))),
|
||
..WindowOptions::default()
|
||
},
|
||
|_, cx| cx.new(|cx| MobileShellView::new(state, cx)),
|
||
)
|
||
.expect("open headless mobile window");
|
||
*handle_out.borrow_mut() = Some(win);
|
||
});
|
||
|
||
let window_handle = handle_cell
|
||
.borrow_mut()
|
||
.take()
|
||
.expect("window handle initialized");
|
||
let headless_win = platform
|
||
.windows()
|
||
.into_iter()
|
||
.next()
|
||
.expect("headless window registered");
|
||
|
||
Self {
|
||
platform,
|
||
app,
|
||
window_handle,
|
||
headless_win,
|
||
}
|
||
}
|
||
|
||
fn read<R>(&self, f: impl FnOnce(&MobileShellView, &ui::App) -> R) -> R {
|
||
self.app
|
||
.update(|cx| self.window_handle.update(cx, |v, _, cx| f(v, cx)))
|
||
.expect("read shell")
|
||
}
|
||
|
||
fn has_element(&self, id: &str) -> bool {
|
||
self.headless_win.request_frame();
|
||
self.app
|
||
.update(|cx| {
|
||
self.window_handle.update(cx, |_, window, _| {
|
||
window.frame_snapshot().elements.contains_key(id)
|
||
})
|
||
})
|
||
.expect("read snapshot")
|
||
}
|
||
|
||
fn click_id(&self, id_or_prefix: &str) {
|
||
self.click_id_with_advance(id_or_prefix, 400);
|
||
}
|
||
|
||
fn click_id_with_advance(&self, id_or_prefix: &str, advance_ms: u64) {
|
||
self.headless_win.request_frame();
|
||
let pt = self
|
||
.app
|
||
.update(|cx| {
|
||
self.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
let el = snap
|
||
.elements
|
||
.get(id_or_prefix)
|
||
.or_else(|| {
|
||
snap.elements
|
||
.iter()
|
||
.find(|(k, _)| k.starts_with(id_or_prefix))
|
||
.map(|(_, v)| v)
|
||
})
|
||
.unwrap_or_else(|| {
|
||
panic!(
|
||
"element `{id_or_prefix}` missing from FrameSnapshot (keys: {:?})",
|
||
snap.elements.keys().collect::<Vec<_>>()
|
||
)
|
||
});
|
||
point(
|
||
px(el.bounds.x + el.bounds.width * 0.5),
|
||
px(el.bounds.y + el.bounds.height * 0.5),
|
||
)
|
||
})
|
||
})
|
||
.expect("read snapshot");
|
||
self.headless_win.simulate_click(pt);
|
||
self.platform.run_until_parked();
|
||
if advance_ms > 0 {
|
||
self.platform
|
||
.advance_clock(Duration::from_millis(advance_ms));
|
||
self.platform.run_until_parked();
|
||
}
|
||
self.headless_win.request_frame();
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn headless_click_drives_tabs_doc_open_location_pick_and_back_navigation() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
|
||
t.click_id("mobile.tab.explorer");
|
||
let route = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Explorer);
|
||
|
||
t.click_id("mobile.tab.home");
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
let (route, is_multi) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let d = v.state.derive_breadcrumb();
|
||
(
|
||
v.state.route.clone(),
|
||
matches!(d.context, ContextState::MultiLocation { count: 2, .. }),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Page("doc-arch".into()));
|
||
assert!(is_multi);
|
||
|
||
t.click_id("mobile.page.breadcrumb.slot.switcher:");
|
||
t.click_id("mobile.sheet.loc.0");
|
||
let (sheet_after, labels) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let d = v.state.derive_breadcrumb();
|
||
let labels: Vec<String> = d.crumbs.iter().map(|c| c.label.clone()).collect();
|
||
(v.state.active_sheet, labels)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(sheet_after, MobileSheet::None);
|
||
assert_eq!(
|
||
labels,
|
||
vec![
|
||
"Engineering",
|
||
"Mobile Rust",
|
||
"Mobile Shell & Breadcrumb Spec"
|
||
]
|
||
);
|
||
|
||
t.click_id("mobile.page.back_btn");
|
||
let route = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Home);
|
||
}
|
||
|
||
#[test]
|
||
fn workspace_switch_isolates_docs_backlinks_and_back_stack() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.workspace_btn");
|
||
t.click_id("mobile.sheet.ws.ws-personal");
|
||
|
||
let (ws_id, has_arch, has_personal, bl_count) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
(
|
||
v.state.active_workspace().scope.workspace_id.clone(),
|
||
v.state.doc_by_id("doc-arch").is_some(),
|
||
v.state.doc_by_id("doc-personal-1").is_some(),
|
||
v.state.backlinks_for("doc-personal-1").items.len(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(ws_id, "ws-personal");
|
||
assert!(!has_arch);
|
||
assert!(has_personal);
|
||
assert_eq!(bl_count, 1);
|
||
|
||
t.click_id("mobile.home.doc.doc-personal-1");
|
||
t.click_id("mobile.page.back_btn");
|
||
let route = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Home);
|
||
}
|
||
|
||
#[test]
|
||
fn explorer_drilldown_and_breadcrumb_folder_navigation_roundtrip() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.tab.explorer");
|
||
t.click_id("mobile.explorer.folder.f-eng");
|
||
t.click_id("mobile.explorer.folder.f-mobile");
|
||
t.click_id("mobile.explorer.doc.14:ws-mobile-rustdoc-arch");
|
||
|
||
let route = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Page("doc-arch".into()));
|
||
|
||
// Click ancestor folder crumb `Engineering` -> opens folder drilldown for `f-eng`.
|
||
t.click_id("mobile.page.breadcrumb.slot.folder:f-eng");
|
||
let (route, target) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
(
|
||
v.state.route.clone(),
|
||
v.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.map(|e| e.target.clone()),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Explorer);
|
||
assert_eq!(target, Some(NavTarget::Folder("f-eng".into())));
|
||
}
|
||
|
||
#[test]
|
||
fn doc_link_cur_location_pick_preserves_d0_and_return_to_trail_restores_without_push() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state
|
||
.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||
let arch_seq = v.state.active_workspace().history.current().unwrap().seq;
|
||
v.state.open_doc(
|
||
"doc-sync",
|
||
Origin::DocLink {
|
||
parent_seq: arch_seq,
|
||
block_id: None,
|
||
},
|
||
);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
|
||
let len_before = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle
|
||
.update(cx, |v, _, _| v.state.active_workspace().history.len())
|
||
})
|
||
.unwrap();
|
||
|
||
// Open Location & Trail sheet via DocActions and pick cur (`doc-sync`)'s own folder location.
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.location_trail");
|
||
t.click_id("mobile.sheet.loc.0");
|
||
|
||
let (can_return, d0_pick_is_none, len_after_pick) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let d = v.state.derive_breadcrumb();
|
||
let arch_entry = v
|
||
.state
|
||
.active_workspace()
|
||
.history
|
||
.entries()
|
||
.iter()
|
||
.find(|e| e.target == NavTarget::Doc("doc-arch".into()))
|
||
.unwrap();
|
||
(
|
||
d.can_return_to_trail,
|
||
arch_entry.pick.is_none(),
|
||
v.state.active_workspace().history.len(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(can_return, "must be able to return to trail after cur pick");
|
||
assert!(d0_pick_is_none, "picking cur location MUST NOT mutate d0");
|
||
assert_eq!(len_after_pick, len_before);
|
||
|
||
// Reopen sheet and click `Return to Trail` -> restores `d0 -> cur` trail with zero history push.
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.location_trail");
|
||
t.click_id("mobile.sheet.use_trail_btn");
|
||
let (trail_len, len_after_return) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let d = v.state.derive_breadcrumb();
|
||
(d.trail.len(), v.state.active_workspace().history.len())
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(trail_len, 2);
|
||
assert_eq!(len_after_return, len_before);
|
||
}
|
||
|
||
#[test]
|
||
fn search_focus_ime_composition_and_commit_opens_matching_doc() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.tab.search");
|
||
t.click_id("mobile.search.clear_btn");
|
||
t.click_id("mobile.search.input");
|
||
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.replace_and_mark_text_in_range(None, "Sy", None, window, cx);
|
||
assert!(v.marked_text_range(window, cx).is_some());
|
||
v.replace_text_in_range(None, "Sync", window, cx);
|
||
assert!(v.marked_text_range(window, cx).is_none());
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
t.click_id("mobile.search.hit.doc-sync");
|
||
let route = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Page("doc-sync".into()));
|
||
}
|
||
|
||
#[test]
|
||
fn published_a11y_tree_exposes_dialog_children_restores_focus_and_sheet_close_passes_clicks() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.more_btn");
|
||
|
||
// Verify published_a11y_tree has valid Dialog with children.
|
||
let (errors, has_done_child) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let tree = v.published_a11y_tree();
|
||
let dialog = tree.nodes.get("app.sheet.dialog").expect("dialog node");
|
||
(
|
||
validate_accessibility_tree(tree),
|
||
dialog.children.iter().any(|c| c == "mobile.sheet.done_btn"),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(errors.is_empty(), "a11y errors: {errors:?}");
|
||
assert!(has_done_child);
|
||
|
||
// Click Done and advance only 60ms (mid-close transition!): content must remain mounted,
|
||
// focus restored to trigger `mobile.page.more_btn`, AND underlying `< Back` button clickable!
|
||
t.click_id_with_advance("mobile.sheet.done_btn", 60);
|
||
let (panel_present, focus_restored) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
let focused_more = v
|
||
.published_a11y_tree()
|
||
.nodes
|
||
.get("mobile.page.more_btn")
|
||
.is_some_and(|n| n.focused);
|
||
(
|
||
snap.elements.contains_key("mobile.sheet.panel"),
|
||
focused_more,
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(
|
||
panel_present,
|
||
"closing sheet must retain content mid-flight"
|
||
);
|
||
assert!(
|
||
focus_restored,
|
||
"closing sheet must restore focus to trigger"
|
||
);
|
||
|
||
// Click `< Back` WHILE sheet is still closing -> input must pass through to underlying route!
|
||
t.click_id("mobile.page.back_btn");
|
||
let route = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Home);
|
||
}
|
||
|
||
#[test]
|
||
fn compact_landscape_location_sheet_keeps_owner_locations_and_use_trail_reachable() {
|
||
let t = TestApp::launch(568, 320, MobileLocale::En);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state
|
||
.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||
let parent_seq = v
|
||
.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.expect("doc-arch entry")
|
||
.seq;
|
||
v.state.open_doc(
|
||
"doc-sync",
|
||
Origin::DocLink {
|
||
parent_seq,
|
||
block_id: Some("b-ref-sync".into()),
|
||
},
|
||
);
|
||
v.state.open_sheet(MobileSheet::LocationAndTrail, 0.0);
|
||
v.state.settle_animations(500.0);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
let (owner_bounds, use_trail_hidden_initially) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
let owner = snap
|
||
.elements
|
||
.get("mobile.sheet.owner_loc.0")
|
||
.expect("owner_loc.0 must remain mounted on 568x320 landscape")
|
||
.bounds;
|
||
(
|
||
owner,
|
||
!snap.elements.contains_key("mobile.sheet.use_trail_btn"),
|
||
)
|
||
})
|
||
})
|
||
.expect("read compact landscape snapshot");
|
||
|
||
assert!(owner_bounds.width >= 44.0 && owner_bounds.height >= 44.0);
|
||
assert!(
|
||
use_trail_hidden_initially,
|
||
"use_trail_btn should only render when can_return_to_trail is true"
|
||
);
|
||
|
||
// Pick cur's own location, reopen sheet, and verify `Return to Trail` is mounted and >= 44x44.
|
||
// The compact menu scrolls its rows, so the reopen goes through the accessibility actions.
|
||
t.click_id("mobile.sheet.loc.0");
|
||
t.click_id("mobile.page.more_btn");
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
assert!(v.perform_a11y_action(
|
||
"mobile.sheet.doc_action.location_trail",
|
||
MobileA11yAction::Activate,
|
||
cx,
|
||
));
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.platform.advance_clock(Duration::from_millis(400));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
let use_trail_bounds = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
window
|
||
.frame_snapshot()
|
||
.elements
|
||
.get("mobile.sheet.use_trail_btn")
|
||
.expect("use_trail_btn must be mounted after cur location pick")
|
||
.bounds
|
||
})
|
||
})
|
||
.expect("read compact landscape snapshot after pick");
|
||
assert!(use_trail_bounds.width >= 44.0 && use_trail_bounds.height >= 44.0);
|
||
}
|
||
|
||
#[test]
|
||
fn explorer_drilldown_back_pops_history_with_dynamic_parent_label() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.tab.explorer");
|
||
t.click_id("mobile.explorer.folder.f-eng");
|
||
t.click_id("mobile.explorer.folder.f-mobile");
|
||
|
||
let (len_at_mobile, back_name_at_mobile) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let name = v
|
||
.published_a11y_tree()
|
||
.nodes
|
||
.get("mobile.explorer.back_btn")
|
||
.map(|n| n.name.clone())
|
||
.unwrap_or_default();
|
||
(v.state.active_workspace().history.len(), name)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(len_at_mobile, 3);
|
||
assert_eq!(back_name_at_mobile, "Engineering");
|
||
|
||
t.click_id("mobile.explorer.back_btn");
|
||
let (target_after_1, len_after_1, back_name_at_eng) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let name = v
|
||
.published_a11y_tree()
|
||
.nodes
|
||
.get("mobile.explorer.back_btn")
|
||
.map(|n| n.name.clone())
|
||
.unwrap_or_default();
|
||
(
|
||
v.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.map(|e| e.target.clone()),
|
||
v.state.active_workspace().history.len(),
|
||
name,
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(target_after_1, Some(NavTarget::Folder("f-eng".into())));
|
||
assert_eq!(len_after_1, 2, "drill-down back must pop rather than push");
|
||
assert_eq!(back_name_at_eng, "All Docs");
|
||
|
||
t.click_id("mobile.explorer.back_btn");
|
||
let (target_after_2, len_after_2, root_back_action) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let target = v
|
||
.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.map(|e| e.target.clone());
|
||
let len = v.state.active_workspace().history.len();
|
||
let action = MobileBackCoordinator::handle_back(&mut v.state, 1000.0);
|
||
(target, len, action)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(target_after_2, Some(NavTarget::AllDocs));
|
||
assert_eq!(len_after_2, 1);
|
||
assert_eq!(root_back_action, BackOutcome::YieldToHostExit);
|
||
}
|
||
|
||
#[test]
|
||
fn explorer_collections_and_tags_index_filter_exact_members() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.tab.explorer");
|
||
t.click_id("mobile.explorer.collections");
|
||
t.click_id("mobile.explorer.collection.col-sync");
|
||
|
||
let (has_sync, has_journal, has_arch) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
(
|
||
snap.elements
|
||
.contains_key("mobile.explorer.doc.14:ws-mobile-rustdoc-sync"),
|
||
snap.elements
|
||
.contains_key("mobile.explorer.doc.14:ws-mobile-rustdoc-journal"),
|
||
snap.elements
|
||
.contains_key("mobile.explorer.doc.14:ws-mobile-rustdoc-arch"),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(
|
||
has_sync && has_journal,
|
||
"col-sync must show its member docs"
|
||
);
|
||
assert!(!has_arch, "col-sync must not show non-member doc-arch");
|
||
|
||
t.click_id("mobile.explorer.back_btn");
|
||
let target_index = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
v.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.map(|e| e.target.clone())
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(target_index, Some(NavTarget::Collection(String::new())));
|
||
|
||
t.click_id("mobile.explorer.back_btn");
|
||
t.click_id("mobile.explorer.tags");
|
||
t.click_id("mobile.explorer.tag.sync");
|
||
let (tag_has_sync, tag_has_arch) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
(
|
||
snap.elements
|
||
.contains_key("mobile.explorer.doc.14:ws-mobile-rustdoc-sync"),
|
||
snap.elements
|
||
.contains_key("mobile.explorer.doc.14:ws-mobile-rustdoc-arch"),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(tag_has_sync);
|
||
assert!(!tag_has_arch);
|
||
}
|
||
|
||
#[test]
|
||
fn search_single_channel_input_and_reversed_range_clamping() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.tab.search");
|
||
t.click_id("mobile.search.clear_btn");
|
||
t.click_id("mobile.search.input");
|
||
|
||
// Simulate both KeyDown('a') and EntityInputHandler::replace_text_in_range("a"):
|
||
// query must receive "a" once, never "aa".
|
||
let mut ks_a = Keystroke::parse("a").unwrap();
|
||
ks_a.key_char = Some("a".into());
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::KeyDown(KeyDownEvent {
|
||
keystroke: ks_a,
|
||
is_held: false,
|
||
prefer_character_input: false,
|
||
}));
|
||
t.platform.run_until_parked();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.replace_text_in_range(None, "a", window, cx);
|
||
assert_eq!(
|
||
v.state.search_query, "a",
|
||
"printable input must not duplicate across key_down + EntityInputHandler"
|
||
);
|
||
// Reversed / out-of-bounds range must clamp safely without panicking.
|
||
let reversed = std::ops::Range { start: 5, end: 1 };
|
||
v.replace_text_in_range(Some(reversed), "b", window, cx);
|
||
assert_eq!(v.state.search_query, "ab");
|
||
})
|
||
})
|
||
.unwrap();
|
||
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::KeyDown(KeyDownEvent {
|
||
keystroke: Keystroke::parse("backspace").unwrap(),
|
||
is_held: false,
|
||
prefer_character_input: false,
|
||
}));
|
||
t.platform.run_until_parked();
|
||
let query_after_bs = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle
|
||
.update(cx, |v, _, _| v.state.search_query.clone())
|
||
})
|
||
.unwrap();
|
||
assert_eq!(query_after_bs, "a");
|
||
}
|
||
|
||
#[test]
|
||
fn host_a11y_sink_receives_published_tree_with_contained_dialog_bounds_and_actions() {
|
||
let sink = InMemoryPlatformAccessibility::new();
|
||
let sink_for_view = sink.clone();
|
||
|
||
let platform = HeadlessPlatform::new(390, 844, 1.0);
|
||
let handle_cell: Rc<RefCell<Option<WindowHandle<MobileShellView>>>> =
|
||
Rc::new(RefCell::new(None));
|
||
let handle_out = handle_cell.clone();
|
||
let app = Application::with_platform(platform.clone()).run_embedded(move |cx| {
|
||
register_mobile_fonts(cx).expect("register mobile fonts");
|
||
let state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||
let win = cx
|
||
.open_window(
|
||
WindowOptions {
|
||
window_bounds: Some(WindowBounds::Windowed(Bounds::new(
|
||
point(px(0.0), px(0.0)),
|
||
size(px(390.0), px(844.0)),
|
||
))),
|
||
..WindowOptions::default()
|
||
},
|
||
move |_, cx| {
|
||
cx.new(|cx| {
|
||
MobileShellView::with_a11y_sink(
|
||
state,
|
||
Arc::new(Mutex::new(sink_for_view)),
|
||
cx,
|
||
)
|
||
})
|
||
},
|
||
)
|
||
.expect("open headless mobile window");
|
||
*handle_out.borrow_mut() = Some(win);
|
||
});
|
||
let window_handle = handle_cell.borrow_mut().take().unwrap();
|
||
let headless_win = platform.windows().into_iter().next().unwrap();
|
||
headless_win.request_frame();
|
||
assert!(sink.publish_count() >= 1);
|
||
|
||
app.update(|cx| {
|
||
window_handle.update(cx, |v, _, cx| {
|
||
v.state
|
||
.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||
assert!(v.perform_a11y_action("mobile.page.more_btn", MobileA11yAction::Activate, cx));
|
||
assert!(v.perform_a11y_action(
|
||
"mobile.sheet.doc_action.location_trail",
|
||
MobileA11yAction::Activate,
|
||
cx
|
||
));
|
||
})
|
||
})
|
||
.unwrap();
|
||
platform.advance_clock(Duration::from_millis(400));
|
||
platform.run_until_parked();
|
||
headless_win.request_frame();
|
||
|
||
let tree = sink.latest_tree().expect("latest published tree");
|
||
assert!(validate_accessibility_tree(&tree).is_empty());
|
||
let dialog = tree.nodes.get("app.sheet.dialog").expect("dialog node");
|
||
assert!(dialog.bounds.y > 0.0);
|
||
for child_id in &dialog.children {
|
||
let c = tree.nodes.get(child_id).expect("dialog child");
|
||
assert!(
|
||
c.bounds.x >= dialog.bounds.x - 0.5
|
||
&& c.bounds.y >= dialog.bounds.y - 0.5
|
||
&& c.bounds.x + c.bounds.width <= dialog.bounds.x + dialog.bounds.width + 0.5
|
||
&& c.bounds.y + c.bounds.height <= dialog.bounds.y + dialog.bounds.height + 0.5,
|
||
"dialog child `{child_id}` {:?} exceeds dialog {:?}",
|
||
c.bounds,
|
||
dialog.bounds
|
||
);
|
||
}
|
||
|
||
app.update(|cx| {
|
||
window_handle.update(cx, |v, _, cx| {
|
||
assert!(v.perform_a11y_action("mobile.sheet.loc.0", MobileA11yAction::Activate, cx));
|
||
})
|
||
})
|
||
.unwrap();
|
||
platform.advance_clock(Duration::from_millis(400));
|
||
platform.run_until_parked();
|
||
headless_win.request_frame();
|
||
|
||
let final_tree = sink.latest_tree().expect("post-action tree");
|
||
assert!(!final_tree.nodes.contains_key("app.sheet.dialog"));
|
||
assert!(
|
||
final_tree
|
||
.nodes
|
||
.get("mobile.page.more_btn")
|
||
.is_some_and(|n| n.focused)
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn single_click_sheet_animation_completes_via_request_animation_frame_without_extra_input() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
|
||
t.click_id_with_advance("mobile.page.more_btn", 0);
|
||
for _ in 0..24 {
|
||
t.platform.advance_clock(Duration::from_millis(16));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
}
|
||
let (open_done, active_sheet) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
let now_ms = v.clock_ms(cx);
|
||
(!v.state.has_active_animation(now_ms), v.state.active_sheet)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(active_sheet, MobileSheet::DocActions);
|
||
assert!(open_done);
|
||
|
||
t.click_id_with_advance("mobile.sheet.done_btn", 0);
|
||
for _ in 0..24 {
|
||
t.platform.advance_clock(Duration::from_millis(16));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
}
|
||
let (close_done, panel_mounted) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
let now_ms = v.clock_ms(cx);
|
||
(
|
||
!v.state.has_active_animation(now_ms),
|
||
window
|
||
.frame_snapshot()
|
||
.elements
|
||
.contains_key("mobile.sheet.panel"),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(close_done);
|
||
assert!(!panel_mounted);
|
||
}
|
||
|
||
#[test]
|
||
fn create_doc_from_home_explorer_root_and_folder_opens_with_expected_origin() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::ZhHans);
|
||
|
||
// 1. Create doc from Home `+` button -> empty stored title, localized display_title,
|
||
// workspace-scoped id, Origin::Direct(AllDocs).
|
||
t.click_id("mobile.home.new_doc_btn");
|
||
let (route1, stored_title1, display_zh, display_en, origin1) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let id = match &v.state.route {
|
||
MobileRoute::Page(id) => id.clone(),
|
||
other => panic!("expected Page route, got {other:?}"),
|
||
};
|
||
let doc = v.state.doc_by_id(&id).unwrap();
|
||
let origin = v
|
||
.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.unwrap()
|
||
.origin
|
||
.clone();
|
||
(
|
||
id,
|
||
doc.title.clone(),
|
||
doc.display_title(MobileLocale::ZhHans),
|
||
doc.display_title(MobileLocale::En),
|
||
origin,
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route1, "doc-ws-mobile-rust-new-1");
|
||
assert!(
|
||
stored_title1.is_empty(),
|
||
"new doc stored title must stay empty so locale switches update display_title"
|
||
);
|
||
assert_eq!(display_zh, "无标题");
|
||
assert_eq!(display_en, "Untitled");
|
||
assert_eq!(origin1, Origin::Direct(DirectKind::AllDocs));
|
||
|
||
// 2. Return to Home, go to All Docs root -> newly created doc and unfiled journal are listed.
|
||
t.click_id("mobile.page.back_btn");
|
||
t.click_id("mobile.tab.explorer");
|
||
let (has_new_doc, has_journal) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
(
|
||
snap.elements.contains_key(
|
||
"mobile.explorer.doc.14:ws-mobile-rustdoc-ws-mobile-rust-new-1",
|
||
),
|
||
snap.elements
|
||
.contains_key("mobile.explorer.doc.14:ws-mobile-rustdoc-journal"),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(
|
||
has_new_doc,
|
||
"new doc must appear in All Docs Documents list"
|
||
);
|
||
assert!(
|
||
has_journal,
|
||
"unfiled journal doc must appear in All Docs Documents list"
|
||
);
|
||
|
||
// 3. Drill into folder `f-eng` and click `+` -> creates doc mounted in `f-eng` with valid fractional index.
|
||
t.click_id("mobile.explorer.folder.f-eng");
|
||
t.click_id("mobile.explorer.new_doc_btn");
|
||
let (route2, origin2, folder_index) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let id = match &v.state.route {
|
||
MobileRoute::Page(id) => id.clone(),
|
||
other => panic!("expected Page route, got {other:?}"),
|
||
};
|
||
let origin = v
|
||
.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.unwrap()
|
||
.origin
|
||
.clone();
|
||
let idx = v
|
||
.state
|
||
.active_workspace()
|
||
.folder_rows
|
||
.iter()
|
||
.find(|r| {
|
||
r.folder_type == "doc"
|
||
&& r.data == id
|
||
&& r.parent_id.as_deref() == Some("f-eng")
|
||
})
|
||
.map(|r| r.index.clone());
|
||
(id, origin, idx)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route2, "doc-ws-mobile-rust-new-2");
|
||
assert!(matches!(origin2, Origin::Placement { .. }));
|
||
let idx = folder_index.expect("new folder doc must be linked under f-eng");
|
||
assert!(
|
||
idx.as_str() > "a0" && !idx.starts_with("z9"),
|
||
"folder doc index {idx:?} must be a valid fractional index after existing siblings"
|
||
);
|
||
|
||
// 4. Opening a nonexistent doc renders explicit `Document not found` empty state.
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state.route = MobileRoute::Page("doc-does-not-exist".into());
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
let has_not_found = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
snap.elements.contains_key("mobile.page.not_found")
|
||
&& snap.elements.contains_key("mobile.page.not_found_back_btn")
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(
|
||
has_not_found,
|
||
"missing doc id must render explicit Document not found state"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn search_no_results_omits_bordered_list_and_shows_empty_state() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.tab.search");
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state.search_query = "NonexistentQuery".to_string();
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
let (has_list, has_empty) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
(
|
||
snap.elements.contains_key("mobile.search.results"),
|
||
snap.elements.contains_key("mobile.search.empty_state"),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(!has_list, "empty search must not render bordered list box");
|
||
assert!(has_empty, "empty search must render centered empty state");
|
||
}
|
||
|
||
#[test]
|
||
fn journals_week_strip_switches_date_and_creates_new_journal_for_empty_day() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.tab.journals");
|
||
|
||
// Today (2026-11-25) already has `doc-journal`: clicking CTA opens it without creating a new doc.
|
||
let docs_before = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle
|
||
.update(cx, |v, _, _| v.state.active_workspace().docs().len())
|
||
})
|
||
.unwrap();
|
||
t.click_id("mobile.journals.create_btn");
|
||
let (route_today, docs_after_today) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
(
|
||
v.state.route.clone(),
|
||
v.state.active_workspace().docs().len(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route_today, MobileRoute::Page("doc-journal".into()));
|
||
assert_eq!(docs_after_today, docs_before);
|
||
|
||
// Go back, select 2026-11-26 (no journal yet), and click CTA -> creates & opens new journal.
|
||
t.click_id("mobile.page.back_btn");
|
||
t.click_id("mobile.journals.day.2026-11-26");
|
||
t.click_id("mobile.journals.create_btn");
|
||
let (new_route, new_title, new_date, origin) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
let id = match &v.state.route {
|
||
MobileRoute::Page(id) => id.clone(),
|
||
other => panic!("expected Page route, got {other:?}"),
|
||
};
|
||
let doc = v.state.doc_by_id(&id).unwrap();
|
||
(
|
||
id,
|
||
doc.title.clone(),
|
||
doc.journal_date.clone(),
|
||
v.state
|
||
.active_workspace()
|
||
.history
|
||
.current()
|
||
.unwrap()
|
||
.origin
|
||
.clone(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_ne!(new_route, "doc-journal");
|
||
assert_eq!(new_title, "Journal 2026-11-26");
|
||
assert_eq!(new_date.as_deref(), Some("2026-11-26"));
|
||
assert_eq!(origin, Origin::Journal);
|
||
}
|
||
|
||
#[test]
|
||
fn trashed_doc_supports_restore_ready_backlinks_two_step_delete_and_history_purge() {
|
||
// 1. Restore clears trashed flag, hides banner, keeps backlinks `Ready` workspace-wide,
|
||
// and rejects late/stale delete or restore calls on non-trashed or wrong-workspace docs.
|
||
let t1 = TestApp::launch(390, 844, MobileLocale::En);
|
||
t1.click_id("mobile.tab.explorer");
|
||
t1.click_id("mobile.explorer.trash");
|
||
t1.click_id("mobile.explorer.doc.14:ws-mobile-rustdoc-trash");
|
||
t1.click_id("mobile.page.trash_restore_btn.14:ws-mobile-rustdoc-trash");
|
||
let (route_after_restore, still_trashed, has_banner, arch_bl_ready, arch_bl_len) = t1
|
||
.app
|
||
.update(|cx| {
|
||
t1.window_handle.update(cx, |v, window, _| {
|
||
let bl = v.state.backlinks_for("doc-arch");
|
||
assert!(!v.state.restore_doc_scoped("ws-mobile-rust", "doc-trash"));
|
||
assert!(!v.state.delete_doc_permanently_scoped(
|
||
"ws-mobile-rust",
|
||
"doc-trash",
|
||
500.0
|
||
));
|
||
assert!(
|
||
!v.state
|
||
.delete_doc_permanently_scoped("ws-personal", "doc-trash", 500.0)
|
||
);
|
||
(
|
||
v.state.route.clone(),
|
||
v.state.doc_by_id("doc-trash").unwrap().trashed,
|
||
window
|
||
.frame_snapshot()
|
||
.elements
|
||
.contains_key("mobile.page.trash_banner"),
|
||
bl.completeness == affine_client::BacklinkCompleteness::Ready,
|
||
bl.items.len(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route_after_restore, MobileRoute::Page("doc-trash".into()));
|
||
assert!(!still_trashed);
|
||
assert!(!has_banner);
|
||
assert!(
|
||
arch_bl_ready,
|
||
"restoring trashed doc must sync link_graph clock so backlinks stay Ready"
|
||
);
|
||
assert_eq!(arch_bl_len, 2);
|
||
|
||
// 2. Delete permanently requires two-step confirmation; Cancel preserves doc; Confirm purges
|
||
// all history entries pointing to `doc-trash` (`Home -> doc-trash -> doc-arch -> doc-trash`).
|
||
let t2 = TestApp::launch(390, 844, MobileLocale::En);
|
||
t2.app
|
||
.update(|cx| {
|
||
t2.window_handle.update(cx, |v, _, cx| {
|
||
v.state
|
||
.open_doc("doc-trash", Origin::Direct(DirectKind::AllDocs));
|
||
v.state
|
||
.open_doc("doc-arch", Origin::Direct(DirectKind::Home));
|
||
v.state
|
||
.open_doc("doc-trash", Origin::Direct(DirectKind::AllDocs));
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t2.platform.run_until_parked();
|
||
t2.headless_win.request_frame();
|
||
|
||
// First click opens confirmation sheet without deleting.
|
||
t2.click_id("mobile.page.trash_delete_btn.14:ws-mobile-rustdoc-trash");
|
||
let (sheet_after_first, doc_still_exists) = t2
|
||
.app
|
||
.update(|cx| {
|
||
t2.window_handle.update(cx, |v, _, _| {
|
||
(
|
||
v.state.active_sheet,
|
||
v.state.doc_by_id("doc-trash").is_some(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(sheet_after_first, MobileSheet::ConfirmDeleteDoc);
|
||
assert!(doc_still_exists, "first click must NOT delete immediately");
|
||
let has_done_btn = t2
|
||
.app
|
||
.update(|cx| {
|
||
t2.window_handle.update(cx, |_, window, _| {
|
||
window
|
||
.frame_snapshot()
|
||
.elements
|
||
.contains_key("mobile.sheet.done_btn")
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert!(
|
||
!has_done_btn,
|
||
"ConfirmDeleteDoc sheet must not render ambiguous top-right Done button"
|
||
);
|
||
|
||
// Cancel closes sheet and keeps doc intact.
|
||
t2.click_id("app.sheet.delete_cancel.14:ws-mobile-rustdoc-trash");
|
||
let (sheet_after_cancel, doc_after_cancel) = t2
|
||
.app
|
||
.update(|cx| {
|
||
t2.window_handle.update(cx, |v, _, _| {
|
||
(
|
||
v.state.active_sheet,
|
||
v.state.doc_by_id("doc-trash").is_some(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(sheet_after_cancel, MobileSheet::None);
|
||
assert!(doc_after_cancel);
|
||
|
||
// Reopen and confirm delete -> doc removed, lands on `doc-arch`, one Back goes straight to `Home`.
|
||
t2.click_id("mobile.page.trash_delete_btn.14:ws-mobile-rustdoc-trash");
|
||
t2.click_id("app.sheet.delete_confirm.14:ws-mobile-rustdoc-trash");
|
||
let (route_after_del, doc_exists) = t2
|
||
.app
|
||
.update(|cx| {
|
||
t2.window_handle.update(cx, |v, _, _| {
|
||
(
|
||
v.state.route.clone(),
|
||
v.state.doc_by_id("doc-trash").is_some(),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route_after_del, MobileRoute::Page("doc-arch".into()));
|
||
assert!(!doc_exists);
|
||
|
||
t2.click_id("mobile.page.back_btn");
|
||
let route_after_back = t2
|
||
.app
|
||
.update(|cx| t2.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(
|
||
route_after_back,
|
||
MobileRoute::Home,
|
||
"Back after permanent delete must skip purged ghost entries and reach Home"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn explorer_scrolls_30_docs_keeps_tabbar_fixed_and_opens_30th_doc() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
for i in 1..=30 {
|
||
v.state.active_workspace_mut().docs_mut().push(
|
||
affine_mobile::MobileDocRecord {
|
||
id: format!("doc-bulk-{i}"),
|
||
title: format!("Bulk Document {i}"),
|
||
body_preview: format!("Preview {i}"),
|
||
tags: Vec::new(),
|
||
updated_at_ms: 1_764_000_000 + i as i64,
|
||
is_favorite: false,
|
||
trashed: false,
|
||
journal_date: None,
|
||
primary_mode: affine_mobile::state::DocMode::Page,
|
||
clock: 1,
|
||
outgoing_edges: Vec::new(),
|
||
blocks: Vec::new(),
|
||
},
|
||
);
|
||
}
|
||
v.state.switch_tab(affine_mobile::MobileTab::Explorer, 0.0);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
let tabbar_before = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
window.frame_snapshot().elements["mobile.tabbar"].bounds
|
||
})
|
||
})
|
||
.unwrap();
|
||
|
||
// Dispatch real scroll-wheel events to scroll to the bottom of the 30-doc list.
|
||
for _ in 0..8 {
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Scroll(ui::ScrollEvent {
|
||
position: point(px(195.0), px(400.0)),
|
||
delta: ui::ScrollDelta::Pixels(point(px(0.0), px(-300.0))),
|
||
modifiers: ui::Modifiers::default(),
|
||
touch_phase: ui::TouchPhase::Moved,
|
||
..Default::default()
|
||
}));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
}
|
||
|
||
let doc30_id = "mobile.explorer.doc.14:ws-mobile-rustdoc-bulk-30";
|
||
let (tabbar_after, snap_bounds, a11y_bounds) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
let tb = snap.elements["mobile.tabbar"].bounds;
|
||
let sb = snap
|
||
.elements
|
||
.get(doc30_id)
|
||
.expect("30th doc must be visible in FrameSnapshot after scrolling")
|
||
.bounds;
|
||
let ab = v
|
||
.published_a11y_tree()
|
||
.nodes
|
||
.get(doc30_id)
|
||
.expect("30th doc must be published in AccessibilityTree after scrolling")
|
||
.bounds;
|
||
(tb, sb, ab)
|
||
})
|
||
})
|
||
.unwrap();
|
||
|
||
assert!((tabbar_after.y - tabbar_before.y).abs() <= 0.5);
|
||
let drift = (snap_bounds.x - a11y_bounds.x)
|
||
.abs()
|
||
.max((snap_bounds.y - a11y_bounds.y).abs())
|
||
.max((snap_bounds.width - a11y_bounds.width).abs())
|
||
.max((snap_bounds.height - a11y_bounds.height).abs());
|
||
assert!(drift <= 1.0, "30th doc a11y drift {drift:.2}px");
|
||
|
||
t.click_id(doc30_id);
|
||
let route = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Page("doc-bulk-30".into()));
|
||
}
|
||
|
||
#[test]
|
||
fn touch_swipe_scrolls_30_docs_without_accidental_click_and_back_restores_scroll() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
for i in 1..=30 {
|
||
v.state.active_workspace_mut().docs_mut().push(
|
||
affine_mobile::MobileDocRecord {
|
||
id: format!("doc-bulk-{i}"),
|
||
title: format!("Bulk Document {i}"),
|
||
body_preview: format!("Preview {i}"),
|
||
tags: Vec::new(),
|
||
updated_at_ms: 1_764_000_000 + i as i64,
|
||
is_favorite: false,
|
||
trashed: false,
|
||
journal_date: None,
|
||
primary_mode: affine_mobile::state::DocMode::Page,
|
||
clock: 1,
|
||
outgoing_edges: Vec::new(),
|
||
blocks: Vec::new(),
|
||
},
|
||
);
|
||
}
|
||
v.state.switch_tab(affine_mobile::MobileTab::Explorer, 0.0);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
let tabbar_before = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
window.frame_snapshot().elements["mobile.tabbar"].bounds
|
||
})
|
||
})
|
||
.unwrap();
|
||
|
||
// Perform 4 native Touch pan swipes upward (y=600 -> y=160) to scroll to the 30th doc.
|
||
for swipe in 0..4u64 {
|
||
let touch_id = ui::TouchId(swipe + 1);
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Touch(ui::TouchEvent {
|
||
id: touch_id,
|
||
phase: ui::TouchPhase::Started,
|
||
position: point(px(195.0), px(600.0)),
|
||
predicted_position: None,
|
||
force: None,
|
||
}));
|
||
for step in 1..=8 {
|
||
let y = 600.0 - (step as f32) * 55.0;
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Touch(ui::TouchEvent {
|
||
id: touch_id,
|
||
phase: ui::TouchPhase::Moved,
|
||
position: point(px(195.0), px(y)),
|
||
predicted_position: None,
|
||
force: None,
|
||
}));
|
||
}
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Touch(ui::TouchEvent {
|
||
id: touch_id,
|
||
phase: ui::TouchPhase::Ended,
|
||
position: point(px(195.0), px(160.0)),
|
||
predicted_position: None,
|
||
force: None,
|
||
}));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
}
|
||
|
||
let doc30_id = format!(
|
||
"mobile.explorer.doc.{}",
|
||
affine_mobile::encode_scoped_doc_target("ws-mobile-rust", "doc-bulk-30")
|
||
);
|
||
let (route_after_swipe, scroll_after_swipe, tabbar_after, doc30_bounds) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
(
|
||
v.state.route.clone(),
|
||
v.state.explorer_scroll_y,
|
||
snap.elements["mobile.tabbar"].bounds,
|
||
snap.elements
|
||
.get(&doc30_id)
|
||
.expect("30th doc must be visible after touch swipe")
|
||
.bounds,
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(
|
||
route_after_swipe,
|
||
MobileRoute::Explorer,
|
||
"touch swipe must never accidentally open an intermediate document"
|
||
);
|
||
assert!(
|
||
scroll_after_swipe > 600.0,
|
||
"expected scroll_y > 600 after swipes, got {scroll_after_swipe}"
|
||
);
|
||
assert!((tabbar_after.y - tabbar_before.y).abs() <= 0.5);
|
||
|
||
// Tap the 30th document via native Touch Started -> Ended.
|
||
let tap_pos = point(
|
||
px(doc30_bounds.x + doc30_bounds.width * 0.5),
|
||
px(doc30_bounds.y + doc30_bounds.height * 0.5),
|
||
);
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Touch(ui::TouchEvent {
|
||
id: ui::TouchId(99),
|
||
phase: ui::TouchPhase::Started,
|
||
position: tap_pos,
|
||
predicted_position: None,
|
||
force: None,
|
||
}));
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Touch(ui::TouchEvent {
|
||
id: ui::TouchId(99),
|
||
phase: ui::TouchPhase::Ended,
|
||
position: tap_pos,
|
||
predicted_position: None,
|
||
force: None,
|
||
}));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
let route_after_tap = t
|
||
.app
|
||
.update(|cx| t.window_handle.update(cx, |v, _, _| v.state.route.clone()))
|
||
.unwrap();
|
||
assert_eq!(route_after_tap, MobileRoute::Page("doc-bulk-30".into()));
|
||
|
||
// Pressing Back must restore the exact saved Explorer scroll position.
|
||
t.click_id("mobile.page.back_btn");
|
||
let (route_after_back, restored_scroll) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
(v.state.route.clone(), v.state.explorer_scroll_y)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route_after_back, MobileRoute::Explorer);
|
||
assert!(
|
||
(restored_scroll - scroll_after_swipe).abs() <= 1.0,
|
||
"expected restored scroll {scroll_after_swipe}, got {restored_scroll}"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn mouse_drag_off_list_and_hover_does_not_scroll_or_open_doc() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
for i in 1..=30 {
|
||
v.state.active_workspace_mut().docs_mut().push(
|
||
affine_mobile::MobileDocRecord {
|
||
id: format!("doc-bulk-{i}"),
|
||
title: format!("Bulk Document {i}"),
|
||
body_preview: format!("Preview {i}"),
|
||
tags: Vec::new(),
|
||
updated_at_ms: 1_764_000_000 + i as i64,
|
||
is_favorite: false,
|
||
trashed: false,
|
||
journal_date: None,
|
||
primary_mode: affine_mobile::state::DocMode::Page,
|
||
clock: 1,
|
||
outgoing_edges: Vec::new(),
|
||
blocks: Vec::new(),
|
||
},
|
||
);
|
||
}
|
||
v.state.switch_tab(affine_mobile::MobileTab::Explorer, 0.0);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
// Press mouse on a list row, drag onto the bottom TabBar, release on TabBar, then hover back across list.
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::MouseDown(ui::MouseDownEvent {
|
||
button: ui::MouseButton::Left,
|
||
position: point(px(195.0), px(450.0)),
|
||
modifiers: ui::Modifiers::default(),
|
||
click_count: 1,
|
||
first_mouse: false,
|
||
}));
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::MouseMove(ui::MouseMoveEvent {
|
||
position: point(px(195.0), px(810.0)),
|
||
pressed_button: Some(ui::MouseButton::Left),
|
||
modifiers: ui::Modifiers::default(),
|
||
}));
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::MouseUp(ui::MouseUpEvent {
|
||
button: ui::MouseButton::Left,
|
||
position: point(px(195.0), px(810.0)),
|
||
modifiers: ui::Modifiers::default(),
|
||
click_count: 1,
|
||
}));
|
||
for y in [700.0_f32, 550.0, 400.0, 250.0] {
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::MouseMove(ui::MouseMoveEvent {
|
||
position: point(px(195.0), px(y)),
|
||
pressed_button: None,
|
||
modifiers: ui::Modifiers::default(),
|
||
}));
|
||
}
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
let (route, scroll_y) = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, _| {
|
||
(v.state.route.clone(), v.state.explorer_scroll_y)
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(route, MobileRoute::Explorer);
|
||
assert_eq!(
|
||
scroll_y, 0.0,
|
||
"mouse drag off-list and subsequent unpressed hover must not scroll Explorer"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn doc_actions_view_switch_default_mode_and_header_readonly_toggle_drive_the_editor() {
|
||
use affine_mobile::state::DocMode;
|
||
use playground::PlaygroundMode;
|
||
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
let editor = |t: &TestApp| {
|
||
t.read(|v, cx| {
|
||
let pv = v.page_editor().expect("editor").read(cx);
|
||
(pv.mode(), pv.page_readonly())
|
||
})
|
||
};
|
||
assert_eq!(editor(&t), (PlaygroundMode::Page, false));
|
||
assert!(t.has_element("mobile.page.readonly_toggle"));
|
||
|
||
// Header toggle: Editing -> Read-only -> Editing.
|
||
for readonly in [true, false] {
|
||
t.click_id("mobile.page.readonly_toggle");
|
||
assert_eq!(editor(&t), (PlaygroundMode::Page, readonly));
|
||
}
|
||
|
||
// `EditorModeSwitch` changes the view only and closes the menu.
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.mode.edgeless");
|
||
assert_eq!(editor(&t).0, PlaygroundMode::Edgeless);
|
||
let (sheet, primary) = t.read(|v, _| {
|
||
(
|
||
v.state.active_sheet,
|
||
v.state.doc_by_id("doc-arch").unwrap().primary_mode,
|
||
)
|
||
});
|
||
assert_eq!((sheet, primary), (MobileSheet::None, DocMode::Page));
|
||
assert!(
|
||
!t.has_element("mobile.page.readonly_toggle"),
|
||
"Edgeless stays read-only on mobile"
|
||
);
|
||
|
||
// `Default to Edgeless mode` then `Default to Page mode` set the primary and view modes.
|
||
for (mode, view) in [
|
||
(DocMode::Edgeless, PlaygroundMode::Edgeless),
|
||
(DocMode::Page, PlaygroundMode::Page),
|
||
] {
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.default_mode");
|
||
let primary = t.read(|v, _| v.state.doc_by_id("doc-arch").unwrap().primary_mode);
|
||
assert_eq!((primary, editor(&t).0), (mode, view));
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn toc_sheet_refreshes_headings_after_an_edit_and_reveals_the_tapped_heading() {
|
||
use blocksuite_playground_doc::schema::ParagraphType;
|
||
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
add_headings(
|
||
&t,
|
||
[
|
||
(
|
||
"toc-h1".to_string(),
|
||
ParagraphType::H1,
|
||
"Overview".to_string(),
|
||
),
|
||
(
|
||
"toc-h2".to_string(),
|
||
ParagraphType::H2,
|
||
"Gestures".to_string(),
|
||
),
|
||
],
|
||
);
|
||
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.toc");
|
||
let toc = t.read(|v, _| {
|
||
v.state
|
||
.page_session
|
||
.toc
|
||
.iter()
|
||
.map(|e| (e.level, e.text.clone()))
|
||
.collect::<Vec<_>>()
|
||
});
|
||
assert_eq!(
|
||
toc,
|
||
[
|
||
(0, "Mobile Shell & Breadcrumb Spec".to_string()),
|
||
(1, "Overview".to_string()),
|
||
(2, "Gestures".to_string()),
|
||
]
|
||
);
|
||
assert!(t.has_element("mobile.sheet.toc.2"));
|
||
|
||
add_headings(
|
||
&t,
|
||
[("toc-h3".into(), ParagraphType::H3, "Appendix".into())],
|
||
);
|
||
assert!(t.has_element("mobile.sheet.toc.3"));
|
||
assert_eq!(
|
||
t.read(|v, _| v.published_a11y_tree().nodes["mobile.sheet.toc.3"]
|
||
.name
|
||
.clone()),
|
||
"Appendix"
|
||
);
|
||
|
||
t.click_id("mobile.sheet.toc.2");
|
||
let (sheet, active) = t.read(|v, cx| {
|
||
let pv = v.page_editor().expect("editor").read(cx);
|
||
(
|
||
v.state.active_sheet,
|
||
pv.active_outline_heading().map(str::to_string),
|
||
)
|
||
});
|
||
assert_eq!(sheet, MobileSheet::None);
|
||
assert_eq!(active.as_deref(), Some("toc-h2"));
|
||
}
|
||
|
||
#[test]
|
||
fn journal_conflicts_open_a_same_day_journal_and_remove_its_journal_mark() {
|
||
let t = launch_on_journal_with_twin();
|
||
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.journal_conflicts");
|
||
for id in ["doc-journal", "doc-journal-twin"] {
|
||
assert!(t.has_element(&format!("mobile.sheet.journal_conflict.doc.{id}")));
|
||
}
|
||
t.click_id("mobile.sheet.journal_conflict.doc.doc-journal-twin");
|
||
let route = t.read(|v, _| v.state.route.clone());
|
||
assert_eq!(route, MobileRoute::Page("doc-journal-twin".into()));
|
||
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.journal_conflicts");
|
||
t.click_id("mobile.sheet.journal_conflict.edit.doc-journal");
|
||
t.click_id("mobile.sheet.journal_conflict.remove_mark");
|
||
let (journal, twin, sheet) = t.read(|v, _| {
|
||
(
|
||
v.state
|
||
.doc_by_id("doc-journal")
|
||
.unwrap()
|
||
.journal_date
|
||
.clone(),
|
||
v.state
|
||
.doc_by_id("doc-journal-twin")
|
||
.unwrap()
|
||
.journal_date
|
||
.clone(),
|
||
v.state.active_sheet,
|
||
)
|
||
});
|
||
assert_eq!(journal, None);
|
||
assert_eq!(twin.as_deref(), Some("2026-11-25"));
|
||
assert_eq!(sheet, MobileSheet::None);
|
||
t.click_id("mobile.page.more_btn");
|
||
assert!(
|
||
!t.has_element("mobile.sheet.doc_action.journal_conflicts"),
|
||
"one journal left for the day"
|
||
);
|
||
}
|
||
|
||
/// Append headings `(block id, level, text)` to `doc-arch` in the embedded editor.
|
||
fn add_headings(
|
||
t: &TestApp,
|
||
headings: impl IntoIterator<
|
||
Item = (
|
||
String,
|
||
blocksuite_playground_doc::schema::ParagraphType,
|
||
String,
|
||
),
|
||
>,
|
||
) {
|
||
use blocksuite_playground_doc::schema::BlockSpec;
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
let editor = v.page_editor().expect("editor").clone();
|
||
editor.update(cx, |pv, cx| {
|
||
pv.edit_document(cx, |doc| {
|
||
let page = doc.workspace.page_mut("doc-arch").expect("page");
|
||
for (id, kind, text) in headings {
|
||
let spec = BlockSpec::Paragraph {
|
||
paragraph_type: kind,
|
||
text,
|
||
};
|
||
page.add_block(id, spec, Some("note-root"), None, 1)
|
||
.expect("add heading");
|
||
}
|
||
});
|
||
});
|
||
})
|
||
})
|
||
.unwrap();
|
||
}
|
||
|
||
/// The shell on `doc-journal` with a second untrashed journal of the same date.
|
||
fn launch_on_journal_with_twin() -> TestApp {
|
||
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||
let ws = state.active_workspace_mut();
|
||
let mut twin = ws.doc("doc-journal").expect("journal").clone();
|
||
twin.id = "doc-journal-twin".into();
|
||
twin.title = "Journal twin".into();
|
||
ws.docs_mut().push(twin);
|
||
let t = TestApp::launch_with_state(390, 844, state);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state
|
||
.open_doc("doc-journal", Origin::Direct(DirectKind::AllDocs));
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t
|
||
}
|
||
|
||
#[test]
|
||
fn toc_sheet_virtualizes_rows_and_reveals_them_by_click_or_accessibility() {
|
||
use blocksuite_playground_doc::schema::ParagraphType;
|
||
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
add_headings(
|
||
&t,
|
||
(1..=32).map(|i| {
|
||
(
|
||
format!("toc-{i}"),
|
||
ParagraphType::H2,
|
||
format!("Section {i}"),
|
||
)
|
||
}),
|
||
);
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.toc");
|
||
let last = "mobile.sheet.toc.32";
|
||
let visible = |t: &TestApp| {
|
||
t.headless_win.request_frame();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let snap = window.frame_snapshot();
|
||
let panel = snap.elements["mobile.sheet.panel"].bounds;
|
||
snap.elements.get(last).is_some_and(|row| {
|
||
row.bounds.y >= panel.y
|
||
&& row.bounds.y + row.bounds.height <= panel.y + panel.height
|
||
})
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
assert!(
|
||
!t.has_element(last),
|
||
"screen readers can reach unmounted rows"
|
||
);
|
||
t.read(|v, _| {
|
||
let tree = v.published_a11y_tree();
|
||
let expected: Vec<_> = (0..=32).map(|i| format!("mobile.sheet.toc.{i}")).collect();
|
||
let children: Vec<_> = tree.nodes["app.sheet.dialog"]
|
||
.children
|
||
.iter()
|
||
.filter(|id| id.starts_with("mobile.sheet.toc."))
|
||
.cloned()
|
||
.collect();
|
||
assert_eq!(children, expected);
|
||
assert_eq!(tree.nodes[last].name, "Section 32");
|
||
});
|
||
assert_eq!(t.read(|v, _| v.state.sheet_extent.content), 33.0 * 44.0);
|
||
|
||
let mut scrolls = Vec::new();
|
||
for _ in 0..12 {
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Scroll(ui::ScrollEvent {
|
||
position: point(px(195.0), px(700.0)),
|
||
delta: ui::ScrollDelta::Pixels(point(px(0.0), px(-300.0))),
|
||
modifiers: ui::Modifiers::default(),
|
||
touch_phase: ui::TouchPhase::Moved,
|
||
..Default::default()
|
||
}));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
scrolls.push(t.read(|v, _| v.state.sheet_scroll_y));
|
||
}
|
||
let max = t.read(|v, _| v.state.sheet_extent.max_scroll());
|
||
assert!(max > 360.0, "the scroll range follows the content: {max}");
|
||
assert_eq!(scrolls.last().copied(), Some(max), "{scrolls:?}");
|
||
assert!(visible(&t), "the last heading scrolls into the sheet");
|
||
|
||
let assert_revealed = |t: &TestApp| {
|
||
t.read(|v, cx| {
|
||
let pv = v.page_editor().expect("editor").read(cx);
|
||
assert_eq!(v.state.active_sheet, MobileSheet::None);
|
||
assert_eq!(pv.active_outline_heading(), Some("toc-32"));
|
||
});
|
||
};
|
||
t.click_id_with_advance(last, 0);
|
||
assert_revealed(&t);
|
||
assert_eq!(t.read(|v, _| v.state.page_session.toc.len()), 33);
|
||
t.platform.advance_clock(Duration::from_millis(400));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
assert_eq!(t.read(|v, _| v.state.page_session.toc.capacity()), 0);
|
||
|
||
let open_toc = || {
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.toc");
|
||
assert!(!t.has_element(last));
|
||
};
|
||
let action = |action| {
|
||
let handled = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle
|
||
.update(cx, |v, _, cx| v.perform_a11y_action(last, action, cx))
|
||
})
|
||
.unwrap();
|
||
assert!(handled);
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
};
|
||
open_toc();
|
||
action(MobileA11yAction::Focus);
|
||
assert!(visible(&t), "focus reveals the offscreen semantic row");
|
||
t.read(|v, _| {
|
||
let node = &v.published_a11y_tree().nodes[last];
|
||
assert!(node.focused);
|
||
assert_eq!(node.bounds.height, 44.0);
|
||
});
|
||
t.click_id("mobile.sheet.done_btn");
|
||
|
||
open_toc();
|
||
action(MobileA11yAction::Activate);
|
||
assert_revealed(&t);
|
||
}
|
||
|
||
#[test]
|
||
fn published_mode_switch_bounds_and_touch_targets_match_in_all_locales() {
|
||
for (locale, labels) in [
|
||
(MobileLocale::En, ["Page", "Edgeless"]),
|
||
(MobileLocale::ZhHans, ["页面", "无界"]),
|
||
(MobileLocale::Ar, ["صفحة", "بدون حواف"]),
|
||
] {
|
||
let t = TestApp::launch(390, 844, locale);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.more_btn");
|
||
let [page, edgeless] = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, _| {
|
||
let tree = v.published_a11y_tree();
|
||
let frame = window.frame_snapshot();
|
||
[
|
||
"mobile.sheet.doc_action.mode.page",
|
||
"mobile.sheet.doc_action.mode.edgeless",
|
||
]
|
||
.map(|id| {
|
||
let b = tree.nodes[id].bounds;
|
||
let visual = frame.elements[id].bounds;
|
||
assert_eq!(
|
||
(b.x, b.y, b.width, b.height),
|
||
(visual.x, visual.y, visual.width, visual.height),
|
||
"{locale:?} {id}"
|
||
);
|
||
assert!(b.width >= 44.0 && b.height >= 44.0);
|
||
(b, tree.nodes[id].name.clone())
|
||
})
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!([page.1.as_str(), edgeless.1.as_str()], labels);
|
||
assert_eq!(page.0.y, edgeless.0.y);
|
||
let (left, right) = if locale == MobileLocale::Ar {
|
||
(edgeless.0, page.0)
|
||
} else {
|
||
(page.0, edgeless.0)
|
||
};
|
||
assert!((left.x + left.width - right.x).abs() < 0.01);
|
||
let seam_edge = if locale == MobileLocale::Ar {
|
||
edgeless.0.x + edgeless.0.width - 0.5
|
||
} else {
|
||
edgeless.0.x + 0.5
|
||
};
|
||
t.headless_win
|
||
.simulate_click(point(px(seam_edge), px(edgeless.0.y + 2.0)));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
t.read(|v, cx| {
|
||
assert_eq!(v.state.active_sheet, MobileSheet::None);
|
||
assert_eq!(
|
||
v.page_editor().unwrap().read(cx).mode(),
|
||
playground::PlaygroundMode::Edgeless
|
||
);
|
||
});
|
||
}
|
||
}
|
||
|
||
fn sheet_scroll(t: &TestApp, position: ui::Point<ui::Pixels>, dy: f32) {
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::Scroll(ui::ScrollEvent {
|
||
position,
|
||
delta: ui::ScrollDelta::Pixels(point(px(0.0), px(dy))),
|
||
modifiers: ui::Modifiers::default(),
|
||
touch_phase: ui::TouchPhase::Moved,
|
||
..Default::default()
|
||
}));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
}
|
||
|
||
#[test]
|
||
fn journal_conflict_list_clamps_after_shrinking_and_keeps_edit_bounds() {
|
||
for locale in [MobileLocale::En, MobileLocale::ZhHans, MobileLocale::Ar] {
|
||
let mut state = seed_showcase_state(locale, ThemeMode::Light, "2026-11-25");
|
||
let ws = state.active_workspace_mut();
|
||
let journal = ws.doc("doc-journal").unwrap().clone();
|
||
ws.docs_mut().extend((1..32).map(|i| {
|
||
let mut copy = journal.clone();
|
||
copy.id = format!("duplicate-{i}");
|
||
copy.title = format!("Duplicate {i}");
|
||
copy
|
||
}));
|
||
state.open_doc("doc-journal", Origin::Direct(DirectKind::AllDocs));
|
||
let t = TestApp::launch_with_state(390, 844, state);
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.journal_conflicts");
|
||
|
||
let edit_id = "mobile.sheet.journal_conflict.edit.doc-journal";
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, _| {
|
||
let measured = window.frame_snapshot().elements[edit_id].bounds;
|
||
let published = v.published_a11y_tree().nodes[edit_id].bounds;
|
||
assert_eq!(
|
||
(published.x, published.y, published.width, published.height),
|
||
(measured.x, measured.y, measured.width, measured.height),
|
||
"{locale:?}"
|
||
);
|
||
assert!(published.width >= 44.0 && published.height >= 44.0);
|
||
if locale == MobileLocale::Ar {
|
||
assert!(published.x < 45.0);
|
||
} else {
|
||
assert!(published.x > 300.0);
|
||
}
|
||
})
|
||
})
|
||
.unwrap();
|
||
|
||
sheet_scroll(&t, point(px(195.0), px(700.0)), -3000.0);
|
||
let extent_and_offset = || t.read(|v, _| (v.state.sheet_extent, v.state.sheet_scroll_y));
|
||
let (before, old_offset) = extent_and_offset();
|
||
assert_eq!(before.max_scroll(), old_offset);
|
||
assert!(old_offset > 500.0);
|
||
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state.active_workspace_mut().docs_mut().retain(|doc| {
|
||
doc.id
|
||
.strip_prefix("duplicate-")
|
||
.and_then(|i| i.parse::<usize>().ok())
|
||
.is_none_or(|i| i < 16)
|
||
});
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.headless_win.request_frame();
|
||
let (after, offset) = extent_and_offset();
|
||
assert!(after.max_scroll() < old_offset);
|
||
assert_eq!(offset, after.max_scroll(), "{locale:?}");
|
||
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let elements = &window.frame_snapshot().elements;
|
||
let last = elements["mobile.sheet.journal_conflict.doc.duplicate-15"].bounds;
|
||
let viewport = elements["mobile.sheet.scroll_viewport"].bounds;
|
||
assert!(
|
||
last.y >= viewport.y
|
||
&& last.y + last.height <= viewport.y + viewport.height
|
||
);
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(extent_and_offset().1, offset);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn compact_landscape_delete_confirmation_scrolls_the_full_button_into_view() {
|
||
for locale in [MobileLocale::En, MobileLocale::ZhHans, MobileLocale::Ar] {
|
||
let t = TestApp::launch(640, 204, locale);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
let now = v.clock_ms(cx);
|
||
let ws_id = v.state.active_workspace_id().to_owned();
|
||
assert!(
|
||
v.state
|
||
.request_delete_doc_scoped(&ws_id, "doc-trash", None, now)
|
||
);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.advance_clock(Duration::from_millis(400));
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
|
||
let bounds = || {
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let elements = &window.frame_snapshot().elements;
|
||
(
|
||
elements["mobile.sheet.scroll_viewport"].bounds,
|
||
elements["app.sheet.delete_confirm.14:ws-mobile-rustdoc-trash"].bounds,
|
||
)
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
let (viewport, before) = bounds();
|
||
assert!(before.y + before.height > viewport.y + viewport.height);
|
||
sheet_scroll(&t, point(px(320.0), px(viewport.y + 10.0)), -300.0);
|
||
let (viewport, after) = bounds();
|
||
assert!(after.height >= 44.0);
|
||
assert!(after.y >= viewport.y && after.y + after.height <= viewport.y + viewport.height);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn journal_conflict_move_to_trash_writes_only_after_confirmation() {
|
||
let t = launch_on_journal_with_twin();
|
||
let trashed =
|
||
|t: &TestApp| t.read(|v, _| v.state.doc_by_id("doc-journal-twin").unwrap().trashed);
|
||
let open_confirm = |t: &TestApp| {
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.journal_conflicts");
|
||
t.click_id("mobile.sheet.journal_conflict.edit.doc-journal-twin");
|
||
t.click_id("mobile.sheet.journal_conflict.trash");
|
||
assert_eq!(
|
||
t.read(|v, _| v.state.active_sheet),
|
||
MobileSheet::ConfirmTrashDoc
|
||
);
|
||
assert!(!trashed(t), "opening the confirmation writes nothing");
|
||
};
|
||
|
||
open_confirm(&t);
|
||
t.click_id("app.sheet.trash_cancel.");
|
||
assert_eq!(t.read(|v, _| v.state.active_sheet), MobileSheet::None);
|
||
assert!(!trashed(&t), "Cancel writes nothing");
|
||
|
||
// The accessibility action shares the confirmation: it writes nothing until confirmed.
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.journal_conflicts");
|
||
t.click_id("mobile.sheet.journal_conflict.edit.doc-journal-twin");
|
||
let a11y = |t: &TestApp, id: &str| {
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.perform_a11y_action(id, MobileA11yAction::Activate, cx)
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
assert!(a11y(&t, "mobile.sheet.journal_conflict.trash"));
|
||
assert_eq!(
|
||
t.read(|v, _| v.state.active_sheet),
|
||
MobileSheet::ConfirmTrashDoc
|
||
);
|
||
assert!(
|
||
!trashed(&t),
|
||
"the accessibility action opens the confirmation only"
|
||
);
|
||
t.headless_win.request_frame();
|
||
let confirm_id = format!(
|
||
"app.sheet.trash_confirm.{}",
|
||
affine_mobile::encode_scoped_doc_target("ws-mobile-rust", "doc-journal-twin")
|
||
);
|
||
assert!(a11y(&t, &confirm_id));
|
||
let (twin, journal, route) = t.read(|v, _| {
|
||
(
|
||
v.state.doc_by_id("doc-journal-twin").unwrap().trashed,
|
||
v.state.doc_by_id("doc-journal").unwrap().trashed,
|
||
v.state.route.clone(),
|
||
)
|
||
});
|
||
assert!(twin && !journal, "only the target journal moves to trash");
|
||
assert_eq!(route, MobileRoute::Page("doc-journal".into()));
|
||
}
|
||
|
||
#[test]
|
||
fn journals_tab_publishes_conflict_row_and_opens_a_same_day_journal() {
|
||
let t = launch_on_journal_with_twin();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state.switch_tab(affine_mobile::MobileTab::Journals, 0.0);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
let conflict_id = "mobile.journals.conflicts_btn";
|
||
let published = || t.read(|v, _| v.published_a11y_tree().nodes.contains_key(conflict_id));
|
||
assert!(t.has_element(conflict_id));
|
||
assert!(published());
|
||
t.click_id(conflict_id);
|
||
assert_eq!(
|
||
t.read(|v, _| v.state.active_sheet),
|
||
MobileSheet::JournalConflicts
|
||
);
|
||
for id in ["doc-journal", "doc-journal-twin"] {
|
||
assert!(t.has_element(&format!("mobile.sheet.journal_conflict.doc.{id}")));
|
||
}
|
||
t.click_id("mobile.sheet.journal_conflict.doc.doc-journal-twin");
|
||
let route = t.read(|v, _| v.state.route.clone());
|
||
assert_eq!(route, MobileRoute::Page("doc-journal-twin".into()));
|
||
|
||
t.click_id("mobile.page.back_btn");
|
||
t.click_id("mobile.journals.day.2026-11-24");
|
||
assert!(
|
||
!t.has_element(conflict_id) && !published(),
|
||
"a date with one journal or none has no conflict row"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn editor_gates_follow_the_readonly_toggle_and_the_edgeless_editing_flag() {
|
||
use playground::PlaygroundMode;
|
||
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
// `(page, database, edgeless)` read-only gates of the embedded editor.
|
||
let gates = |t: &TestApp| {
|
||
t.read(|v, cx| {
|
||
let pv = v.page_editor().expect("editor").read(cx);
|
||
(
|
||
pv.page_readonly(),
|
||
pv.database_readonly(),
|
||
pv.edgeless_readonly(),
|
||
)
|
||
})
|
||
};
|
||
assert_eq!(
|
||
gates(&t),
|
||
(false, false, true),
|
||
"an editable doc unlocks Database"
|
||
);
|
||
t.click_id("mobile.page.readonly_toggle");
|
||
assert_eq!(gates(&t), (true, true, true));
|
||
t.click_id("mobile.page.readonly_toggle");
|
||
|
||
t.click_id("mobile.page.back_btn");
|
||
t.click_id("mobile.home.settings_btn");
|
||
t.click_id("mobile.settings.row.experimental");
|
||
assert_eq!(
|
||
t.read(|v, _| v.state.active_sheet),
|
||
MobileSheet::Experimental
|
||
);
|
||
t.click_id("mobile.sheet.experimental.enable_mobile_edgeless_editing");
|
||
let (enabled, checked) = t.read(|v, _| {
|
||
(
|
||
v.state.settings.enable_mobile_edgeless_editing,
|
||
v.published_a11y_tree().nodes["mobile.sheet.experimental.enable_mobile_edgeless_editing"]
|
||
.state
|
||
.checked,
|
||
)
|
||
});
|
||
assert_eq!((enabled, checked), (true, Some(true)));
|
||
t.click_id("mobile.sheet.done_btn");
|
||
t.click_id("mobile.settings.back_btn");
|
||
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.mode.edgeless");
|
||
let mode = t.read(|v, cx| v.page_editor().expect("editor").read(cx).mode());
|
||
assert_eq!(mode, PlaygroundMode::Edgeless);
|
||
assert_eq!(
|
||
gates(&t),
|
||
(false, false, false),
|
||
"the flag unlocks Edgeless edits"
|
||
);
|
||
assert!(t.has_element("mobile.page.readonly_toggle"));
|
||
t.click_id("mobile.page.readonly_toggle");
|
||
assert_eq!(gates(&t), (true, true, true));
|
||
}
|
||
|
||
#[test]
|
||
fn view_info_sheet_toggles_doc_tags_and_lists_times_and_link_counts() {
|
||
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||
let ws = state.active_workspace_mut();
|
||
ws.doc_created_ms
|
||
.insert("doc-arch".into(), 1_763_712_000_000);
|
||
ws.doc_mut("doc-arch").expect("doc").updated_at_ms = 1_764_072_000_000;
|
||
let t = TestApp::launch_with_state(390, 844, state);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.more_btn");
|
||
t.click_id("mobile.sheet.doc_action.view_info");
|
||
assert_eq!(t.read(|v, _| v.state.active_sheet), MobileSheet::DocInfo);
|
||
let tags = |t: &TestApp| t.read(|v, _| v.state.doc_by_id("doc-arch").unwrap().tags.clone());
|
||
for expected in [vec!["rust", "mobile", "sync"], vec!["rust", "mobile"]] {
|
||
t.click_id("mobile.sheet.doc_info.tag.sync");
|
||
assert_eq!(tags(&t), expected);
|
||
}
|
||
t.click_id("mobile.sheet.doc_info.tag.rust");
|
||
assert_eq!(tags(&t), vec!["mobile"]);
|
||
let (names, rust_checked, errors) = t.read(|v, _| {
|
||
let tree = v.published_a11y_tree();
|
||
(
|
||
[
|
||
"mobile.sheet.doc_info.created",
|
||
"mobile.sheet.doc_info.updated",
|
||
"mobile.sheet.doc_info.backlinks",
|
||
"mobile.sheet.doc_info.outgoing_links",
|
||
]
|
||
.map(|id| tree.nodes[id].name.clone()),
|
||
tree.nodes["mobile.sheet.doc_info.tag.rust"].state.checked,
|
||
validate_accessibility_tree(tree),
|
||
)
|
||
});
|
||
assert_eq!(
|
||
names,
|
||
[
|
||
"Created: 2025-11-21 08:00".to_string(),
|
||
"Updated: 2025-11-25 12:00".to_string(),
|
||
"Backlinks: 2".to_string(),
|
||
"Outgoing links: 0".to_string(),
|
||
]
|
||
);
|
||
assert_eq!(rust_checked, Some(false));
|
||
assert!(errors.is_empty(), "{errors:?}");
|
||
}
|
||
|
||
#[test]
|
||
fn journal_strip_returns_to_today_and_opens_a_dated_journal_in_place_or_an_empty_day_on_the_journals_tab()
|
||
{
|
||
let mut state = seed_showcase_state(MobileLocale::En, ThemeMode::Light, "2026-11-25");
|
||
let ws = state.active_workspace_mut();
|
||
let mut monday = ws.doc("doc-journal").expect("journal").clone();
|
||
monday.id = "doc-journal-monday".into();
|
||
monday.journal_date = Some("2026-11-23".into());
|
||
ws.docs_mut().push(monday);
|
||
let t = TestApp::launch_with_state(390, 844, state);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.state.open_doc("doc-journal", Origin::Journal);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
let can_back = |t: &TestApp| t.read(|v, _| v.state.active_workspace().history.can_back());
|
||
let back_before = can_back(&t);
|
||
assert!(!t.has_element("mobile.page.journal_strip.today_btn"));
|
||
|
||
// Two weeks back from today's journal, `Today` returns the strip without navigating.
|
||
t.click_id("mobile.page.journal_strip.prev_btn");
|
||
t.click_id("mobile.page.journal_strip.prev_btn");
|
||
assert!(t.has_element("mobile.page.journal_strip.day.2026-11-09"));
|
||
let today_node = t.read(|v, _| {
|
||
v.published_a11y_tree()
|
||
.nodes
|
||
.contains_key("mobile.page.journal_strip.today_btn")
|
||
});
|
||
assert!(today_node);
|
||
t.click_id("mobile.page.journal_strip.today_btn");
|
||
assert!(t.has_element("mobile.page.journal_strip.day.2026-11-25"));
|
||
assert!(!t.has_element("mobile.page.journal_strip.today_btn"));
|
||
let route = t.read(|v, _| v.state.route.clone());
|
||
assert_eq!(route, MobileRoute::Page("doc-journal".into()));
|
||
assert_eq!(
|
||
can_back(&t),
|
||
back_before,
|
||
"returning the strip keeps the history"
|
||
);
|
||
|
||
t.click_id("mobile.page.journal_strip.day.2026-11-23");
|
||
let route = t.read(|v, _| v.state.route.clone());
|
||
assert_eq!(route, MobileRoute::Page("doc-journal-monday".into()));
|
||
assert_eq!(
|
||
can_back(&t),
|
||
back_before,
|
||
"the picked journal replaces the entry"
|
||
);
|
||
t.click_id("mobile.page.journal_strip.today_btn");
|
||
let route = t.read(|v, _| v.state.route.clone());
|
||
assert_eq!(route, MobileRoute::Page("doc-journal".into()));
|
||
|
||
t.click_id("mobile.page.journal_strip.prev_btn");
|
||
assert!(t.has_element("mobile.page.journal_strip.day.2026-11-16"));
|
||
t.click_id("mobile.page.journal_strip.next_btn");
|
||
t.click_id("mobile.page.journal_strip.day.2026-11-27");
|
||
let (route, date) =
|
||
t.read(|v, _| (v.state.route.clone(), v.state.selected_journal_date.clone()));
|
||
assert_eq!(
|
||
(route, date.as_str()),
|
||
(MobileRoute::Journals, "2026-11-27")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn drawer_filter_takes_ime_text_moves_and_draws_the_caret_filters_rows_and_clears() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.drawer_btn");
|
||
t.click_id("mobile.drawer.filter_bar");
|
||
let key = |t: &TestApp, keystroke: &'static str| {
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::KeyDown(KeyDownEvent {
|
||
keystroke: Keystroke::parse(keystroke).unwrap(),
|
||
is_held: false,
|
||
prefer_character_input: false,
|
||
}));
|
||
t.platform.run_until_parked();
|
||
};
|
||
let typed = |t: &TestApp, text: &'static str| {
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.replace_text_in_range(None, text, window, cx);
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
};
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.replace_and_mark_text_in_range(None, "Sy", None, window, cx);
|
||
assert_eq!(v.marked_text_range(window, cx), Some(0..2));
|
||
v.replace_text_in_range(None, "Syc", window, cx);
|
||
assert_eq!(v.text_length_utf16(window, cx), Some(3));
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
assert!(!t.has_element("mobile.drawer.doc.doc-sync"));
|
||
let caret_x = |t: &TestApp| {
|
||
t.headless_win.request_frame();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
window.frame_snapshot().elements["mobile.drawer.filter_bar.caret"]
|
||
.bounds
|
||
.x
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
let at_end = caret_x(&t);
|
||
|
||
// A typo fixed in place: `Left` then `n` turns `Syc` into `Sync`, and the caret is drawn
|
||
// where it inserts.
|
||
key(&t, "left");
|
||
assert!(caret_x(&t) < at_end, "the caret moves into the word");
|
||
typed(&t, "n");
|
||
assert_eq!(t.read(|v, _| v.state.drawer_filter.clone()), "Sync");
|
||
assert!(t.has_element("mobile.drawer.doc.doc-sync"));
|
||
assert!(!t.has_element("mobile.drawer.doc.doc-arch"));
|
||
|
||
// `End`, `Home`, then `Shift+Right`: each frame draws the field differently, as the caret
|
||
// moves to the start and the first character gets the selection highlight.
|
||
let field_pixels = |t: &TestApp| {
|
||
t.headless_win.request_frame();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
let b = window.frame_snapshot().elements["mobile.drawer.filter_bar"].bounds;
|
||
let image = window.render_to_image().expect("render frame");
|
||
let width = image.width() as usize;
|
||
let raw = image.as_raw();
|
||
let mut pixels = Vec::new();
|
||
for y in b.y as usize..(b.y + b.height) as usize {
|
||
let row = (y * width + b.x as usize) * 4;
|
||
pixels.extend_from_slice(&raw[row..row + b.width as usize * 4]);
|
||
}
|
||
pixels
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
let mut frames = Vec::new();
|
||
for k in ["end", "home", "shift-right"] {
|
||
key(&t, k);
|
||
frames.push(field_pixels(&t));
|
||
}
|
||
let selection = t.read(|v, _| v.state.drawer_filter_selection.clone());
|
||
assert_eq!(selection, 0..1);
|
||
for (a, b) in [(0, 1), (1, 2), (0, 2)] {
|
||
assert_ne!(
|
||
frames[a], frames[b],
|
||
"frames {a} and {b} draw the same field"
|
||
);
|
||
}
|
||
key(&t, "end");
|
||
|
||
for (keys, text, filter) in [
|
||
(&["home", "shift-right"][..], "X", "Xync"),
|
||
(&["end", "backspace"][..], "", "Xyn"),
|
||
(&["cmd-a"][..], "Sync", "Sync"),
|
||
] {
|
||
for k in keys {
|
||
key(&t, k);
|
||
}
|
||
if !text.is_empty() {
|
||
typed(&t, text);
|
||
}
|
||
assert_eq!(
|
||
t.read(|v, _| v.state.drawer_filter.clone()),
|
||
filter,
|
||
"{keys:?}"
|
||
);
|
||
}
|
||
|
||
t.click_id("mobile.drawer.filter_clear_btn");
|
||
let (filter, sheet) = t.read(|v, _| (v.state.drawer_filter.clone(), v.state.active_sheet));
|
||
assert_eq!((filter.as_str(), sheet), ("", MobileSheet::WorkspaceDrawer));
|
||
assert!(t.has_element("mobile.drawer.doc.doc-arch"));
|
||
}
|
||
|
||
/// Window-space `(x, y, width, height)` of the element `id` in a fresh frame.
|
||
fn element_bounds(t: &TestApp, id: &str) -> Option<(f32, f32, f32, f32)> {
|
||
t.headless_win.request_frame();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |_, window, _| {
|
||
window
|
||
.frame_snapshot()
|
||
.elements
|
||
.get(id)
|
||
.map(|el| (el.bounds.x, el.bounds.y, el.bounds.width, el.bounds.height))
|
||
})
|
||
})
|
||
.unwrap()
|
||
}
|
||
|
||
/// Report a `safe_bottom` home indicator and a `keyboard` software keyboard over the bottom
|
||
/// edge, as a native host does.
|
||
fn set_bottom_insets(t: &TestApp, safe_bottom: f32, keyboard: f32) {
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
v.set_insets_override(Some(WindowInsets {
|
||
safe_area: Edges {
|
||
bottom: px(safe_bottom),
|
||
..Edges::default()
|
||
},
|
||
ime: Edges {
|
||
bottom: px(keyboard),
|
||
..Edges::default()
|
||
},
|
||
..WindowInsets::default()
|
||
}));
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
t.platform.run_until_parked();
|
||
}
|
||
|
||
/// Click into the first body paragraph of the embedded editor.
|
||
fn click_editor_body(t: &TestApp) {
|
||
t.headless_win.request_frame();
|
||
let pt = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
let pv = v.page_editor().expect("embedded editor").read(cx);
|
||
let (origin, canvas) = pv.canvas_rect(window);
|
||
let geom = playground::block_flow::page_geometry(f32::from(canvas.width));
|
||
let layout = pv.flow_layout().expect("editor layout");
|
||
let body = layout
|
||
.blocks
|
||
.iter()
|
||
.find(|b| {
|
||
b.editable()
|
||
&& !matches!(b.body.kind, playground::block_flow::FlowKind::Title)
|
||
})
|
||
.expect("editable body paragraph")
|
||
.rect();
|
||
point(
|
||
px(f32::from(origin.x) + geom.column_x + body.x + 16.0),
|
||
px(f32::from(origin.y) + body.y + body.h * 0.5),
|
||
)
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.headless_win.simulate_click(pt);
|
||
t.platform.run_until_parked();
|
||
t.headless_win.request_frame();
|
||
}
|
||
|
||
fn shell_has_focus(t: &TestApp) -> bool {
|
||
t.headless_win.request_frame();
|
||
t.platform.run_until_parked();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle
|
||
.update(cx, |v, window, _| v.search_focus.is_focused(window))
|
||
})
|
||
.unwrap()
|
||
}
|
||
|
||
#[test]
|
||
fn page_mode_editor_owns_the_bottom_edge_with_its_keyboard_toolbar_on_the_keyboard() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
set_bottom_insets(&t, 34.0, 0.0);
|
||
click_editor_body(&t);
|
||
let canvas_bottom = |t: &TestApp| {
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
let (origin, size) = v.page_editor().unwrap().read(cx).canvas_rect(window);
|
||
f32::from(origin.y) + f32::from(size.height)
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
|
||
// `(keyboard, bottom edge of the keyboard toolbar)`: the editor reaches the window bottom.
|
||
for (keyboard, toolbar_bottom) in [
|
||
(336.0, Some(844.0 - 336.0)),
|
||
(291.0, Some(844.0 - 291.0)),
|
||
(0.0, None),
|
||
] {
|
||
set_bottom_insets(&t, 34.0, keyboard);
|
||
assert_eq!(canvas_bottom(&t), 844.0, "keyboard {keyboard}");
|
||
let toolbar =
|
||
element_bounds(&t, "overlay.keyboard_toolbar").map(|(_, y, _, h)| (y + h).round());
|
||
assert_eq!(toolbar, toolbar_bottom, "keyboard {keyboard}");
|
||
}
|
||
|
||
// The Edgeless canvas stays inside the bottom safe area that the shell pads.
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
let now_ms = v.clock_ms(cx);
|
||
v.state.set_page_view_mode(
|
||
"doc-arch",
|
||
affine_mobile::state::DocMode::Edgeless,
|
||
now_ms,
|
||
);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
set_bottom_insets(&t, 34.0, 0.0);
|
||
assert_eq!(canvas_bottom(&t), 844.0 - 34.0);
|
||
}
|
||
|
||
#[test]
|
||
fn overlay_sheets_over_a_page_take_the_editor_focus_and_the_drawer_leaves_it() {
|
||
// A host opens the sheet (an accessibility action or a deep link), so no click on the
|
||
// shell moves the focus first. `(sheet, the shell takes the focus)`
|
||
for (sheet, shell_focus) in [
|
||
(MobileSheet::DocActions, true),
|
||
(MobileSheet::DocInfo, true),
|
||
(MobileSheet::Backlinks, true),
|
||
(MobileSheet::ConfirmTrashDoc, true),
|
||
(MobileSheet::WorkspaceDrawer, false),
|
||
] {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
click_editor_body(&t);
|
||
assert!(
|
||
!shell_has_focus(&t),
|
||
"the editor has the focus before {sheet:?}"
|
||
);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, _, cx| {
|
||
let now_ms = v.clock_ms(cx);
|
||
v.state.open_sheet_from(sheet, None, now_ms);
|
||
cx.notify();
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(t.read(|v, _| v.state.active_sheet), sheet);
|
||
assert_eq!(shell_has_focus(&t), shell_focus, "{sheet:?}");
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn tabbar_hides_while_the_software_keyboard_is_up() {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
// `(tab, keyboard, TabBar shows)`
|
||
for (tab, keyboard, shows) in [
|
||
("mobile.tab.home", 0.0, true),
|
||
("mobile.tab.home", 300.0, false),
|
||
("mobile.tab.search", 0.0, true),
|
||
("mobile.tab.search", 300.0, false),
|
||
] {
|
||
set_bottom_insets(&t, 34.0, 0.0);
|
||
t.click_id(tab);
|
||
set_bottom_insets(&t, 34.0, keyboard);
|
||
assert_eq!(t.has_element("mobile.tabbar"), shows, "{tab} {keyboard}");
|
||
let a11y_tabbar =
|
||
t.read(|v, _| v.published_a11y_tree().nodes.contains_key("app.nav.tabbar"));
|
||
assert_eq!(a11y_tabbar, shows, "{tab} {keyboard}");
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn native_selection_ui_takes_the_caret_from_the_gpu_editor() {
|
||
// `(selection UI of the host, the GPU editor draws the caret)`
|
||
for (selection_ui, gpu_caret) in [
|
||
(NativeSelectionUi::default(), true),
|
||
(
|
||
NativeSelectionUi {
|
||
native_selection_ui: true,
|
||
native_suppresses_gpu_caret_and_selection: false,
|
||
},
|
||
true,
|
||
),
|
||
(
|
||
NativeSelectionUi {
|
||
native_selection_ui: true,
|
||
native_suppresses_gpu_caret_and_selection: true,
|
||
},
|
||
false,
|
||
),
|
||
] {
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle
|
||
.update(cx, |v, _, _| v.set_native_selection_ui(selection_ui))
|
||
})
|
||
.unwrap();
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
click_editor_body(&t);
|
||
assert_eq!(
|
||
t.has_element("page.local_caret"),
|
||
gpu_caret,
|
||
"{selection_ui:?}"
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn long_field_text_scrolls_to_keep_the_caret_inside_the_field() {
|
||
const QUERY: &str = "mobile shell breadcrumb architecture sync design note";
|
||
let t = TestApp::launch(390, 844, MobileLocale::En);
|
||
let key = |keystroke: &'static str| {
|
||
t.headless_win
|
||
.dispatch_input(PlatformInput::KeyDown(KeyDownEvent {
|
||
keystroke: Keystroke::parse(keystroke).unwrap(),
|
||
is_held: false,
|
||
prefer_character_input: false,
|
||
}));
|
||
t.platform.run_until_parked();
|
||
};
|
||
let type_query = || {
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.replace_text_in_range(None, QUERY, window, cx);
|
||
})
|
||
})
|
||
.unwrap();
|
||
t.platform.run_until_parked();
|
||
};
|
||
|
||
// `(how to reach the field, field ID, the clear button at the end of the field)`
|
||
let search: &dyn Fn() = &|| {
|
||
t.click_id("mobile.tab.search");
|
||
t.click_id("mobile.search.clear_btn");
|
||
t.click_id("mobile.search.input");
|
||
};
|
||
let drawer: &dyn Fn() = &|| {
|
||
t.click_id("mobile.tab.home");
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.drawer_btn");
|
||
t.click_id("mobile.drawer.filter_bar");
|
||
};
|
||
for (open, field, clear) in [
|
||
(search, "mobile.search.input", "mobile.search.clear_btn"),
|
||
(
|
||
drawer,
|
||
"mobile.drawer.filter_bar",
|
||
"mobile.drawer.filter_clear_btn",
|
||
),
|
||
] {
|
||
open();
|
||
type_query();
|
||
assert_eq!(QUERY.len(), 53);
|
||
let (field_x, _, _, _) = element_bounds(&t, field).unwrap();
|
||
let (clear_x, _, _, _) = element_bounds(&t, clear).unwrap();
|
||
let caret_id = format!("{field}.caret");
|
||
let caret = |t: &TestApp| element_bounds(t, &caret_id).map(|(x, _, w, _)| (x, x + w));
|
||
let mut carets = Vec::new();
|
||
for keys in [
|
||
&["end"][..],
|
||
&["left", "left"],
|
||
&["home"],
|
||
&["shift-right", "shift-right"],
|
||
&["end", "shift-left"],
|
||
&["end", "backspace"],
|
||
] {
|
||
for k in keys {
|
||
key(k);
|
||
}
|
||
let (start, end) = caret(&t).unwrap_or_else(|| panic!("{field} {keys:?}"));
|
||
assert!(
|
||
start >= field_x && end <= clear_x,
|
||
"{field} {keys:?}: caret {start}..{end} leaves {field_x}..{clear_x}"
|
||
);
|
||
carets.push(start);
|
||
}
|
||
// `End` puts the caret at the end edge of the line. Two steps back move the caret
|
||
// and keep the text still, and `Home` puts the caret back at the start edge.
|
||
assert!(carets[0] > carets[2] + 100.0, "{field} {carets:?}");
|
||
assert!(carets[0] - carets[1] > 8.0, "{field} {carets:?}");
|
||
assert!(carets[2] - field_x < 48.0, "{field} {carets:?}");
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn field_ime_rects_and_touch_offsets_follow_shaped_glyphs_in_both_fields() {
|
||
const ARABIC: &str = "بحث عربي";
|
||
const MIXED: &str = "AFFiNE بحث notes";
|
||
const QUERY: &str = "mobile shell breadcrumb architecture sync design note";
|
||
assert_eq!(QUERY.len(), 53);
|
||
|
||
for (locale, drawer) in [
|
||
(MobileLocale::En, false),
|
||
(MobileLocale::Ar, false),
|
||
(MobileLocale::En, true),
|
||
(MobileLocale::Ar, true),
|
||
] {
|
||
let t = TestApp::launch(390, 844, locale);
|
||
let field_id = if drawer {
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.drawer_btn");
|
||
"mobile.drawer.filter_bar"
|
||
} else {
|
||
t.click_id("mobile.tab.search");
|
||
t.click_id("mobile.search.clear_btn");
|
||
"mobile.search.input"
|
||
};
|
||
t.click_id(field_id);
|
||
let field_bounds = || {
|
||
let (x, y, w, h) = element_bounds(&t, field_id).unwrap();
|
||
Bounds::new(point(px(x), px(y)), size(px(w), px(h)))
|
||
};
|
||
let caret_id = format!("{field_id}.caret");
|
||
let context = format!("{locale:?} {field_id}");
|
||
let edit = |f: &dyn Fn(&mut MobileShellView, &mut ui::Window, &mut ui::Context<_>)| {
|
||
t.app
|
||
.update(|cx| t.window_handle.update(cx, |v, window, cx| f(v, window, cx)))
|
||
.unwrap();
|
||
};
|
||
let settle = || {
|
||
// A frame measures the text viewport and schedules a redraw if its width changes.
|
||
for _ in 0..3 {
|
||
t.headless_win.request_frame();
|
||
t.platform.run_until_parked();
|
||
}
|
||
};
|
||
let set_text = |text: &str| {
|
||
edit(&|v, window, cx| {
|
||
let len = v.text_length_utf16(window, cx).unwrap();
|
||
v.replace_text_in_range(Some(0..len), text, window, cx);
|
||
});
|
||
settle();
|
||
};
|
||
let rect = |offset| {
|
||
let field = field_bounds();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.bounds_for_range(offset..offset, field, window, cx)
|
||
.expect("caret rect")
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
let agrees = |rect: Bounds<ui::Pixels>| {
|
||
let (x, y, w, h) = element_bounds(&t, &caret_id).unwrap();
|
||
for (expected, shown) in [
|
||
(rect.left(), x),
|
||
(rect.top(), y),
|
||
(rect.size.width, w),
|
||
(rect.size.height, h),
|
||
] {
|
||
assert!(
|
||
(f32::from(expected) - shown).abs() <= 1.0,
|
||
"{context} IME {rect:?}, rendered caret ({x}, {y}, {w}, {h})"
|
||
);
|
||
}
|
||
let field = field_bounds();
|
||
assert!(
|
||
field.contains(&point(px(x), px(y)))
|
||
&& field.contains(&point(px(x + w), px(y + h))),
|
||
"{context} caret ({x}, {y}, {w}, {h}) in {field:?}"
|
||
);
|
||
point(px(x + w / 2.0), px(y + h / 2.0))
|
||
};
|
||
let hit = |position| {
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.character_index_for_point(position, window, cx)
|
||
})
|
||
})
|
||
.unwrap()
|
||
};
|
||
|
||
agrees(rect(0));
|
||
|
||
let widths = ["iiii", "WWWW"].map(|text| {
|
||
set_text(text);
|
||
let end = rect(4);
|
||
agrees(end);
|
||
f32::from(end.left() - rect(0).left())
|
||
});
|
||
assert!(widths[1] > widths[0] + 20.0, "{context} {widths:?}");
|
||
|
||
for (text, offsets, insert) in [
|
||
(ARABIC, &[0, 2, 4, 8][..], Some((2, "بح!ث عربي"))),
|
||
("لا", &[0, 1, 2], Some((1, "ل!ا"))),
|
||
("سلام", &[0, 1, 2, 3, 4], Some((2, "سل!ام"))),
|
||
(MIXED, &[0, 2, 9, 16], None),
|
||
(
|
||
QUERY,
|
||
&[QUERY.len(), QUERY.len() - 5, 10, QUERY.len()],
|
||
None,
|
||
),
|
||
] {
|
||
set_text(text);
|
||
let len = text.encode_utf16().count();
|
||
for &offset in offsets {
|
||
edit(&|v, window, cx| v.set_selected_text_range(offset..offset, window, cx));
|
||
settle();
|
||
let position = agrees(rect(offset));
|
||
assert_eq!(
|
||
hit(position),
|
||
Some(offset),
|
||
"{context} {text:?} at {offset}"
|
||
);
|
||
if let Some((target, expected)) = insert
|
||
&& offset == target
|
||
{
|
||
edit(&|v, window, cx| v.set_selected_text_range(len..len, window, cx));
|
||
settle();
|
||
t.headless_win.simulate_click(position);
|
||
edit(&|v, window, cx| {
|
||
v.replace_text_in_range(None, "!", window, cx);
|
||
let mut adjusted = None;
|
||
assert_eq!(
|
||
v.text_for_range(0..len + 1, &mut adjusted, window, cx)
|
||
.as_deref(),
|
||
Some(expected),
|
||
"{context}"
|
||
);
|
||
});
|
||
set_text(text);
|
||
}
|
||
}
|
||
if text == "لا" {
|
||
let [start, middle, end] = [0, 1, 2].map(|offset| rect(offset).center().x);
|
||
assert!(
|
||
end < middle && middle < start,
|
||
"{context} {start:?} {middle:?} {end:?}"
|
||
);
|
||
let field = field_bounds();
|
||
edit(&|v, window, cx| {
|
||
for (range, left, right) in [(0..1, middle, start), (1..2, end, middle)] {
|
||
let span = v.bounds_for_range(range, field, window, cx).unwrap();
|
||
assert!((span.left() - left).abs() <= px(0.25), "{context} {span:?}");
|
||
assert!(
|
||
(span.right() - right).abs() <= px(0.25),
|
||
"{context} {span:?}"
|
||
);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
// Ask for the empty caret rectangle in the edit that clears a scrolled line.
|
||
let field = field_bounds();
|
||
let before_frame = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.replace_text_in_range(Some(0..QUERY.len()), "", window, cx);
|
||
v.bounds_for_range(0..0, field, window, cx).unwrap()
|
||
})
|
||
})
|
||
.unwrap();
|
||
assert_eq!(before_frame.center().y, field.center().y, "{context}");
|
||
settle();
|
||
let empty = rect(0);
|
||
assert!(
|
||
(before_frame.left() - empty.left()).abs() <= px(1.0),
|
||
"{context}"
|
||
);
|
||
agrees(empty);
|
||
|
||
// Test the edges of the text viewport, within the icon and clear button.
|
||
set_text(ARABIC);
|
||
edit(&|v, window, cx| v.set_selected_text_range(4..4, window, cx));
|
||
settle();
|
||
let scroll = t.read(|v, _| {
|
||
if drawer {
|
||
v.state.drawer_filter_scroll
|
||
} else {
|
||
v.state.search_scroll
|
||
}
|
||
});
|
||
for (x, expected) in [
|
||
(scroll.origin_x + 0.25, 8),
|
||
(scroll.origin_x + scroll.visible_width - 0.25, 0),
|
||
] {
|
||
let position = point(px(x), field_bounds().center().y);
|
||
assert_eq!(hit(position), Some(expected), "{context} x={x}");
|
||
t.headless_win.simulate_click(position);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
let selection = v.selected_text_range(false, window, cx).unwrap();
|
||
assert_eq!(selection.range, expected..expected, "{context} x={x}");
|
||
})
|
||
})
|
||
.unwrap();
|
||
}
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn drawer_ime_underlines_are_visible_for_ltr_rtl_and_mixed_text() {
|
||
for locale in [MobileLocale::En, MobileLocale::Ar] {
|
||
let t = TestApp::launch(390, 844, locale);
|
||
let field_id = "mobile.drawer.filter_bar";
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.drawer_btn");
|
||
t.click_id(field_id);
|
||
let frame = || {
|
||
for _ in 0..3 {
|
||
t.headless_win.request_frame();
|
||
t.platform.run_until_parked();
|
||
}
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle
|
||
.update(cx, |_, window, _| window.render_to_image().unwrap())
|
||
})
|
||
.unwrap()
|
||
};
|
||
for (text, marked, segments) in
|
||
[("abcd", 1..3, 1), ("بحث", 0..2, 1), ("ab بحث cd", 1..4, 2)]
|
||
{
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
let len = v.text_length_utf16(window, cx).unwrap();
|
||
v.replace_text_in_range(Some(0..len), text, window, cx);
|
||
})
|
||
})
|
||
.unwrap();
|
||
let plain = frame();
|
||
let (x, y, w, h) = element_bounds(&t, "mobile.drawer.filter_bar.caret").unwrap();
|
||
let accent = plain.get_pixel((x + w / 2.0) as u32, (y + h / 2.0) as u32);
|
||
let start = text.char_indices().nth(marked.start).unwrap().0;
|
||
let end = text.char_indices().nth(marked.end).unwrap().0;
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.replace_and_mark_text_in_range(
|
||
Some(marked.clone()),
|
||
&text[start..end],
|
||
None,
|
||
window,
|
||
cx,
|
||
);
|
||
assert_eq!(v.marked_text_range(window, cx), Some(marked.clone()));
|
||
})
|
||
})
|
||
.unwrap();
|
||
let composition = frame();
|
||
let (x, y, w, h) = element_bounds(&t, field_id).unwrap();
|
||
let mut visible_segments = Vec::new();
|
||
let mut previous = None;
|
||
for col in x as u32..(x + w) as u32 {
|
||
let ink = (y as u32..(y + h) as u32).any(|row| {
|
||
composition.get_pixel(col, row) == accent && plain.get_pixel(col, row) != accent
|
||
});
|
||
if ink {
|
||
if previous == Some(col - 1) {
|
||
*visible_segments.last_mut().unwrap() += 1;
|
||
} else {
|
||
visible_segments.push(1);
|
||
}
|
||
previous = Some(col);
|
||
}
|
||
}
|
||
assert_eq!(
|
||
visible_segments.len(),
|
||
segments,
|
||
"{locale:?} {text:?}: {visible_segments:?}"
|
||
);
|
||
assert!(
|
||
visible_segments.iter().all(|&width| width >= 3),
|
||
"{locale:?} {text:?}: {visible_segments:?}"
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn field_pointer_clicks_stop_at_extended_grapheme_boundaries() {
|
||
for (locale, drawer) in [
|
||
(MobileLocale::En, false),
|
||
(MobileLocale::Ar, false),
|
||
(MobileLocale::En, true),
|
||
(MobileLocale::Ar, true),
|
||
] {
|
||
let t = TestApp::launch(390, 844, locale);
|
||
let field_id = if drawer {
|
||
t.click_id("mobile.home.doc.doc-arch");
|
||
t.click_id("mobile.page.drawer_btn");
|
||
"mobile.drawer.filter_bar"
|
||
} else {
|
||
t.click_id("mobile.tab.search");
|
||
t.click_id("mobile.search.clear_btn");
|
||
"mobile.search.input"
|
||
};
|
||
t.click_id(field_id);
|
||
for text in [
|
||
"🇯🇵",
|
||
"か\u{3099}",
|
||
"कि",
|
||
"가",
|
||
"e\u{0301}",
|
||
"👍🏽",
|
||
"👨👩👧",
|
||
"ب\u{064E}",
|
||
"\r\n",
|
||
] {
|
||
let len = text.encode_utf16().count();
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
let previous = v.text_length_utf16(window, cx).unwrap();
|
||
v.replace_text_in_range(Some(0..previous), text, window, cx);
|
||
})
|
||
})
|
||
.unwrap();
|
||
for _ in 0..3 {
|
||
t.headless_win.request_frame();
|
||
t.platform.run_until_parked();
|
||
}
|
||
let (x, y, w, h) = element_bounds(&t, field_id).unwrap();
|
||
let field = Bounds::new(point(px(x), px(y)), size(px(w), px(h)));
|
||
let span = t
|
||
.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
v.bounds_for_range(0..len, field, window, cx).unwrap()
|
||
})
|
||
})
|
||
.unwrap();
|
||
let first = f32::from(span.left()).floor() as i32 - 2;
|
||
let last = f32::from(span.right()).ceil() as i32 + 2;
|
||
let mut seen = [false; 2];
|
||
for x in first..=last {
|
||
let position = point(px(x as f32), field.center().y);
|
||
t.headless_win.simulate_click(position);
|
||
t.app
|
||
.update(|cx| {
|
||
t.window_handle.update(cx, |v, window, cx| {
|
||
let found = v.character_index_for_point(position, window, cx).unwrap();
|
||
let clicked = v.selected_text_range(false, window, cx).unwrap();
|
||
assert!(
|
||
found == 0 || found == len,
|
||
"{locale:?} {field_id} {text:?} at x={x}: {found}"
|
||
);
|
||
assert_eq!(
|
||
clicked.range,
|
||
found..found,
|
||
"{locale:?} {field_id} {text:?} at x={x}"
|
||
);
|
||
seen[usize::from(found == len)] = true;
|
||
})
|
||
})
|
||
.unwrap();
|
||
}
|
||
assert_eq!(seen, [true; 2], "{locale:?} {field_id} {text:?}");
|
||
}
|
||
}
|
||
}
|