Skip to content

Commit

Permalink
test: add tests for linking with nested screens
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 22, 2024
1 parent d2513d7 commit 482d9c4
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions packages/core/src/__tests__/StaticNavigation.test.tsx
Expand Up @@ -479,7 +479,7 @@ it('returns undefined if there is no linking configuration', () => {
});

it('automatically generates paths if auto is specified', () => {
const Nested = createTestNavigator({
const NestedA = createTestNavigator({
screens: {
Profile: {
screen: TestScreen,
Expand All @@ -496,7 +496,7 @@ it('automatically generates paths if auto is specified', () => {
screens: {
Login: {
screen: TestScreen,
linking: {},
linking: undefined,
},
Register: {
screen: TestScreen,
Expand All @@ -510,14 +510,25 @@ it('automatically generates paths if auto is specified', () => {
},
});

const NestedB = createTestNavigator({
screens: {
Library: TestScreen,
Wishlist: {
screen: TestScreen,
},
},
});

const Root = createTestNavigator({
screens: {
Home: TestScreen,
Feed: {
screen: TestScreen,
},
Nested: {
screen: Nested,
NestedA,
NestedB: {
screen: NestedB,
linking: 'store/:type',
},
},
groups: {
Expand All @@ -543,25 +554,16 @@ it('automatically generates paths if auto is specified', () => {
expect(getStateFromPath('forgot-password', { screens })).toEqual({
routes: [
{
name: 'Nested',
name: 'NestedA',
state: { routes: [{ name: 'Forgot', path: 'forgot-password' }] },
},
],
});

expect(getStateFromPath('contact', { screens })).toEqual({
routes: [
{
name: 'Contact',
path: 'contact',
},
],
});

expect(getStateFromPath('settings', { screens })).toEqual({
routes: [
{
name: 'Nested',
name: 'NestedA',
state: {
routes: [{ name: 'Settings', path: 'settings' }],
},
Expand All @@ -572,7 +574,7 @@ it('automatically generates paths if auto is specified', () => {
expect(getStateFromPath('profile?id=123', { screens })).toEqual({
routes: [
{
name: 'Nested',
name: 'NestedA',
state: {
routes: [
{
Expand All @@ -585,4 +587,33 @@ it('automatically generates paths if auto is specified', () => {
},
],
});

expect(getStateFromPath('store/furniture', { screens })).toEqual({
routes: [
{
name: 'NestedB',
params: { type: 'furniture' },
path: 'store/furniture',
},
],
});

expect(getStateFromPath('store/digital/library', { screens })).toEqual({
routes: [
{
name: 'NestedB',
params: { type: 'digital' },
state: { routes: [{ name: 'Library', path: 'store/digital/library' }] },
},
],
});

expect(getStateFromPath('contact', { screens })).toEqual({
routes: [
{
name: 'Contact',
path: 'contact',
},
],
});
});

0 comments on commit 482d9c4

Please sign in to comment.