url_group_test.rs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. use crate::database::group_test::script::DatabaseGroupTest;
  2. use crate::database::group_test::script::GroupScript::*;
  3. #[tokio::test]
  4. async fn group_group_by_url() {
  5. let mut test = DatabaseGroupTest::new().await;
  6. let url_field = test.get_url_field().await;
  7. let scripts = vec![
  8. GroupByField {
  9. field_id: url_field.id.clone(),
  10. },
  11. // no status group
  12. AssertGroupRowCount {
  13. group_index: 0,
  14. row_count: 2,
  15. },
  16. // https://appflowy.io
  17. AssertGroupRowCount {
  18. group_index: 1,
  19. row_count: 2,
  20. },
  21. // https://github.com/AppFlowy-IO/AppFlowy
  22. AssertGroupRowCount {
  23. group_index: 2,
  24. row_count: 1,
  25. },
  26. AssertGroupCount(3),
  27. ];
  28. test.run_scripts(scripts).await;
  29. }
  30. #[tokio::test]
  31. async fn group_alter_url_to_another_group_url_test() {
  32. let mut test = DatabaseGroupTest::new().await;
  33. let url_field = test.get_url_field().await;
  34. let scripts = vec![
  35. GroupByField {
  36. field_id: url_field.id.clone(),
  37. },
  38. // no status group
  39. AssertGroupRowCount {
  40. group_index: 0,
  41. row_count: 2,
  42. },
  43. // https://appflowy.io
  44. AssertGroupRowCount {
  45. group_index: 1,
  46. row_count: 2,
  47. },
  48. // https://github.com/AppFlowy-IO/AppFlowy
  49. AssertGroupRowCount {
  50. group_index: 2,
  51. row_count: 1,
  52. },
  53. // When moving the last row from 2nd group to 1nd group, the 2nd group will be removed
  54. UpdateGroupedCell {
  55. from_group_index: 2,
  56. row_index: 0,
  57. to_group_index: 1,
  58. },
  59. AssertGroupCount(2),
  60. ];
  61. test.run_scripts(scripts).await;
  62. }
  63. #[tokio::test]
  64. async fn group_alter_url_to_new_url_test() {
  65. let mut test = DatabaseGroupTest::new().await;
  66. let url_field = test.get_url_field().await;
  67. let scripts = vec![
  68. GroupByField {
  69. field_id: url_field.id.clone(),
  70. },
  71. // When moving the last row from 2nd group to 1nd group, the 2nd group will be removed
  72. UpdateGroupedCellWithData {
  73. from_group_index: 0,
  74. row_index: 0,
  75. cell_data: "https://github.com/AppFlowy-IO".to_string(),
  76. },
  77. // no status group
  78. AssertGroupRowCount {
  79. group_index: 0,
  80. row_count: 1,
  81. },
  82. // https://appflowy.io
  83. AssertGroupRowCount {
  84. group_index: 1,
  85. row_count: 2,
  86. },
  87. // https://github.com/AppFlowy-IO/AppFlowy
  88. AssertGroupRowCount {
  89. group_index: 2,
  90. row_count: 1,
  91. },
  92. AssertGroupRowCount {
  93. group_index: 3,
  94. row_count: 1,
  95. },
  96. AssertGroupCount(4),
  97. ];
  98. test.run_scripts(scripts).await;
  99. }
  100. #[tokio::test]
  101. async fn group_move_url_group_row_test() {
  102. let mut test = DatabaseGroupTest::new().await;
  103. let url_field = test.get_url_field().await;
  104. let scripts = vec![
  105. GroupByField {
  106. field_id: url_field.id.clone(),
  107. },
  108. // no status group
  109. AssertGroupRowCount {
  110. group_index: 0,
  111. row_count: 2,
  112. },
  113. // https://appflowy.io
  114. AssertGroupRowCount {
  115. group_index: 1,
  116. row_count: 2,
  117. },
  118. // https://github.com/AppFlowy-IO/AppFlowy
  119. AssertGroupRowCount {
  120. group_index: 2,
  121. row_count: 1,
  122. },
  123. AssertGroupCount(3),
  124. MoveRow {
  125. from_group_index: 0,
  126. from_row_index: 0,
  127. to_group_index: 1,
  128. to_row_index: 0,
  129. },
  130. AssertGroupRowCount {
  131. group_index: 0,
  132. row_count: 1,
  133. },
  134. AssertGroupRowCount {
  135. group_index: 1,
  136. row_count: 3,
  137. },
  138. AssertGroupRowCount {
  139. group_index: 2,
  140. row_count: 1,
  141. },
  142. ];
  143. test.run_scripts(scripts).await;
  144. }