-
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.
- Loading branch information
1 parent
0209dde
commit 3f66ccb
Showing
4 changed files
with
81 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NavigationActions } from '@react-navigation/compat'; | ||
import { navigate, setTopLevelNavigator } from '@services/navigationService'; | ||
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,37 @@ | ||
import { StackActions } from '@react-navigation/compat'; | ||
import { | ||
setTopLevelNavigator, | ||
navigateAndReset | ||
} from '@services/navigationService'; | ||
|
||
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,11 @@ | ||
import { setTopLevelNavigator } from '@services/navigationService'; // Import the function to be tested | ||
|
||
describe('setTopLevelNavigator', () => { | ||
it('should update navigatorObject with the provided navigatorRef using mocked Object.assign', () => { | ||
const mockNavigatorRef = { navigator: 'test_navigator' }; | ||
const mockAssign = jest.spyOn(Object, 'assign'); | ||
setTopLevelNavigator(mockNavigatorRef); | ||
expect(mockAssign).toHaveBeenCalledTimes(1); | ||
mockAssign.mockRestore(); | ||
}); | ||
}); |
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