mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: newly-created rows aren't being automatically sorted (#4661)
* fix: newly-created rows aren't being automatically sorted * chore: new database view collab notification and add tests
This commit is contained in:
@ -36,6 +36,7 @@ pub enum SortScript {
|
||||
row_id: RowId,
|
||||
text: String,
|
||||
},
|
||||
AddNewRow,
|
||||
AssertSortChanged {
|
||||
old_row_orders: Vec<&'static str>,
|
||||
new_row_orders: Vec<&'static str>,
|
||||
@ -145,6 +146,28 @@ impl DatabaseSortTest {
|
||||
);
|
||||
self.update_text_cell(row_id, &text).await.unwrap();
|
||||
},
|
||||
SortScript::AddNewRow => {
|
||||
self.recv = Some(
|
||||
self
|
||||
.editor
|
||||
.subscribe_view_changed(&self.view_id)
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
self
|
||||
.editor
|
||||
.create_row(
|
||||
&self.view_id,
|
||||
None,
|
||||
collab_database::rows::CreateRowParams {
|
||||
id: collab_database::database::gen_row_id(),
|
||||
timestamp: collab_database::database::timestamp(),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
},
|
||||
SortScript::AssertSortChanged {
|
||||
new_row_orders,
|
||||
old_row_orders,
|
||||
@ -195,6 +218,7 @@ async fn assert_sort_changed(
|
||||
old_row_orders.insert(changed.new_index, old);
|
||||
assert_eq!(old_row_orders, new_row_orders);
|
||||
},
|
||||
DatabaseViewChanged::InsertSortedRowNotification(_changed) => {},
|
||||
_ => {},
|
||||
}
|
||||
})
|
||||
|
@ -81,10 +81,36 @@ async fn sort_change_notification_by_update_text_test() {
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sort_after_new_row_test() {
|
||||
let mut test = DatabaseSortTest::new().await;
|
||||
let checkbox_field = test.get_first_field(FieldType::Checkbox);
|
||||
let scripts = vec![
|
||||
AssertCellContentOrder {
|
||||
field_id: checkbox_field.id.clone(),
|
||||
orders: vec!["Yes", "Yes", "No", "No", "No", "Yes", ""],
|
||||
},
|
||||
InsertSort {
|
||||
field: checkbox_field.clone(),
|
||||
condition: SortCondition::Ascending,
|
||||
},
|
||||
AssertCellContentOrder {
|
||||
field_id: checkbox_field.id.clone(),
|
||||
orders: vec!["No", "No", "No", "", "Yes", "Yes", "Yes"],
|
||||
},
|
||||
AddNewRow {},
|
||||
AssertCellContentOrder {
|
||||
field_id: checkbox_field.id,
|
||||
orders: vec!["No", "No", "No", "", "", "Yes", "Yes", "Yes"],
|
||||
},
|
||||
];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sort_text_by_ascending_and_delete_sort_test() {
|
||||
let mut test = DatabaseSortTest::new().await;
|
||||
let text_field = test.get_first_field(FieldType::RichText).clone();
|
||||
let text_field = test.get_first_field(FieldType::RichText);
|
||||
let scripts = vec![
|
||||
InsertSort {
|
||||
field: text_field.clone(),
|
||||
|
Reference in New Issue
Block a user