-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from wednesday-solutions/feat/root-component-n…
…avogation-test test for setting top level navogator in root component
- Loading branch information
Showing
9 changed files
with
107 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/services/UserService.test.js → app/services/tests/UserService.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { navigate, setTopLevelNavigator } from '../NavigationService'; | ||
import { NavigationActions } from '@react-navigation/compat'; | ||
jest.mock('@react-navigation/compat', () => ({ | ||
NavigationActions: { | ||
navigate: jest.fn() | ||
} | ||
})); | ||
const navigatorRef = { goBack: 'goBack', dispatch: jest.fn() }; | ||
setTopLevelNavigator(navigatorRef); | ||
describe('navigate', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('dispatches navigation action with the correct routeName and params', () => { | ||
const routeName = '/test'; | ||
const params = { screen: 'MainScreen' }; | ||
NavigationActions.navigate.mockReturnValueOnce({ | ||
type: 'NAVIGATE_ACTION', | ||
payload: { routeName, params } | ||
}); | ||
navigate(routeName, params); | ||
expect(NavigationActions.navigate).toHaveBeenCalledWith({ | ||
routeName, | ||
params | ||
}); | ||
expect(navigatorRef.dispatch).toHaveBeenCalledWith({ | ||
type: 'NAVIGATE_ACTION', | ||
payload: { routeName, params } | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { setTopLevelNavigator, navigateAndReset } from '../NavigationService'; | ||
import { StackActions } from '@react-navigation/compat'; | ||
|
||
jest.mock('@react-navigation/compat', () => ({ | ||
StackActions: { | ||
replace: jest.fn() | ||
} | ||
})); | ||
const navigatorRef = { goBack: 'goBack', dispatch: jest.fn() }; | ||
setTopLevelNavigator(navigatorRef); | ||
describe('test navigateAndReset', () => { | ||
afterEach(() => { | ||
// Reset mocks after each test | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('dispatches stack action with the correct routeName and params', () => { | ||
const routeName = '/test'; | ||
const params = { screen: 'MainScreen' }; | ||
StackActions.replace.mockReturnValueOnce({ | ||
type: 'NAVIGATE_ACTION', | ||
payload: { routeName, params } | ||
}); | ||
navigateAndReset(routeName, params); | ||
expect(StackActions.replace).toHaveBeenCalledWith({ | ||
routeName, | ||
params | ||
}); | ||
expect(navigatorRef.dispatch).toHaveBeenCalledWith({ | ||
type: 'NAVIGATE_ACTION', | ||
payload: { routeName, params } | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import set from 'lodash/set'; | ||
import { setTopLevelNavigator } from '../NavigationService'; | ||
jest.mock('lodash/set', () => jest.fn()); | ||
describe('setTopLevelNavigator', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('sets the navigator object with the provided reference', () => { | ||
const navigatorObject = { | ||
navigator: null | ||
}; | ||
const navigatorRef = { goBack: 'goBack' }; | ||
setTopLevelNavigator(navigatorRef); | ||
expect(set).toHaveBeenCalledWith( | ||
navigatorObject, | ||
'navigator', | ||
navigatorRef | ||
); | ||
}); | ||
}); |