ElyTable: under LOK an AutoFilter range keeps its rows through list, apply, toggle, undo and reopen (R2.9)
This commit is contained in:
5 files changed
+141
-120
No files matched your search
@@ -1,4 +1,4 @@
|
||||
//! An AutoFilter keeps to the marked block (TABLE-08).
|
||||
//! An AutoFilter range keeps its rows (TABLE-08).
|
||||
|
||||
use super::sheet::open_book;
|
||||
use super::*;
|
||||
@@ -18,14 +18,33 @@ const BLOCK: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
</table:table></office:spreadsheet></office:body>
|
||||
</office:document>"#;
|
||||
|
||||
/// The filter entries after an AutoFilter on `marked`.
|
||||
fn entries_after(marked: &str) -> Vec<String> {
|
||||
let (_dir, mut worker, doc) = open_book(BLOCK);
|
||||
/// Column A's filter entries.
|
||||
fn entries(worker: &mut Worker, doc: &Doc) -> Vec<String> {
|
||||
let query = sheet::cell_query(sheet::FILTER, 0, 0);
|
||||
let json = worker.values(doc, &query).expect("the entries");
|
||||
sheet::filter_values(&json).expect("parses").entries.into_iter().map(|e| e.text).collect()
|
||||
}
|
||||
|
||||
/// A book with an AutoFilter set on `marked`.
|
||||
fn filtered(marked: &str) -> (tempfile::TempDir, Worker, Doc) {
|
||||
let (dir, mut worker, doc) = open_book(BLOCK);
|
||||
worker.run(&doc, "cell.goto", &[marked]).expect("marks the cells");
|
||||
worker.run(&doc, "data.autofilter", &[]).expect("filters");
|
||||
let query = sheet::cell_query(sheet::FILTER, 0, 0);
|
||||
let json = worker.values(&doc, &query).expect("the entries");
|
||||
sheet::filter_values(&json).expect("parses").entries.into_iter().map(|e| e.text).collect()
|
||||
(dir, worker, doc)
|
||||
}
|
||||
|
||||
/// Keeps 1: the saved range, and whether the total hides.
|
||||
fn keep_one(worker: &mut Worker, doc: &Doc, dir: &std::path::Path) -> (String, bool) {
|
||||
worker.run(doc, "cell.goto", &["A1"]).expect("A1");
|
||||
let one = r#"{"column":0,"conditions":[{"op":"values","values":["1"]}]}"#;
|
||||
worker.run(doc, "data.filter", &[one]).expect("keeps 1");
|
||||
let out = dir.join("kept.fods");
|
||||
doc.save_as(worker, &crate::file_url(&out), "fods").expect("saves");
|
||||
let xml = std::fs::read_to_string(&out).expect("the saved book");
|
||||
let range = xml.split("table:target-range-address=\"").nth(1).expect("a filter range");
|
||||
let total = &xml[..xml.find("office:value=\"6\"").expect("the total")];
|
||||
let row = &total[total.rfind("<table:table-row").expect("its row")..];
|
||||
(range[..range.find('"').expect("closed")].to_string(), row.contains("table:visibility=\"filter\""))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -34,7 +53,9 @@ fn an_autofilter_on_a_marked_block_leaves_the_row_below_out() {
|
||||
eprintln!("SKIP: no pinned LOK build");
|
||||
return;
|
||||
}
|
||||
assert_eq!(entries_after("A1:A4"), ["1", "2", "3"], "the total below stays out");
|
||||
let (dir, mut worker, doc) = filtered("A1:A4");
|
||||
assert_eq!(entries(&mut worker, &doc), ["1", "2", "3"], "the total below stays out");
|
||||
assert_eq!(keep_one(&mut worker, &doc, dir.path()), ("S.A1:S.A4".into(), false), "applied from one cell");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -43,5 +64,43 @@ fn an_autofilter_on_one_cell_takes_the_data_area() {
|
||||
eprintln!("SKIP: no pinned LOK build");
|
||||
return;
|
||||
}
|
||||
assert_eq!(entries_after("A1"), ["1", "2", "3", "6"], "the whole column of data");
|
||||
let (_dir, mut worker, doc) = filtered("A1");
|
||||
assert_eq!(entries(&mut worker, &doc), ["1", "2", "3", "6"], "the whole column of data");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn off_and_undone_or_set_on_a_filtered_block_the_rows_stay() {
|
||||
if install().is_none() {
|
||||
eprintln!("SKIP: no pinned LOK build");
|
||||
return;
|
||||
}
|
||||
let (_dir, mut worker, doc) = filtered("A1:A4");
|
||||
worker.run(&doc, "cell.goto", &["A1"]).expect("A1");
|
||||
worker.run(&doc, "data.autofilter", &[]).expect("off");
|
||||
worker.run(&doc, "edit.undo", &[]).expect("back on");
|
||||
assert_eq!(entries(&mut worker, &doc), ["1", "2", "3"], "undo keeps the rows");
|
||||
let (_dir, mut worker, doc) = open_book(BLOCK);
|
||||
worker.run(&doc, "cell.goto", &["A1:A4"]).expect("marks the block");
|
||||
let one = r#"{"conditions":[{"field":0,"op":"equals","value":"1"}]}"#;
|
||||
worker.run(&doc, "data.filter", &[one]).expect("a standard filter");
|
||||
worker.run(&doc, "cell.goto", &["A1:A4"]).expect("marks it again");
|
||||
worker.run(&doc, "data.autofilter", &[]).expect("filters");
|
||||
assert_eq!(entries(&mut worker, &doc), ["1", "2", "3"], "a filtered block keeps its rows");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_saved_autofilter_range_keeps_its_rows_when_reopened() {
|
||||
if install().is_none() {
|
||||
eprintln!("SKIP: no pinned LOK build");
|
||||
return;
|
||||
}
|
||||
for format in ["xlsx", "ods"] {
|
||||
let (dir, mut worker, doc) = filtered("A1:A4");
|
||||
let path = dir.path().join(format!("book.{format}"));
|
||||
doc.save_as(&mut worker, &crate::file_url(&path), format).expect("saves");
|
||||
worker.close_doc(doc).expect("closes");
|
||||
let doc = worker.load(&crate::file_url(&path)).expect("reopens");
|
||||
assert_eq!(entries(&mut worker, &doc), ["1", "2", "3"], "{format}");
|
||||
assert_eq!(keep_one(&mut worker, &doc, dir.path()), ("S.A1:S.A4".into(), false), "{format}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user