use super::*; use ely_platform::clipboard::{self, Clip}; use gpui::TestAppContext; const BOOK: &str = r#" 2 6 "#; fn flush(cx: &TestAppContext) { for _ in 0..80 { cx.executor().tick(); } } fn goto(view: &Entity, cx: &mut TestAppContext, cell: &str) { cx.update(|app| { let view = view.read(app); let mut worker = view.worker.lock().expect("the worker lock"); worker .run(&view.doc, "cell.goto", &[cell]) .expect("the cell"); }); } /// The workbook as flat XML. fn saved(view: &Entity, cx: &mut TestAppContext) -> String { let out = tempfile::tempdir() .expect("a temp dir") .keep() .join("out.fods"); cx.update(|app| { let view = view.read(app); let mut worker = view.worker.lock().expect("the worker lock"); view.doc .save_as(&mut worker, &crate::file_url(&out), "fods") .expect("the save works"); }); std::fs::read_to_string(&out).expect("the save reads") } #[test] fn values_and_formulas_paste_alone_from_the_views_copy() { let Some(install) = crate::client::tests::install() else { eprintln!("SKIP: no pinned LOK build"); return; }; if std::env::var_os("ELY_CLIPBOARD_TEST").is_none() { eprintln!("SKIP: set ELY_CLIPBOARD_TEST=1; this replaces the clipboard"); return; } let mut cx = TestAppContext::single(); let (view, _) = cx.update(|app| live_view_of(app, &install, "book.fods", BOOK)); goto(&view, &mut cx, "B1"); cx.update(|app| { view.update(app, |view, _| { view.send(crate::view::input::Input::Copy { cut: false }) }) }); flush(&cx); for (cell, id) in [("C1", "paste.values"), ("D1", "paste.formulas")] { goto(&view, &mut cx, cell); cx.update(|app| view.update(app, |view, _| view.paste_only(id))); flush(&cx); } let xml = saved(&view, &mut cx); assert_eq!(xml.matches("table:formula=").count(), 2, "C1 holds 6 alone"); assert!(xml.contains("of:=[.C1]*3"), "D1 keeps the formula"); let copy = cx.update(|app| { let read = clipboard::read().expect("the clipboard reads"); let Some(Clip::Html { html, .. }) = read else { panic!("the copy lands as html"); }; view.read(app).holds_copy(&html) }); assert!(copy, "the view knows its own copy"); // Copies made elsewhere carry no mark of this view. let other = "
6
"; assert!(cx.update(|app| !view.read(app).holds_copy(other))); let foreign = "6"; assert!( cx.update(|app| !view.read(app).holds_copy(foreign)), "another copy's mark" ); }