test.rs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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: 1,
  11. row_count: 2,
  12. },
  13. AssertGroupRowCount {
  14. group_index: 2,
  15. row_count: 2,
  16. },
  17. AssertGroupRowCount {
  18. group_index: 3,
  19. row_count: 1,
  20. },
  21. AssertGroupRowCount {
  22. group_index: 0,
  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(1).await;
  32. let scripts = vec![
  33. // Move the row at 0 in group0 to group1 at 1
  34. MoveRow {
  35. from_group_index: 1,
  36. from_row_index: 0,
  37. to_group_index: 1,
  38. to_row_index: 1,
  39. },
  40. AssertGroupRowCount {
  41. group_index: 1,
  42. row_count: 2,
  43. },
  44. AssertRow {
  45. group_index: 1,
  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(1).await;
  56. let scripts = vec![
  57. MoveRow {
  58. from_group_index: 1,
  59. from_row_index: 0,
  60. to_group_index: 2,
  61. to_row_index: 1,
  62. },
  63. AssertGroupRowCount {
  64. group_index: 1,
  65. row_count: 1,
  66. },
  67. AssertGroupRowCount {
  68. group_index: 2,
  69. row_count: 3,
  70. },
  71. AssertRow {
  72. group_index: 2,
  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_1 = test.group_at_index(1).await;
  83. let scripts = vec![
  84. // Move row at index 0 from group 1 to group 2 at index 1
  85. MoveRow {
  86. from_group_index: 1,
  87. from_row_index: 0,
  88. to_group_index: 2,
  89. to_row_index: 1,
  90. },
  91. AssertGroupRowCount {
  92. group_index: 1,
  93. row_count: 1,
  94. },
  95. AssertGroupRowCount {
  96. group_index: 2,
  97. row_count: 3,
  98. },
  99. AssertRow {
  100. group_index: 2,
  101. row_index: 1,
  102. row: group_1.rows.get(0).unwrap().clone(),
  103. },
  104. ];
  105. test.run_scripts(scripts).await;
  106. let group_1 = test.group_at_index(1).await;
  107. // Move row at index 0 from group 1 to group 2 at index 1
  108. let scripts = vec![
  109. MoveRow {
  110. from_group_index: 1,
  111. from_row_index: 0,
  112. to_group_index: 2,
  113. to_row_index: 1,
  114. },
  115. AssertGroupRowCount {
  116. group_index: 1,
  117. row_count: 0,
  118. },
  119. AssertGroupRowCount {
  120. group_index: 2,
  121. row_count: 4,
  122. },
  123. AssertRow {
  124. group_index: 2,
  125. row_index: 1,
  126. row: group_1.rows.get(0).unwrap().clone(),
  127. },
  128. ];
  129. test.run_scripts(scripts).await;
  130. }
  131. #[tokio::test]
  132. async fn group_move_row_to_other_group_and_reorder_from_up_to_down_test() {
  133. let mut test = GridGroupTest::new().await;
  134. let group_1 = test.group_at_index(1).await;
  135. let group_2 = test.group_at_index(2).await;
  136. let scripts = vec![
  137. MoveRow {
  138. from_group_index: 1,
  139. from_row_index: 0,
  140. to_group_index: 2,
  141. to_row_index: 1,
  142. },
  143. AssertRow {
  144. group_index: 2,
  145. row_index: 1,
  146. row: group_1.rows.get(0).unwrap().clone(),
  147. },
  148. ];
  149. test.run_scripts(scripts).await;
  150. let scripts = vec![
  151. MoveRow {
  152. from_group_index: 2,
  153. from_row_index: 0,
  154. to_group_index: 2,
  155. to_row_index: 2,
  156. },
  157. AssertRow {
  158. group_index: 2,
  159. row_index: 2,
  160. row: group_2.rows.get(0).unwrap().clone(),
  161. },
  162. ];
  163. test.run_scripts(scripts).await;
  164. }
  165. #[tokio::test]
  166. async fn group_move_row_to_other_group_and_reorder_from_bottom_to_up_test() {
  167. let mut test = GridGroupTest::new().await;
  168. let scripts = vec![MoveRow {
  169. from_group_index: 1,
  170. from_row_index: 0,
  171. to_group_index: 2,
  172. to_row_index: 1,
  173. }];
  174. test.run_scripts(scripts).await;
  175. let group = test.group_at_index(2).await;
  176. let scripts = vec![
  177. AssertGroupRowCount {
  178. group_index: 2,
  179. row_count: 3,
  180. },
  181. MoveRow {
  182. from_group_index: 2,
  183. from_row_index: 2,
  184. to_group_index: 2,
  185. to_row_index: 0,
  186. },
  187. AssertRow {
  188. group_index: 2,
  189. row_index: 0,
  190. row: group.rows.get(2).unwrap().clone(),
  191. },
  192. ];
  193. test.run_scripts(scripts).await;
  194. }
  195. #[tokio::test]
  196. async fn group_create_row_test() {
  197. let mut test = GridGroupTest::new().await;
  198. let scripts = vec![
  199. CreateRow { group_index: 1 },
  200. AssertGroupRowCount {
  201. group_index: 1,
  202. row_count: 3,
  203. },
  204. CreateRow { group_index: 2 },
  205. CreateRow { group_index: 2 },
  206. AssertGroupRowCount {
  207. group_index: 2,
  208. row_count: 4,
  209. },
  210. ];
  211. test.run_scripts(scripts).await;
  212. }
  213. #[tokio::test]
  214. async fn group_delete_row_test() {
  215. let mut test = GridGroupTest::new().await;
  216. let scripts = vec![
  217. DeleteRow {
  218. group_index: 1,
  219. row_index: 0,
  220. },
  221. AssertGroupRowCount {
  222. group_index: 1,
  223. row_count: 1,
  224. },
  225. ];
  226. test.run_scripts(scripts).await;
  227. }
  228. #[tokio::test]
  229. async fn group_delete_all_row_test() {
  230. let mut test = GridGroupTest::new().await;
  231. let scripts = vec![
  232. DeleteRow {
  233. group_index: 1,
  234. row_index: 0,
  235. },
  236. DeleteRow {
  237. group_index: 1,
  238. row_index: 0,
  239. },
  240. AssertGroupRowCount {
  241. group_index: 1,
  242. row_count: 0,
  243. },
  244. ];
  245. test.run_scripts(scripts).await;
  246. }
  247. #[tokio::test]
  248. async fn group_update_row_test() {
  249. let mut test = GridGroupTest::new().await;
  250. let scripts = vec![
  251. // Update the row at 0 in group0 by setting the row's group field data
  252. UpdateRow {
  253. from_group_index: 1,
  254. row_index: 0,
  255. to_group_index: 2,
  256. },
  257. AssertGroupRowCount {
  258. group_index: 1,
  259. row_count: 1,
  260. },
  261. AssertGroupRowCount {
  262. group_index: 2,
  263. row_count: 3,
  264. },
  265. ];
  266. test.run_scripts(scripts).await;
  267. }
  268. #[tokio::test]
  269. async fn group_reorder_group_test() {
  270. let mut test = GridGroupTest::new().await;
  271. let scripts = vec![
  272. // Update the row at 0 in group0 by setting the row's group field data
  273. UpdateRow {
  274. from_group_index: 1,
  275. row_index: 0,
  276. to_group_index: 2,
  277. },
  278. AssertGroupRowCount {
  279. group_index: 1,
  280. row_count: 1,
  281. },
  282. AssertGroupRowCount {
  283. group_index: 2,
  284. row_count: 3,
  285. },
  286. ];
  287. test.run_scripts(scripts).await;
  288. }
  289. #[tokio::test]
  290. async fn group_move_to_default_group_test() {
  291. let mut test = GridGroupTest::new().await;
  292. let scripts = vec![
  293. UpdateRow {
  294. from_group_index: 1,
  295. row_index: 0,
  296. to_group_index: 0,
  297. },
  298. AssertGroupRowCount {
  299. group_index: 1,
  300. row_count: 1,
  301. },
  302. AssertGroupRowCount {
  303. group_index: 0,
  304. row_count: 1,
  305. },
  306. ];
  307. test.run_scripts(scripts).await;
  308. }
  309. #[tokio::test]
  310. async fn group_move_from_default_group_test() {
  311. let mut test = GridGroupTest::new().await;
  312. // Move one row from group 1 to group 0
  313. let scripts = vec![
  314. UpdateRow {
  315. from_group_index: 1,
  316. row_index: 0,
  317. to_group_index: 0,
  318. },
  319. AssertGroupRowCount {
  320. group_index: 1,
  321. row_count: 1,
  322. },
  323. AssertGroupRowCount {
  324. group_index: 0,
  325. row_count: 1,
  326. },
  327. ];
  328. test.run_scripts(scripts).await;
  329. // Move one row from group 0 to group 1
  330. let scripts = vec![
  331. UpdateRow {
  332. from_group_index: 0,
  333. row_index: 0,
  334. to_group_index: 1,
  335. },
  336. AssertGroupRowCount {
  337. group_index: 1,
  338. row_count: 2,
  339. },
  340. AssertGroupRowCount {
  341. group_index: 0,
  342. row_count: 0,
  343. },
  344. ];
  345. test.run_scripts(scripts).await;
  346. }
  347. #[tokio::test]
  348. async fn group_move_group_test() {
  349. let mut test = GridGroupTest::new().await;
  350. let group_0 = test.group_at_index(0).await;
  351. let group_1 = test.group_at_index(1).await;
  352. let scripts = vec![
  353. MoveGroup {
  354. from_group_index: 0,
  355. to_group_index: 1,
  356. },
  357. AssertGroupRowCount {
  358. group_index: 0,
  359. row_count: 2,
  360. },
  361. AssertGroup {
  362. group_index: 0,
  363. expected_group: group_1,
  364. },
  365. AssertGroupRowCount {
  366. group_index: 1,
  367. row_count: 0,
  368. },
  369. AssertGroup {
  370. group_index: 1,
  371. expected_group: group_0,
  372. },
  373. ];
  374. test.run_scripts(scripts).await;
  375. }
  376. #[tokio::test]
  377. async fn group_move_group_row_after_move_group_test() {
  378. let mut test = GridGroupTest::new().await;
  379. let group_1 = test.group_at_index(1).await;
  380. let group_2 = test.group_at_index(2).await;
  381. let scripts = vec![
  382. MoveGroup {
  383. from_group_index: 1,
  384. to_group_index: 2,
  385. },
  386. AssertGroup {
  387. group_index: 1,
  388. expected_group: group_2,
  389. },
  390. AssertGroup {
  391. group_index: 2,
  392. expected_group: group_1,
  393. },
  394. MoveRow {
  395. from_group_index: 1,
  396. from_row_index: 0,
  397. to_group_index: 2,
  398. to_row_index: 0,
  399. },
  400. AssertGroupRowCount {
  401. group_index: 1,
  402. row_count: 1,
  403. },
  404. AssertGroupRowCount {
  405. group_index: 2,
  406. row_count: 3,
  407. },
  408. ];
  409. test.run_scripts(scripts).await;
  410. }
  411. #[tokio::test]
  412. async fn group_move_group_to_default_group_pos_test() {
  413. let mut test = GridGroupTest::new().await;
  414. let group_0 = test.group_at_index(0).await;
  415. let group_3 = test.group_at_index(3).await;
  416. let scripts = vec![
  417. MoveGroup {
  418. from_group_index: 3,
  419. to_group_index: 0,
  420. },
  421. AssertGroup {
  422. group_index: 0,
  423. expected_group: group_3,
  424. },
  425. AssertGroup {
  426. group_index: 1,
  427. expected_group: group_0,
  428. },
  429. ];
  430. test.run_scripts(scripts).await;
  431. }
  432. #[tokio::test]
  433. async fn group_insert_single_select_option_test() {
  434. let mut test = GridGroupTest::new().await;
  435. let new_option_name = "New option";
  436. let scripts = vec![
  437. AssertGroupCount(4),
  438. UpdateSingleSelectSelectOption {
  439. inserted_options: vec![SelectOptionPB::new(new_option_name)],
  440. },
  441. AssertGroupCount(5),
  442. ];
  443. test.run_scripts(scripts).await;
  444. let new_group = test.group_at_index(1).await;
  445. assert_eq!(new_group.desc, new_option_name);
  446. }
  447. #[tokio::test]
  448. async fn group_group_by_other_field() {
  449. let mut test = GridGroupTest::new().await;
  450. let multi_select_field = test.get_multi_select_field().await;
  451. let scripts = vec![
  452. GroupByField {
  453. field_id: multi_select_field.id.clone(),
  454. },
  455. AssertGroupRowCount {
  456. group_index: 1,
  457. row_count: 3,
  458. },
  459. AssertGroupRowCount {
  460. group_index: 2,
  461. row_count: 2,
  462. },
  463. AssertGroupCount(4),
  464. ];
  465. test.run_scripts(scripts).await;
  466. }