diff --git a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs index 4c8ac601ee..3a8796bfc4 100644 --- a/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/entities/filter_entities/select_option_filter.rs @@ -12,6 +12,7 @@ pub struct SelectOptionFilterPB { #[pb(index = 2)] pub option_ids: Vec, } + #[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)] #[repr(u8)] pub enum SelectOptionCondition { diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs index 577dc34beb..063a564216 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/selection_type_option/select_filter.rs @@ -82,6 +82,26 @@ mod tests { false, ); } + + #[test] + fn select_option_filter_is_not_empty_test() { + let option_1 = SelectOptionPB::new("A"); + let option_2 = SelectOptionPB::new("B"); + let filter = SelectOptionFilterPB { + condition: SelectOptionCondition::OptionIsNotEmpty, + option_ids: vec![option_1.id.clone(), option_2.id.clone()], + }; + + assert_eq!( + filter.is_visible(&SelectedSelectOptions { + options: vec![option_1] + }), + true + ); + + assert_eq!(filter.is_visible(&SelectedSelectOptions { options: vec![] }), false,); + } + #[test] fn select_option_filter_is_not_test() { let option_1 = SelectOptionPB::new("A"); diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/mod.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/mod.rs index 791576d92e..c26a66ea3b 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/mod.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/mod.rs @@ -2,4 +2,5 @@ mod checkbox_filter_test; mod date_filter_test; mod number_filter_test; mod script; +mod select_option_filter_test; mod text_filter_test; diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs index 4c1fa1a079..f3872f6f35 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/script.rs @@ -4,7 +4,8 @@ #![allow(unused_imports)] use futures::TryFutureExt; -use flowy_grid::entities::{CreateFilterParams, CreateFilterPayloadPB, DeleteFilterParams, GridLayout, GridSettingChangesetParams, GridSettingPB, RowPB, TextFilterCondition, FieldType, NumberFilterCondition, CheckboxFilterCondition, DateFilterCondition, DateFilterContent}; +use flowy_grid::entities::{CreateFilterParams, CreateFilterPayloadPB, DeleteFilterParams, GridLayout, GridSettingChangesetParams, GridSettingPB, RowPB, TextFilterCondition, FieldType, NumberFilterCondition, CheckboxFilterCondition, DateFilterCondition, DateFilterContent, SelectOptionCondition}; +use flowy_grid::services::field::SelectOptionIds; use flowy_grid::services::setting::GridSettingChangesetBuilder; use grid_rev_model::{FieldRevision, FieldTypeRevision}; use flowy_grid::services::filter::FilterType; @@ -31,6 +32,10 @@ pub enum FilterScript { end: Option, timestamp: Option, }, + CreateMultiSelectFilter { + condition: SelectOptionCondition, + option_ids: Vec, + }, AssertFilterCount { count: i32, }, @@ -105,6 +110,14 @@ impl GridFilterTest { self.insert_filter(payload).await; } + FilterScript::CreateMultiSelectFilter { condition, option_ids} => { + let field_rev = self.get_field_rev(FieldType::MultiSelect); + let content = + SelectOptionIds::from(option_ids).to_string(); + let payload = + CreateFilterPayloadPB::new(field_rev, condition, content); + self.insert_filter(payload).await; + } FilterScript::AssertFilterCount { count } => { let filters = self.editor.get_all_filters().await.unwrap(); assert_eq!(count as usize, filters.len()); diff --git a/frontend/rust-lib/flowy-grid/tests/grid/filter_test/select_option_filter_test.rs b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/select_option_filter_test.rs new file mode 100644 index 0000000000..ebe57bbc08 --- /dev/null +++ b/frontend/rust-lib/flowy-grid/tests/grid/filter_test/select_option_filter_test.rs @@ -0,0 +1,29 @@ +use crate::grid::filter_test::script::FilterScript::*; +use crate::grid::filter_test::script::GridFilterTest; +use flowy_grid::entities::{NumberFilterCondition, SelectOptionCondition}; + +#[tokio::test] +async fn grid_filter_multi_select_is_empty_test() { + let mut test = GridFilterTest::new().await; + let scripts = vec![ + CreateMultiSelectFilter { + condition: SelectOptionCondition::OptionIsEmpty, + option_ids: vec![], + }, + AssertNumberOfRows { expected: 2 }, + ]; + test.run_scripts(scripts).await; +} + +#[tokio::test] +async fn grid_filter_multi_select_is_not_empty_test() { + let mut test = GridFilterTest::new().await; + let scripts = vec![ + CreateMultiSelectFilter { + condition: SelectOptionCondition::OptionIsNotEmpty, + option_ids: vec![], + }, + AssertNumberOfRows { expected: 3 }, + ]; + test.run_scripts(scripts).await; +} diff --git a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs index 0a6153f1e4..79590ef588 100644 --- a/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs +++ b/frontend/rust-lib/flowy-grid/tests/grid/grid_editor.rs @@ -224,7 +224,7 @@ fn make_test_grid() -> BuildGridContext { row_builder.insert_single_select_cell(|mut options| options.remove(1)) } FieldType::MultiSelect => { - row_builder.insert_multi_select_cell(|mut options| vec![options.remove(0)]) + row_builder.insert_multi_select_cell(|mut options| vec![options.remove(1)]) } FieldType::Checkbox => row_builder.insert_checkbox_cell("false"), _ => "".to_owned(),