mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add select option tests
This commit is contained in:
parent
c80fa5da78
commit
18c209848b
@ -105,6 +105,7 @@ void main() {
|
|||||||
fieldController: boardTest.context.fieldController,
|
fieldController: boardTest.context.fieldController,
|
||||||
),
|
),
|
||||||
act: (bloc) async {
|
act: (bloc) async {
|
||||||
|
await boardResponseFuture();
|
||||||
bloc.add(GridGroupEvent.setGroupByField(
|
bloc.add(GridGroupEvent.setGroupByField(
|
||||||
multiSelectField.id,
|
multiSelectField.id,
|
||||||
multiSelectField.fieldType,
|
multiSelectField.fieldType,
|
||||||
|
@ -12,26 +12,27 @@ impl SelectOptionFilterPB {
|
|||||||
match self.condition {
|
match self.condition {
|
||||||
SelectOptionCondition::OptionIs => {
|
SelectOptionCondition::OptionIs => {
|
||||||
if self.option_ids.len() != selected_option_ids.len() {
|
if self.option_ids.len() != selected_option_ids.len() {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if selected options equal to filter's options, then the required_options will be empty.
|
// if selected options equal to filter's options, then the required_options will be empty.
|
||||||
let required_options = self
|
let required_options = self
|
||||||
.option_ids
|
.option_ids
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|id| !selected_option_ids.contains(id))
|
.filter(|id| selected_option_ids.contains(id))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
required_options.len() == selected_option_ids.len()
|
||||||
// https://stackoverflow.com/questions/69413164/how-to-fix-this-clippy-warning-needless-collect
|
|
||||||
!required_options.is_empty()
|
|
||||||
}
|
}
|
||||||
SelectOptionCondition::OptionIsNot => {
|
SelectOptionCondition::OptionIsNot => {
|
||||||
for option_id in selected_option_ids {
|
if self.option_ids.len() != selected_option_ids.len() {
|
||||||
if self.option_ids.contains(option_id) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
let required_options = self
|
||||||
false
|
.option_ids
|
||||||
|
.iter()
|
||||||
|
.filter(|id| selected_option_ids.contains(id))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
required_options.len() != selected_option_ids.len()
|
||||||
}
|
}
|
||||||
SelectOptionCondition::OptionIsEmpty => selected_option_ids.is_empty(),
|
SelectOptionCondition::OptionIsEmpty => selected_option_ids.is_empty(),
|
||||||
SelectOptionCondition::OptionIsNotEmpty => !selected_option_ids.is_empty(),
|
SelectOptionCondition::OptionIsNotEmpty => !selected_option_ids.is_empty(),
|
||||||
@ -67,43 +68,87 @@ mod tests {
|
|||||||
use crate::services::field::selection_type_option::{SelectOptionPB, SelectedSelectOptions};
|
use crate::services::field::selection_type_option::{SelectOptionPB, SelectedSelectOptions};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn select_option_filter_is_test() {
|
fn select_option_filter_is_empty_test() {
|
||||||
|
let option = SelectOptionPB::new("A");
|
||||||
|
let filter = SelectOptionFilterPB {
|
||||||
|
condition: SelectOptionCondition::OptionIsEmpty,
|
||||||
|
option_ids: vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(filter.is_visible(&SelectedSelectOptions { options: vec![] }), true);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
filter.is_visible(&SelectedSelectOptions { options: vec![option] }),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn select_option_filter_is_not_test() {
|
||||||
let option_1 = SelectOptionPB::new("A");
|
let option_1 = SelectOptionPB::new("A");
|
||||||
let option_2 = SelectOptionPB::new("B");
|
let option_2 = SelectOptionPB::new("B");
|
||||||
let option_3 = SelectOptionPB::new("C");
|
let option_3 = SelectOptionPB::new("C");
|
||||||
|
|
||||||
let filter_1 = SelectOptionFilterPB {
|
let filter = SelectOptionFilterPB {
|
||||||
condition: SelectOptionCondition::OptionIs,
|
condition: SelectOptionCondition::OptionIsNot,
|
||||||
option_ids: vec![option_1.id.clone(), option_2.id.clone()],
|
option_ids: vec![option_1.id.clone(), option_2.id.clone()],
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_1.is_visible(&SelectedSelectOptions {
|
filter.is_visible(&SelectedSelectOptions {
|
||||||
options: vec![option_1.clone(), option_2.clone()],
|
options: vec![option_1.clone(), option_2.clone()],
|
||||||
}),
|
}),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_1.is_visible(&SelectedSelectOptions {
|
filter.is_visible(&SelectedSelectOptions {
|
||||||
options: vec![option_1.clone(), option_2.clone(), option_3.clone()],
|
options: vec![option_1.clone(), option_2.clone(), option_3.clone()],
|
||||||
}),
|
}),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_1.is_visible(&SelectedSelectOptions {
|
filter.is_visible(&SelectedSelectOptions {
|
||||||
options: vec![option_1.clone(), option_3.clone()],
|
options: vec![option_1.clone(), option_3.clone()],
|
||||||
}),
|
}),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(filter_1.is_visible(&SelectedSelectOptions { options: vec![] }), true);
|
assert_eq!(filter.is_visible(&SelectedSelectOptions { options: vec![] }), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn select_option_filter_is_test() {
|
||||||
|
let option_1 = SelectOptionPB::new("A");
|
||||||
|
let option_2 = SelectOptionPB::new("B");
|
||||||
|
let option_3 = SelectOptionPB::new("C");
|
||||||
|
|
||||||
|
let filter = SelectOptionFilterPB {
|
||||||
|
condition: SelectOptionCondition::OptionIs,
|
||||||
|
option_ids: vec![option_1.id.clone(), option_2.id.clone()],
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filter_1.is_visible(&SelectedSelectOptions {
|
filter.is_visible(&SelectedSelectOptions {
|
||||||
options: vec![option_1.clone()],
|
options: vec![option_1.clone(), option_2.clone()],
|
||||||
}),
|
}),
|
||||||
true,
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
filter.is_visible(&SelectedSelectOptions {
|
||||||
|
options: vec![option_1.clone(), option_2.clone(), option_3.clone()],
|
||||||
|
}),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
filter.is_visible(&SelectedSelectOptions {
|
||||||
|
options: vec![option_1.clone(), option_3.clone()],
|
||||||
|
}),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(filter.is_visible(&SelectedSelectOptions { options: vec![] }), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,8 +237,8 @@ impl GridViewRevisionEditor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn is_grouped(&self) -> bool {
|
pub(crate) async fn group_id(&self) -> String {
|
||||||
self.group_controller.read().await.groups().len() > 1
|
self.group_controller.read().await.field_id().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_view_setting(&self) -> GridSettingPB {
|
pub(crate) async fn get_view_setting(&self) -> GridSettingPB {
|
||||||
|
@ -184,7 +184,7 @@ impl GridViewManager {
|
|||||||
#[tracing::instrument(level = "trace", skip(self), err)]
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
||||||
pub(crate) async fn did_update_view_field_type_option(&self, field_id: &str) -> FlowyResult<()> {
|
pub(crate) async fn did_update_view_field_type_option(&self, field_id: &str) -> FlowyResult<()> {
|
||||||
let view_editor = self.get_default_view_editor().await?;
|
let view_editor = self.get_default_view_editor().await?;
|
||||||
if view_editor.is_grouped().await {
|
if view_editor.group_id().await == field_id {
|
||||||
let _ = view_editor.group_by_view_field(field_id).await?;
|
let _ = view_editor.group_by_view_field(field_id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user