test.rs 7.8 KB

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