react-native-navigation的迁移库

LayoutTreeParser.test.js 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import * as SimpleLayouts from './SimpleLayouts';
  2. import LayoutTreeParser from './LayoutTreeParser';
  3. describe('LayoutTreeParser', () => {
  4. let uut;
  5. beforeEach(() => {
  6. uut = new LayoutTreeParser();
  7. });
  8. describe('parseFromSimpleJSON', () => {
  9. it('parses single screen', () => {
  10. expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenApp))
  11. .toEqual({
  12. type: 'ContainerStack',
  13. children: [
  14. {
  15. type: 'Container',
  16. data: {
  17. name: 'com.example.MyScreen'
  18. },
  19. children: []
  20. }
  21. ]
  22. });
  23. });
  24. it('parses single screen with props', () => {
  25. expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams))
  26. .toEqual({
  27. type: 'ContainerStack',
  28. children: [
  29. {
  30. type: 'Container',
  31. children: [],
  32. data: {
  33. name: 'com.example.MyScreen',
  34. passProps: SimpleLayouts.passProps,
  35. style: {},
  36. buttons: {}
  37. }
  38. }
  39. ]
  40. });
  41. const parsedPropsFn = uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams)
  42. .children[0].data.passProps.fnProp;
  43. expect(parsedPropsFn).toBe(SimpleLayouts.passProps.fnProp);
  44. expect(parsedPropsFn()).toEqual('Hello from a function');
  45. });
  46. it('parses tab based', () => {
  47. expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedApp))
  48. .toEqual({
  49. type: 'BottomTabs',
  50. children: [
  51. {
  52. type: 'ContainerStack',
  53. children: [
  54. {
  55. type: 'Container',
  56. children: [],
  57. data: {
  58. name: 'com.example.ATab'
  59. }
  60. }
  61. ]
  62. },
  63. {
  64. type: 'ContainerStack',
  65. children: [
  66. {
  67. type: 'Container',
  68. children: [],
  69. data: {
  70. name: 'com.example.SecondTab'
  71. }
  72. }
  73. ]
  74. },
  75. {
  76. type: 'ContainerStack',
  77. children: [
  78. {
  79. type: 'Container',
  80. children: [],
  81. data: {
  82. name: 'com.example.ATab'
  83. }
  84. }
  85. ]
  86. }
  87. ]
  88. });
  89. });
  90. it('parses side menus', () => {
  91. expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
  92. .toEqual({
  93. type: 'SideMenuRoot',
  94. children: [
  95. {
  96. type: 'SideMenuLeft',
  97. children: [
  98. {
  99. type: 'Container',
  100. data: {
  101. name: 'com.example.SideMenu'
  102. },
  103. children: []
  104. }
  105. ]
  106. },
  107. {
  108. type: 'SideMenuCenter',
  109. children: [
  110. {
  111. type: 'ContainerStack',
  112. children: [
  113. {
  114. type: 'Container',
  115. data: {
  116. name: 'com.example.MyScreen'
  117. },
  118. children: []
  119. }
  120. ]
  121. }
  122. ]
  123. }
  124. ]
  125. });
  126. });
  127. it('parses side menu right', () => {
  128. expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithRightSideMenu))
  129. .toEqual({
  130. type: 'SideMenuRoot',
  131. children: [
  132. {
  133. type: 'SideMenuCenter',
  134. children: [
  135. {
  136. type: 'ContainerStack',
  137. children: [
  138. {
  139. type: 'Container',
  140. data: {
  141. name: 'com.example.MyScreen'
  142. },
  143. children: []
  144. }
  145. ]
  146. }
  147. ]
  148. },
  149. {
  150. type: 'SideMenuRight',
  151. children: [
  152. {
  153. type: 'Container',
  154. data: {
  155. name: 'com.example.SideMenu'
  156. },
  157. children: []
  158. }
  159. ]
  160. }
  161. ]
  162. });
  163. });
  164. it('parses both side menus', () => {
  165. expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithBothMenus))
  166. .toEqual({
  167. type: 'SideMenuRoot',
  168. children: [
  169. {
  170. type: 'SideMenuLeft',
  171. children: [
  172. {
  173. type: 'Container',
  174. data: {
  175. name: 'com.example.Menu1'
  176. },
  177. children: []
  178. }
  179. ]
  180. },
  181. {
  182. type: 'SideMenuCenter',
  183. children: [
  184. {
  185. type: 'ContainerStack',
  186. children: [
  187. {
  188. type: 'Container',
  189. data: {
  190. name: 'com.example.MyScreen'
  191. },
  192. children: []
  193. }
  194. ]
  195. }
  196. ]
  197. },
  198. {
  199. type: 'SideMenuRight',
  200. children: [
  201. {
  202. type: 'Container',
  203. data: {
  204. name: 'com.example.Menu2'
  205. },
  206. children: []
  207. }
  208. ]
  209. }
  210. ]
  211. });
  212. });
  213. it('parses tabs with side menus', () => {
  214. expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedWithBothSideMenus))
  215. .toEqual({
  216. type: 'SideMenuRoot',
  217. children: [
  218. {
  219. type: 'SideMenuLeft',
  220. children: [
  221. {
  222. type: 'Container',
  223. data: {
  224. name: 'com.example.Menu1'
  225. },
  226. children: []
  227. }
  228. ]
  229. },
  230. {
  231. type: 'SideMenuCenter',
  232. children: [
  233. {
  234. type: 'BottomTabs',
  235. children: [
  236. {
  237. type: 'ContainerStack',
  238. children: [
  239. {
  240. type: 'Container',
  241. data: {
  242. name: 'com.example.FirstTab'
  243. },
  244. children: []
  245. }
  246. ]
  247. },
  248. {
  249. type: 'ContainerStack',
  250. children: [
  251. {
  252. type: 'Container',
  253. data: {
  254. name: 'com.example.SecondTab'
  255. },
  256. children: []
  257. }
  258. ]
  259. }
  260. ]
  261. }
  262. ]
  263. },
  264. {
  265. type: 'SideMenuRight',
  266. children: [
  267. {
  268. type: 'Container',
  269. data: {
  270. name: 'com.example.Menu2'
  271. },
  272. children: []
  273. }
  274. ]
  275. }
  276. ]
  277. });
  278. });
  279. });
  280. describe('createContainer', () => {
  281. it('creates container object with passed data', () => {
  282. expect(uut.createContainer({ foo: 'bar' })).toEqual({ type: 'Container', data: { foo: 'bar' }, children: [] });
  283. });
  284. });
  285. });