test.rs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. use crate::grid::group_test::script::GridGroupTest;
  2. use crate::grid::group_test::script::GroupScript::*;
  3. use flowy_grid::entities::FieldChangesetParams;
  4. #[tokio::test]
  5. async fn group_init_test() {
  6. let mut test = GridGroupTest::new().await;
  7. let scripts = vec![
  8. AssertGroupCount(3),
  9. AssertGroupRowCount {
  10. group_index: 0,
  11. row_count: 2,
  12. },
  13. AssertGroupRowCount {
  14. group_index: 1,
  15. row_count: 2,
  16. },
  17. AssertGroupRowCount {
  18. group_index: 2,
  19. row_count: 1,
  20. },
  21. ];
  22. test.run_scripts(scripts).await;
  23. }
  24. #[tokio::test]
  25. async fn group_move_row_test() {
  26. let mut test = GridGroupTest::new().await;
  27. let group = test.group_at_index(0).await;
  28. let scripts = vec![
  29. // Move the row at 0 in group0 to group1 at 1
  30. MoveRow {
  31. from_group_index: 0,
  32. from_row_index: 0,
  33. to_group_index: 0,
  34. to_row_index: 1,
  35. },
  36. AssertGroupRowCount {
  37. group_index: 0,
  38. row_count: 2,
  39. },
  40. AssertRow {
  41. group_index: 0,
  42. row_index: 1,
  43. row: group.rows.get(0).unwrap().clone(),
  44. },
  45. ];
  46. test.run_scripts(scripts).await;
  47. }
  48. #[tokio::test]
  49. async fn group_move_row_to_other_group_test() {
  50. let mut test = GridGroupTest::new().await;
  51. let group = test.group_at_index(0).await;
  52. let scripts = vec![
  53. MoveRow {
  54. from_group_index: 0,
  55. from_row_index: 0,
  56. to_group_index: 1,
  57. to_row_index: 1,
  58. },
  59. AssertGroupRowCount {
  60. group_index: 0,
  61. row_count: 1,
  62. },
  63. AssertGroupRowCount {
  64. group_index: 1,
  65. row_count: 3,
  66. },
  67. AssertRow {
  68. group_index: 1,
  69. row_index: 1,
  70. row: group.rows.get(0).unwrap().clone(),
  71. },
  72. ];
  73. test.run_scripts(scripts).await;
  74. }
  75. #[tokio::test]
  76. async fn group_move_two_row_to_other_group_test() {
  77. let mut test = GridGroupTest::new().await;
  78. let group = test.group_at_index(0).await;
  79. let scripts = vec![
  80. MoveRow {
  81. from_group_index: 0,
  82. from_row_index: 0,
  83. to_group_index: 1,
  84. to_row_index: 1,
  85. },
  86. AssertGroupRowCount {
  87. group_index: 0,
  88. row_count: 1,
  89. },
  90. AssertGroupRowCount {
  91. group_index: 1,
  92. row_count: 3,
  93. },
  94. AssertRow {
  95. group_index: 1,
  96. row_index: 1,
  97. row: group.rows.get(0).unwrap().clone(),
  98. },
  99. ];
  100. test.run_scripts(scripts).await;
  101. let group = test.group_at_index(0).await;
  102. let scripts = vec![
  103. MoveRow {
  104. from_group_index: 0,
  105. from_row_index: 0,
  106. to_group_index: 1,
  107. to_row_index: 1,
  108. },
  109. AssertGroupRowCount {
  110. group_index: 0,
  111. row_count: 0,
  112. },
  113. AssertGroupRowCount {
  114. group_index: 1,
  115. row_count: 4,
  116. },
  117. AssertRow {
  118. group_index: 1,
  119. row_index: 1,
  120. row: group.rows.get(0).unwrap().clone(),
  121. },
  122. ];
  123. test.run_scripts(scripts).await;
  124. }
  125. #[tokio::test]
  126. async fn group_move_row_to_other_group_and_reorder_from_up_to_down_test() {
  127. let mut test = GridGroupTest::new().await;
  128. let group_0 = test.group_at_index(0).await;
  129. let group_1 = test.group_at_index(1).await;
  130. let scripts = vec![
  131. MoveRow {
  132. from_group_index: 0,
  133. from_row_index: 0,
  134. to_group_index: 1,
  135. to_row_index: 1,
  136. },
  137. AssertRow {
  138. group_index: 1,
  139. row_index: 1,
  140. row: group_0.rows.get(0).unwrap().clone(),
  141. },
  142. ];
  143. test.run_scripts(scripts).await;
  144. let scripts = vec![
  145. MoveRow {
  146. from_group_index: 1,
  147. from_row_index: 0,
  148. to_group_index: 1,
  149. to_row_index: 2,
  150. },
  151. AssertRow {
  152. group_index: 1,
  153. row_index: 2,
  154. row: group_1.rows.get(0).unwrap().clone(),
  155. },
  156. ];
  157. test.run_scripts(scripts).await;
  158. }
  159. #[tokio::test]
  160. async fn group_move_row_to_other_group_and_reorder_from_bottom_to_up_test() {
  161. let mut test = GridGroupTest::new().await;
  162. let scripts = vec![MoveRow {
  163. from_group_index: 0,
  164. from_row_index: 0,
  165. to_group_index: 1,
  166. to_row_index: 1,
  167. }];
  168. test.run_scripts(scripts).await;
  169. let group = test.group_at_index(1).await;
  170. let scripts = vec![
  171. AssertGroupRowCount {
  172. group_index: 1,
  173. row_count: 3,
  174. },
  175. MoveRow {
  176. from_group_index: 1,
  177. from_row_index: 2,
  178. to_group_index: 1,
  179. to_row_index: 0,
  180. },
  181. AssertRow {
  182. group_index: 1,
  183. row_index: 0,
  184. row: group.rows.get(2).unwrap().clone(),
  185. },
  186. ];
  187. test.run_scripts(scripts).await;
  188. }
  189. #[tokio::test]
  190. async fn group_create_row_test() {
  191. let mut test = GridGroupTest::new().await;
  192. let scripts = vec![
  193. CreateRow { group_index: 0 },
  194. AssertGroupRowCount {
  195. group_index: 0,
  196. row_count: 3,
  197. },
  198. CreateRow { group_index: 1 },
  199. CreateRow { group_index: 1 },
  200. AssertGroupRowCount {
  201. group_index: 1,
  202. row_count: 4,
  203. },
  204. ];
  205. test.run_scripts(scripts).await;
  206. }
  207. #[tokio::test]
  208. async fn group_delete_row_test() {
  209. let mut test = GridGroupTest::new().await;
  210. let scripts = vec![
  211. DeleteRow {
  212. group_index: 0,
  213. row_index: 0,
  214. },
  215. AssertGroupRowCount {
  216. group_index: 0,
  217. row_count: 1,
  218. },
  219. ];
  220. test.run_scripts(scripts).await;
  221. }
  222. #[tokio::test]
  223. async fn group_delete_all_row_test() {
  224. let mut test = GridGroupTest::new().await;
  225. let scripts = vec![
  226. DeleteRow {
  227. group_index: 0,
  228. row_index: 0,
  229. },
  230. DeleteRow {
  231. group_index: 0,
  232. row_index: 0,
  233. },
  234. AssertGroupRowCount {
  235. group_index: 0,
  236. row_count: 0,
  237. },
  238. ];
  239. test.run_scripts(scripts).await;
  240. }
  241. #[tokio::test]
  242. async fn group_update_row_test() {
  243. let mut test = GridGroupTest::new().await;
  244. let scripts = vec![
  245. // Update the row at 0 in group0 by setting the row's group field data
  246. UpdateRow {
  247. from_group_index: 0,
  248. row_index: 0,
  249. to_group_index: 1,
  250. },
  251. AssertGroupRowCount {
  252. group_index: 0,
  253. row_count: 1,
  254. },
  255. AssertGroupRowCount {
  256. group_index: 1,
  257. row_count: 3,
  258. },
  259. ];
  260. test.run_scripts(scripts).await;
  261. }
  262. #[tokio::test]
  263. async fn group_reorder_group_test() {
  264. let mut test = GridGroupTest::new().await;
  265. let scripts = vec![
  266. // Update the row at 0 in group0 by setting the row's group field data
  267. UpdateRow {
  268. from_group_index: 0,
  269. row_index: 0,
  270. to_group_index: 1,
  271. },
  272. AssertGroupRowCount {
  273. group_index: 0,
  274. row_count: 1,
  275. },
  276. AssertGroupRowCount {
  277. group_index: 1,
  278. row_count: 3,
  279. },
  280. ];
  281. test.run_scripts(scripts).await;
  282. }
  283. #[tokio::test]
  284. async fn group_move_group_test() {
  285. let mut test = GridGroupTest::new().await;
  286. let group_0 = test.group_at_index(0).await;
  287. let group_1 = test.group_at_index(1).await;
  288. let scripts = vec![
  289. MoveGroup {
  290. from_group_index: 0,
  291. to_group_index: 1,
  292. },
  293. AssertGroup {
  294. group_index: 0,
  295. expected_group: group_1,
  296. },
  297. AssertGroup {
  298. group_index: 1,
  299. expected_group: group_0,
  300. },
  301. ];
  302. test.run_scripts(scripts).await;
  303. }
  304. #[tokio::test]
  305. async fn group_update_field_test() {
  306. let mut test = GridGroupTest::new().await;
  307. let mut group = test.group_at_index(0).await;
  308. let changeset = FieldChangesetParams {
  309. field_id: group.field_id.clone(),
  310. grid_id: test.grid_id.clone(),
  311. name: Some("ABC".to_string()),
  312. ..Default::default()
  313. };
  314. // group.desc = "ABC".to_string();
  315. let scripts = vec![
  316. UpdateField { changeset },
  317. AssertGroup {
  318. group_index: 0,
  319. expected_group: group,
  320. },
  321. ];
  322. test.run_scripts(scripts).await;
  323. }