From b9e8e928619ffd1b0a545a5cae66af682b329d9a Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Thu, 11 Apr 2024 21:18:08 +0530 Subject: [PATCH] Revert "Merge pull request #71 from wednesday-solutions/feat/notification_service_test" This reverts commit bc9071d070be68e632e005d34f85ed2b7744d4dc, reversing changes made to c62a33971f54ef478b66a199890116d13f6cfef1. --- app/navigators/AppNavigator.js | 4 +-- app/scenes/RootScreen/index.js | 3 +- app/scenes/RootScreen/saga.js | 4 +-- app/scenes/RootScreen/tests/saga.test.js | 22 +++++------- app/services/NavigationService.js | 6 +++- app/services/{tests => }/UserService.test.js | 2 +- app/services/tests/navigate.test.js | 32 ----------------- app/services/tests/navigateAndReset.test.js | 34 ------------------- .../tests/setTopLevelNavigation.test.js | 20 ----------- 9 files changed, 20 insertions(+), 107 deletions(-) rename app/services/{tests => }/UserService.test.js (94%) delete mode 100644 app/services/tests/navigate.test.js delete mode 100644 app/services/tests/navigateAndReset.test.js delete mode 100644 app/services/tests/setTopLevelNavigation.test.js diff --git a/app/navigators/AppNavigator.js b/app/navigators/AppNavigator.js index b03dff6..d3baa1c 100644 --- a/app/navigators/AppNavigator.js +++ b/app/navigators/AppNavigator.js @@ -3,7 +3,7 @@ import { createStackNavigator } from '@react-navigation/stack'; import SplashScreen from '@scenes/SplashScreen/'; import ExampleScreen from '@scenes/ExampleScreen'; import { NavigationContainer } from '@react-navigation/native'; -import { setTopLevelNavigator } from '../services/NavigationService'; +import NavigationService from '../services/NavigationService'; const Stack = createStackNavigator(); /** * The root screen contains the application's navigation. @@ -12,7 +12,7 @@ const Stack = createStackNavigator(); */ export default function AppNavigator() { return ( - + diff --git a/app/scenes/RootScreen/index.js b/app/scenes/RootScreen/index.js index 93f16f3..7818b4a 100644 --- a/app/scenes/RootScreen/index.js +++ b/app/scenes/RootScreen/index.js @@ -2,9 +2,10 @@ import { connect } from 'react-redux'; import { PropTypes } from 'prop-types'; import AppNavigator from '@navigators/AppNavigator'; import Container from '@atoms/Container'; + import { rootScreenActions } from './reducer'; import React, { useEffect } from 'react'; -import { setRefForTopLevelNavigtor } from '@app/services/NavigationService'; +import setRefForTopLevelNavigtor from '@app/services/NavigationService'; const RootScreen = props => { useEffect(() => { diff --git a/app/scenes/RootScreen/saga.js b/app/scenes/RootScreen/saga.js index a988d24..098f16e 100644 --- a/app/scenes/RootScreen/saga.js +++ b/app/scenes/RootScreen/saga.js @@ -1,12 +1,12 @@ import { takeLatest } from 'redux-saga/effects'; -import { navigateAndReset } from '@app/services/NavigationService'; +import NavigationService from '@app/services/NavigationService'; import { rootScreenTypes } from './reducer'; /** * The startup saga is the place to define behavior to execute when the application starts. */ export function* startup() { - setTimeout(() => navigateAndReset('MainScreen'), 1000); + setTimeout(() => NavigationService.navigateAndReset('MainScreen'), 1000); } /** diff --git a/app/scenes/RootScreen/tests/saga.test.js b/app/scenes/RootScreen/tests/saga.test.js index c743c43..f8ce417 100644 --- a/app/scenes/RootScreen/tests/saga.test.js +++ b/app/scenes/RootScreen/tests/saga.test.js @@ -1,4 +1,3 @@ -/* eslint-disable sonarjs/no-duplicate-string */ /** * Test sagas */ @@ -6,22 +5,12 @@ /* eslint-disable redux-saga/yield-effects */ import { takeLatest } from 'redux-saga/effects'; -// import NavigationService from 'app/services/NavigationService'; -import { navigateAndReset } from '@app/services/NavigationService'; +import NavigationService from 'app/services/NavigationService'; import { timeout } from 'app/utils/testUtils'; import rootScreenSaga, { startup } from '../saga'; import { rootScreenTypes } from '../reducer'; import set from 'lodash/set'; - -const NavigationService = '@app/services/NavigationService'; -jest.mock('@app/services/NavigationService', () => ({ - ...jest.requireActual('@app/services/NavigationService'), - navigateAndReset: jest.fn() -})); describe('Tests for RootScreen sagas', () => { - afterEach(() => { - jest.clearAllMocks(); - }); const setupTests = () => ({ generator: rootScreenSaga(), submitSpy: jest.fn() @@ -36,10 +25,15 @@ describe('Tests for RootScreen sagas', () => { it('should ensure that the navigation service is called after waiting for 1000ms', async () => { const method = startup(); + NavigationService.setTopLevelNavigator({ dispatch: () => {} }); + const navigateAndResetSpy = jest.spyOn( + NavigationService, + 'navigateAndReset' + ); method.next(); await timeout(1000); - expect(navigateAndReset).toHaveBeenCalled(); - expect(navigateAndReset).toHaveBeenCalledWith('MainScreen'); + expect(navigateAndResetSpy).toHaveBeenCalled(); + expect(navigateAndResetSpy).toHaveBeenCalledWith('MainScreen'); }); it('should ensure that the navigation service is called after waiting for 1000ms', async () => { diff --git a/app/services/NavigationService.js b/app/services/NavigationService.js index 7b5ae4b..467c8ac 100644 --- a/app/services/NavigationService.js +++ b/app/services/NavigationService.js @@ -50,4 +50,8 @@ function navigateAndReset(routeName, params) { ); } -export { navigate, navigateAndReset, setTopLevelNavigator }; +export default { + navigate, + navigateAndReset, + setTopLevelNavigator +}; diff --git a/app/services/tests/UserService.test.js b/app/services/UserService.test.js similarity index 94% rename from app/services/tests/UserService.test.js rename to app/services/UserService.test.js index a8155f7..53cbead 100644 --- a/app/services/tests/UserService.test.js +++ b/app/services/UserService.test.js @@ -1,6 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; import { getApiClient } from 'app/utils/apiUtils'; -import { getUser } from '../UserService'; +import { getUser } from './UserService'; describe('UserService tests', () => { it('should make the api call to "/quotes?count=1"', async () => { diff --git a/app/services/tests/navigate.test.js b/app/services/tests/navigate.test.js deleted file mode 100644 index fea5a93..0000000 --- a/app/services/tests/navigate.test.js +++ /dev/null @@ -1,32 +0,0 @@ -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 } - }); - }); -}); diff --git a/app/services/tests/navigateAndReset.test.js b/app/services/tests/navigateAndReset.test.js deleted file mode 100644 index 0a0df12..0000000 --- a/app/services/tests/navigateAndReset.test.js +++ /dev/null @@ -1,34 +0,0 @@ -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 } - }); - }); -}); diff --git a/app/services/tests/setTopLevelNavigation.test.js b/app/services/tests/setTopLevelNavigation.test.js deleted file mode 100644 index dcf2aa1..0000000 --- a/app/services/tests/setTopLevelNavigation.test.js +++ /dev/null @@ -1,20 +0,0 @@ -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 - ); - }); -});