test.rs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. use crate::grid::group_test::script::GridGroupTest;
  2. use crate::grid::group_test::script::GroupScript::*;
  3. use flowy_grid::services::field::SelectOptionPB;
  4. #[tokio::test]
  5. async fn group_init_test() {
  6. let mut test = GridGroupTest::new().await;
  7. let scripts = vec![
  8. AssertGroupCount(4),
  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. AssertGroupRowCount {
  22. group_index: 3,
  23. row_count: 0,
  24. },
  25. ];
  26. test.run_scripts(scripts).await;
  27. }
  28. #[tokio::test]
  29. async fn group_move_row_test() {
  30. let mut test = GridGroupTest::new().await;
  31. let group = test.group_at_index(0).await;
  32. let scripts = vec![
  33. // Move the row at 0 in group0 to group1 at 1
  34. MoveRow {
  35. from_group_index: 0,
  36. from_row_index: 0,
  37. to_group_index: 0,
  38. to_row_index: 1,
  39. },
  40. AssertGroupRowCount {
  41. group_index: 0,
  42. row_count: 2,
  43. },
  44. AssertRow {
  45. group_index: 0,
  46. row_index: 1,
  47. row: group.rows.get(0).unwrap().clone(),
  48. },
  49. ];
  50. test.run_scripts(scripts).await;
  51. }
  52. #[tokio::test]
  53. async fn group_move_row_to_other_group_test() {
  54. let mut test = GridGroupTest::new().await;
  55. let group = test.group_at_index(0).await;
  56. let scripts = vec![
  57. MoveRow {
  58. from_group_index: 0,
  59. from_row_index: 0,
  60. to_group_index: 1,
  61. to_row_index: 1,
  62. },
  63. AssertGroupRowCount {
  64. group_index: 0,
  65. row_count: 1,
  66. },
  67. AssertGroupRowCount {
  68. group_index: 1,
  69. row_count: 3,
  70. },
  71. AssertRow {
  72. group_index: 1,
  73. row_index: 1,
  74. row: group.rows.get(0).unwrap().clone(),
  75. },
  76. ];
  77. test.run_scripts(scripts).await;
  78. }
  79. #[tokio::test]
  80. async fn group_move_two_row_to_other_group_test() {
  81. let mut test = GridGroupTest::new().await;
  82. let group = test.group_at_index(0).await;
  83. let scripts = vec![
  84. MoveRow {
  85. from_group_index: 0,
  86. from_row_index: 0,
  87. to_group_index: 1,
  88. to_row_index: 1,
  89. },
  90. AssertGroupRowCount {
  91. group_index: 0,
  92. row_count: 1,
  93. },
  94. AssertGroupRowCount {
  95. group_index: 1,
  96. row_count: 3,
  97. },
  98. AssertRow {
  99. group_index: 1,
  100. row_index: 1,
  101. row: group.rows.get(0).unwrap().clone(),
  102. },
  103. ];
  104. test.run_scripts(scripts).await;
  105. let group = test.group_at_index(0).await;
  106. let scripts = vec![
  107. MoveRow {
  108. from_group_index: 0,
  109. from_row_index: 0,
  110. to_group_index: 1,
  111. to_row_index: 1,
  112. },
  113. AssertGroupRowCount {
  114. group_index: 0,
  115. row_count: 0,
  116. },
  117. AssertGroupRowCount {
  118. group_index: 1,
  119. row_count: 4,
  120. },
  121. AssertRow {
  122. group_index: 1,
  123. row_index: 1,
  124. row: group.rows.get(0).unwrap().clone(),
  125. },
  126. ];
  127. test.run_scripts(scripts).await;
  128. }
  129. #[tokio::test]
  130. async fn group_move_row_to_other_group_and_reorder_from_up_to_down_test() {
  131. let mut test = GridGroupTest::new().await;
  132. let group_0 = test.group_at_index(0).await;
  133. let group_1 = test.group_at_index(1).await;
  134. let scripts = vec![
  135. MoveRow {
  136. from_group_index: 0,
  137. from_row_index: 0,
  138. to_group_index: 1,
  139. to_row_index: 1,
  140. },
  141. AssertRow {
  142. group_index: 1,
  143. row_index: 1,
  144. row: group_0.rows.get(0).unwrap().clone(),
  145. },
  146. ];
  147. test.run_scripts(scripts).await;
  148. let scripts = vec![
  149. MoveRow {
  150. from_group_index: 1,
  151. from_row_index: 0,
  152. to_group_index: 1,
  153. to_row_index: 2,
  154. },
  155. AssertRow {
  156. group_index: 1,
  157. row_index: 2,
  158. row: group_1.rows.get(0).unwrap().clone(),
  159. },
  160. ];
  161. test.run_scripts(scripts).await;
  162. }
  163. #[tokio::test]
  164. async fn group_move_row_to_other_group_and_reorder_from_bottom_to_up_test() {
  165. let mut test = GridGroupTest::new().await;
  166. let scripts = vec![MoveRow {
  167. from_group_index: 0,
  168. from_row_index: 0,
  169. to_group_index: 1,
  170. to_row_index: 1,
  171. }];
  172. test.run_scripts(scripts).await;
  173. let group = test.group_at_index(1).await;
  174. let scripts = vec![
  175. AssertGroupRowCount {
  176. group_index: 1,
  177. row_count: 3,
  178. },
  179. MoveRow {
  180. from_group_index: 1,
  181. from_row_index: 2,
  182. to_group_index: 1,
  183. to_row_index: 0,
  184. },
  185. AssertRow {
  186. group_index: 1,
  187. row_index: 0,
  188. row: group.rows.get(2).unwrap().clone(),
  189. },
  190. ];
  191. test.run_scripts(scripts).await;
  192. }
  193. #[tokio::test]
  194. async fn group_create_row_test() {
  195. let mut test = GridGroupTest::new().await;
  196. let scripts = vec![
  197. CreateRow { group_index: 0 },
  198. AssertGroupRowCount {
  199. group_index: 0,
  200. row_count: 3,
  201. },
  202. CreateRow { group_index: 1 },
  203. CreateRow { group_index: 1 },
  204. AssertGroupRowCount {
  205. group_index: 1,
  206. row_count: 4,
  207. },
  208. ];
  209. test.run_scripts(scripts).await;
  210. }
  211. #[tokio::test]
  212. async fn group_delete_row_test() {
  213. let mut test = GridGroupTest::new().await;
  214. let scripts = vec![
  215. DeleteRow {
  216. group_index: 0,
  217. row_index: 0,
  218. },
  219. AssertGroupRowCount {
  220. group_index: 0,
  221. row_count: 1,
  222. },
  223. ];
  224. test.run_scripts(scripts).await;
  225. }
  226. #[tokio::test]
  227. async fn group_delete_all_row_test() {
  228. let mut test = GridGroupTest::new().await;
  229. let scripts = vec![
  230. DeleteRow {
  231. group_index: 0,
  232. row_index: 0,
  233. },
  234. DeleteRow {
  235. group_index: 0,
  236. row_index: 0,
  237. },
  238. AssertGroupRowCount {
  239. group_index: 0,
  240. row_count: 0,
  241. },
  242. ];
  243. test.run_scripts(scripts).await;
  244. }
  245. #[tokio::test]
  246. async fn group_update_row_test() {
  247. let mut test = GridGroupTest::new().await;
  248. let scripts = vec![
  249. // Update the row at 0 in group0 by setting the row's group field data
  250. UpdateRow {
  251. from_group_index: 0,
  252. row_index: 0,
  253. to_group_index: 1,
  254. },
  255. AssertGroupRowCount {
  256. group_index: 0,
  257. row_count: 1,
  258. },
  259. AssertGroupRowCount {
  260. group_index: 1,
  261. row_count: 3,
  262. },
  263. ];
  264. test.run_scripts(scripts).await;
  265. }
  266. #[tokio::test]
  267. async fn group_reorder_group_test() {
  268. let mut test = GridGroupTest::new().await;
  269. let scripts = vec![
  270. // Update the row at 0 in group0 by setting the row's group field data
  271. UpdateRow {
  272. from_group_index: 0,
  273. row_index: 0,
  274. to_group_index: 1,
  275. },
  276. AssertGroupRowCount {
  277. group_index: 0,
  278. row_count: 1,
  279. },
  280. AssertGroupRowCount {
  281. group_index: 1,
  282. row_count: 3,
  283. },
  284. ];
  285. test.run_scripts(scripts).await;
  286. }
  287. #[tokio::test]
  288. async fn group_move_to_default_group_test() {
  289. let mut test = GridGroupTest::new().await;
  290. let scripts = vec![
  291. UpdateRow {
  292. from_group_index: 0,
  293. row_index: 0,
  294. to_group_index: 3,
  295. },
  296. AssertGroupRowCount {
  297. group_index: 0,
  298. row_count: 1,
  299. },
  300. AssertGroupRowCount {
  301. group_index: 3,
  302. row_count: 1,
  303. },
  304. ];
  305. test.run_scripts(scripts).await;
  306. }
  307. #[tokio::test]
  308. async fn group_move_from_default_group_test() {
  309. let mut test = GridGroupTest::new().await;
  310. let scripts = vec![UpdateRow {
  311. from_group_index: 0,
  312. row_index: 0,
  313. to_group_index: 3,
  314. }];
  315. test.run_scripts(scripts).await;
  316. let scripts = vec![
  317. UpdateRow {
  318. from_group_index: 3,
  319. row_index: 0,
  320. to_group_index: 0,
  321. },
  322. AssertGroupRowCount {
  323. group_index: 0,
  324. row_count: 2,
  325. },
  326. AssertGroupRowCount {
  327. group_index: 3,
  328. row_count: 0,
  329. },
  330. ];
  331. test.run_scripts(scripts).await;
  332. }
  333. #[tokio::test]
  334. async fn group_move_group_test() {
  335. let mut test = GridGroupTest::new().await;
  336. let group_0 = test.group_at_index(0).await;
  337. let group_1 = test.group_at_index(1).await;
  338. let scripts = vec![
  339. MoveGroup {
  340. from_group_index: 0,
  341. to_group_index: 1,
  342. },
  343. AssertGroup {
  344. group_index: 0,
  345. expected_group: group_1,
  346. },
  347. AssertGroup {
  348. group_index: 1,
  349. expected_group: group_0,
  350. },
  351. ];
  352. test.run_scripts(scripts).await;
  353. }
  354. #[tokio::test]
  355. async fn group_default_move_group_test() {
  356. let mut test = GridGroupTest::new().await;
  357. let group_0 = test.group_at_index(0).await;
  358. let group_3 = test.group_at_index(3).await;
  359. let scripts = vec![
  360. MoveGroup {
  361. from_group_index: 3,
  362. to_group_index: 0,
  363. },
  364. AssertGroup {
  365. group_index: 0,
  366. expected_group: group_3,
  367. },
  368. AssertGroup {
  369. group_index: 1,
  370. expected_group: group_0,
  371. },
  372. ];
  373. test.run_scripts(scripts).await;
  374. }
  375. #[tokio::test]
  376. async fn group_insert_single_select_option_test() {
  377. let mut test = GridGroupTest::new().await;
  378. let new_option_name = "New option";
  379. let scripts = vec![
  380. AssertGroupCount(4),
  381. UpdateSingleSelectOption {
  382. inserted_options: vec![SelectOptionPB::new(new_option_name)],
  383. },
  384. AssertGroupCount(5),
  385. ];
  386. test.run_scripts(scripts).await;
  387. let new_group = test.group_at_index(0).await;
  388. assert_eq!(new_group.desc, new_option_name);
  389. }
  390. #[tokio::test]
  391. async fn group_group_by_other_field() {
  392. let mut test = GridGroupTest::new().await;
  393. let multi_select_field = test.get_multi_select_field().await;
  394. let scripts = vec![
  395. GroupByField {
  396. field_id: multi_select_field.id.clone(),
  397. },
  398. AssertGroupRowCount {
  399. group_index: 0,
  400. row_count: 3,
  401. },
  402. AssertGroupRowCount {
  403. group_index: 1,
  404. row_count: 2,
  405. },
  406. AssertGroupCount(5),
  407. ];
  408. test.run_scripts(scripts).await;
  409. }