chore: fix tests

This commit is contained in:
appflowy 2022-07-17 12:57:25 +08:00
parent cca577f967
commit 5ea3213c4e
4 changed files with 12 additions and 11 deletions

View File

@ -25,6 +25,6 @@ mod tests {
assert_eq!(decode_any_cell_data(data, &field_rev,).to_string(), NO); assert_eq!(decode_any_cell_data(data, &field_rev,).to_string(), NO);
let data = apply_cell_data_changeset("12", None, &field_rev).unwrap(); let data = apply_cell_data_changeset("12", None, &field_rev).unwrap();
assert_eq!(decode_any_cell_data(data, &field_rev,).to_string(), NO); assert_eq!(decode_any_cell_data(data, &field_rev,).to_string(), "");
} }
} }

View File

@ -6,7 +6,7 @@ use std::str::FromStr;
pub const YES: &str = "Yes"; pub const YES: &str = "Yes";
pub const NO: &str = "No"; pub const NO: &str = "No";
pub struct CheckboxCellData(pub String); pub struct CheckboxCellData(String);
impl CheckboxCellData { impl CheckboxCellData {
pub fn is_check(&self) -> bool { pub fn is_check(&self) -> bool {

View File

@ -28,6 +28,7 @@ impl CellFilterOperation<GridCheckboxFilter> for CheckboxTypeOption {
mod tests { mod tests {
use crate::entities::{CheckboxCondition, GridCheckboxFilter}; use crate::entities::{CheckboxCondition, GridCheckboxFilter};
use crate::services::field::CheckboxCellData; use crate::services::field::CheckboxCellData;
use std::str::FromStr;
#[test] #[test]
fn checkbox_filter_is_check_test() { fn checkbox_filter_is_check_test() {
@ -35,7 +36,7 @@ mod tests {
condition: CheckboxCondition::IsChecked, condition: CheckboxCondition::IsChecked,
}; };
for (value, visible) in [("true", true), ("yes", true), ("false", false), ("no", false)] { for (value, visible) in [("true", true), ("yes", true), ("false", false), ("no", false)] {
let data = CheckboxCellData(value.to_owned()); let data = CheckboxCellData::from_str(value).unwrap();
assert_eq!(checkbox_filter.is_visible(&data), visible); assert_eq!(checkbox_filter.is_visible(&data), visible);
} }
} }
@ -46,7 +47,7 @@ mod tests {
condition: CheckboxCondition::IsUnChecked, condition: CheckboxCondition::IsUnChecked,
}; };
for (value, visible) in [("false", true), ("no", true), ("true", false), ("yes", false)] { for (value, visible) in [("false", true), ("no", true), ("true", false), ("yes", false)] {
let data = CheckboxCellData(value.to_owned()); let data = CheckboxCellData::from_str(value).unwrap();
assert_eq!(checkbox_filter.is_visible(&data), visible); assert_eq!(checkbox_filter.is_visible(&data), visible);
} }
} }

View File

@ -9,13 +9,13 @@ use flowy_grid_data_model::revision::RowMetaChangeset;
async fn grid_create_row_count_test() { async fn grid_create_row_count_test() {
let mut test = GridRowTest::new().await; let mut test = GridRowTest::new().await;
let scripts = vec![ let scripts = vec![
AssertRowCount(3), AssertRowCount(5),
CreateEmptyRow, CreateEmptyRow,
CreateEmptyRow, CreateEmptyRow,
CreateRow { CreateRow {
row_rev: test.row_builder().build(), row_rev: test.row_builder().build(),
}, },
AssertRowCount(6), AssertRowCount(8),
]; ];
test.run_scripts(scripts).await; test.run_scripts(scripts).await;
} }
@ -31,11 +31,11 @@ async fn grid_update_row() {
cell_by_field_id: Default::default(), cell_by_field_id: Default::default(),
}; };
let scripts = vec![AssertRowCount(3), CreateRow { row_rev }, UpdateRow { changeset }]; let scripts = vec![AssertRowCount(5), CreateRow { row_rev }, UpdateRow { changeset }];
test.run_scripts(scripts).await; test.run_scripts(scripts).await;
let expected_row = test.last_row().unwrap(); let expected_row = test.last_row().unwrap();
let scripts = vec![AssertRow { expected_row }, AssertRowCount(4)]; let scripts = vec![AssertRow { expected_row }, AssertRowCount(6)];
test.run_scripts(scripts).await; test.run_scripts(scripts).await;
} }
@ -46,19 +46,19 @@ async fn grid_delete_row() {
let row_2 = test.row_builder().build(); let row_2 = test.row_builder().build();
let row_ids = vec![row_1.id.clone(), row_2.id.clone()]; let row_ids = vec![row_1.id.clone(), row_2.id.clone()];
let scripts = vec![ let scripts = vec![
AssertRowCount(3), AssertRowCount(5),
CreateRow { row_rev: row_1 }, CreateRow { row_rev: row_1 },
CreateRow { row_rev: row_2 }, CreateRow { row_rev: row_2 },
AssertBlockCount(1), AssertBlockCount(1),
AssertBlock { AssertBlock {
block_index: 0, block_index: 0,
row_count: 5, row_count: 7,
start_row_index: 0, start_row_index: 0,
}, },
DeleteRows { row_ids }, DeleteRows { row_ids },
AssertBlock { AssertBlock {
block_index: 0, block_index: 0,
row_count: 3, row_count: 5,
start_row_index: 0, start_row_index: 0,
}, },
]; ];