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:
Richard Shiue
2024-02-20 13:17:46 +08:00
committed by GitHub
parent 15c9a67028
commit a6c6aa819c
6 changed files with 108 additions and 6 deletions

View File

@ -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) => {},
_ => {},
}
})

View File

@ -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(),