react-native-navigation的迁移库

LayoutTreeCrawler.test.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import LayoutTypes from './LayoutTypes';
  2. import LayoutTreeCrawler from './LayoutTreeCrawler';
  3. import Store from '../containers/Store';
  4. import UniqueIdProvider from '../adapters/UniqueIdProvider.mock';
  5. describe('LayoutTreeCrawler', () => {
  6. let uut;
  7. let store;
  8. beforeEach(() => {
  9. store = new Store();
  10. uut = new LayoutTreeCrawler(new UniqueIdProvider(), store);
  11. });
  12. it('crawls a layout tree and adds unique id to each node', () => {
  13. const node = { type: LayoutTypes.Container, children: [{ type: LayoutTypes.BottomTabs }] };
  14. uut.crawl(node);
  15. expect(node.id).toEqual('Container+UNIQUE_ID');
  16. expect(node.children[0].id).toEqual('BottomTabs+UNIQUE_ID');
  17. });
  18. it('crawls a layout tree and ensures data exists', () => {
  19. const node = { type: LayoutTypes.Container, children: [{ type: LayoutTypes.BottomTabs }] };
  20. uut.crawl(node);
  21. expect(node.data).toEqual({});
  22. expect(node.children[0].data).toEqual({});
  23. });
  24. it('crawls a layout tree and ensures children exists', () => {
  25. const node = { type: LayoutTypes.Container, children: [{ type: LayoutTypes.BottomTabs }] };
  26. uut.crawl(node);
  27. expect(node.children[0].children).toEqual([]);
  28. });
  29. it('crawls a layout tree and asserts known layout type', () => {
  30. const node = { type: LayoutTypes.Container, children: [{ type: 'Bob' }] };
  31. expect(() => uut.crawl(node)).toThrow(new Error('Unknown layout type Bob'));
  32. });
  33. it('saves passProps into store for Container nodes', () => {
  34. const node = { type: LayoutTypes.BottomTabs, children: [{ type: LayoutTypes.Container, data: { passProps: { myProp: 123 } } }] };
  35. expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual({});
  36. uut.crawl(node);
  37. expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual({ myProp: 123 });
  38. });
  39. });