test.rs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. use crate::grid::group_test::script::GridGroupTest;
  2. use crate::grid::group_test::script::GroupScript::*;
  3. #[tokio::test]
  4. async fn board_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 board_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 board_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 board_move_row_to_other_group_and_reorder_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. MoveRow {
  86. from_group_index: 1,
  87. from_row_index: 1,
  88. to_group_index: 1,
  89. to_row_index: 2,
  90. },
  91. AssertRow {
  92. group_index: 1,
  93. row_index: 2,
  94. row: group.rows.get(0).unwrap().clone(),
  95. },
  96. ];
  97. test.run_scripts(scripts).await;
  98. }
  99. #[tokio::test]
  100. async fn board_create_row_test() {
  101. let mut test = GridGroupTest::new().await;
  102. let scripts = vec![
  103. CreateRow { group_index: 0 },
  104. AssertGroupRowCount {
  105. group_index: 0,
  106. row_count: 3,
  107. },
  108. CreateRow { group_index: 1 },
  109. CreateRow { group_index: 1 },
  110. AssertGroupRowCount {
  111. group_index: 1,
  112. row_count: 4,
  113. },
  114. ];
  115. test.run_scripts(scripts).await;
  116. }
  117. #[tokio::test]
  118. async fn board_delete_row_test() {
  119. let mut test = GridGroupTest::new().await;
  120. let scripts = vec![
  121. DeleteRow {
  122. group_index: 0,
  123. row_index: 0,
  124. },
  125. AssertGroupRowCount {
  126. group_index: 0,
  127. row_count: 1,
  128. },
  129. ];
  130. test.run_scripts(scripts).await;
  131. }
  132. #[tokio::test]
  133. async fn board_delete_all_row_test() {
  134. let mut test = GridGroupTest::new().await;
  135. let scripts = vec![
  136. DeleteRow {
  137. group_index: 0,
  138. row_index: 0,
  139. },
  140. DeleteRow {
  141. group_index: 0,
  142. row_index: 0,
  143. },
  144. AssertGroupRowCount {
  145. group_index: 0,
  146. row_count: 0,
  147. },
  148. ];
  149. test.run_scripts(scripts).await;
  150. }
  151. #[tokio::test]
  152. async fn board_update_row_test() {
  153. let mut test = GridGroupTest::new().await;
  154. let scripts = vec![
  155. // Update the row at 0 in group0 by setting the row's group field data
  156. UpdateRow {
  157. from_group_index: 0,
  158. row_index: 0,
  159. to_group_index: 1,
  160. },
  161. AssertGroupRowCount {
  162. group_index: 0,
  163. row_count: 1,
  164. },
  165. AssertGroupRowCount {
  166. group_index: 1,
  167. row_count: 3,
  168. },
  169. ];
  170. test.run_scripts(scripts).await;
  171. }
  172. #[tokio::test]
  173. async fn board_reorder_group_test() {
  174. let mut test = GridGroupTest::new().await;
  175. let scripts = vec![
  176. // Update the row at 0 in group0 by setting the row's group field data
  177. UpdateRow {
  178. from_group_index: 0,
  179. row_index: 0,
  180. to_group_index: 1,
  181. },
  182. AssertGroupRowCount {
  183. group_index: 0,
  184. row_count: 1,
  185. },
  186. AssertGroupRowCount {
  187. group_index: 1,
  188. row_count: 3,
  189. },
  190. ];
  191. test.run_scripts(scripts).await;
  192. }
  193. #[tokio::test]
  194. async fn board_move_group_test() {
  195. let mut test = GridGroupTest::new().await;
  196. let group_0 = test.group_at_index(0).await;
  197. let group_1 = test.group_at_index(1).await;
  198. let scripts = vec![
  199. MoveGroup {
  200. from_group_index: 0,
  201. to_group_index: 1,
  202. },
  203. AssertGroup {
  204. group_index: 0,
  205. expected_group: group_1,
  206. },
  207. AssertGroup {
  208. group_index: 1,
  209. expected_group: group_0,
  210. },
  211. ];
  212. test.run_scripts(scripts).await;
  213. }