1import { getReactNavigationScreensConfig } from '../getReactNavigationConfig';
2
3const mockRoutes = [
4  {
5    children: [
6      {
7        children: [],
8        dynamic: null,
9        route: 'people',
10        contextKey: './(second-group)/people.tsx',
11      },
12    ],
13    dynamic: null,
14    route: '(second-group)',
15    contextKey: './(second-group)/_layout.tsx',
16  },
17  {
18    children: [
19      {
20        children: [],
21        dynamic: [
22          {
23            name: 'deep',
24            deep: true,
25          },
26        ],
27        route: '[...deep]',
28        contextKey: './(group)/[...deep].tsx',
29      },
30      {
31        children: [],
32        dynamic: [
33          {
34            name: 'dynamic',
35            deep: false,
36          },
37        ],
38        route: '[dynamic]',
39        contextKey: './(group)/[dynamic].tsx',
40      },
41      {
42        children: [],
43        dynamic: null,
44        route: 'index',
45        contextKey: './(group)/index.tsx',
46      },
47    ],
48    dynamic: null,
49    route: '(group)',
50    contextKey: './(group)/_layout.tsx',
51  },
52  {
53    children: [],
54    dynamic: [
55      {
56        name: 'screen',
57        deep: true,
58      },
59    ],
60    route: 'other/nested/[...screen]',
61    contextKey: './other/nested/[...screen].js',
62  },
63  {
64    children: [],
65    dynamic: null,
66    route: '_sitemap',
67    contextKey: './_sitemap.tsx',
68    generated: true,
69    internal: true,
70  },
71];
72
73describe(getReactNavigationScreensConfig, () => {
74  it('should return a valid linking config', () => {
75    expect(
76      getReactNavigationScreensConfig(
77        // @ts-expect-error
78        mockRoutes,
79        true
80      )
81    ).toEqual({
82      '(group)': {
83        initialRouteName: undefined,
84        path: '(group)',
85        screens: { '[...deep]': '*deep', '[dynamic]': ':dynamic', index: '' },
86      },
87      '(second-group)': {
88        initialRouteName: undefined,
89        path: '(second-group)',
90        screens: { people: 'people' },
91      },
92      _sitemap: '_sitemap',
93      'other/nested/[...screen]': 'other/nested/*screen',
94    });
95  });
96  it('should return a valid linking config with route nodes', () => {
97    expect(
98      getReactNavigationScreensConfig(
99        // @ts-expect-error
100        mockRoutes,
101        false
102      )
103    ).toEqual({
104      '(group)': {
105        initialRouteName: undefined,
106        path: '(group)',
107        _route: expect.anything(),
108        screens: {
109          '[...deep]': {
110            path: '*deep',
111            screens: {},
112            _route: expect.anything(),
113          },
114          '[dynamic]': {
115            path: ':dynamic',
116            screens: {},
117            _route: expect.anything(),
118          },
119          index: { path: '', screens: {}, _route: expect.anything() },
120        },
121      },
122      '(second-group)': {
123        initialRouteName: undefined,
124        path: '(second-group)',
125        _route: expect.anything(),
126        screens: {
127          people: { path: 'people', screens: {}, _route: expect.anything() },
128        },
129      },
130      _sitemap: { path: '_sitemap', screens: {}, _route: expect.anything() },
131      'other/nested/[...screen]': {
132        path: 'other/nested/*screen',
133        screens: {},
134        _route: expect.anything(),
135      },
136    });
137  });
138});
139