From 8ad104d7396192039f2a4a75a0a8afc2d5e95d68 Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Mon, 15 Apr 2024 19:32:43 +0530 Subject: [PATCH] Revert "Merge pull request #77 from wednesday-solutions/feature/rootscreen-refactor" This reverts commit 9f18cdcd1af75b55d51203526245ae9531f62ccc, reversing changes made to 230157c1adb5cf82ab479d2b289235e5bf9db240. --- app/scenes/RootScreen/index.js | 35 ++++++++++++--------- app/scenes/RootScreen/saga.js | 4 +-- app/scenes/RootScreen/tests/index.test.js | 13 +++++--- app/scenes/RootScreen/tests/reducer.test.js | 17 +++------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/app/scenes/RootScreen/index.js b/app/scenes/RootScreen/index.js index 1351e91..963caae 100644 --- a/app/scenes/RootScreen/index.js +++ b/app/scenes/RootScreen/index.js @@ -1,23 +1,30 @@ +import React, { Component } from 'react'; import { connect } from 'react-redux'; import { PropTypes } from 'prop-types'; +import NavigationService from '@services/NavigationService'; import AppNavigator from '@navigators/AppNavigator'; import Container from '@atoms/Container'; -import React, { useEffect } from 'react'; -import { setRefForTopLevelNavigtor } from '@app/services/NavigationService'; + import { rootScreenActions } from './reducer'; -const RootScreen = props => { - useEffect(() => { - // Run the startup function when the component mounts - props.startup(); - }, []); +export class RootScreen extends Component { + componentDidMount() { + // Run the startup saga when the application is starting + this.props.startup(); + } - return ( - - - - ); -}; + setRefForTopLevelNavigtor = navigatorRef => { + NavigationService.setTopLevelNavigator(navigatorRef); + }; + + render() { + return ( + + + + ); + } +} RootScreen.propTypes = { startup: PropTypes.func @@ -26,5 +33,5 @@ RootScreen.propTypes = { const mapDispatchToProps = dispatch => ({ startup: () => dispatch(rootScreenActions.startup()) }); + export default connect(null, mapDispatchToProps)(RootScreen); -export { RootScreen as RootScreenTest }; diff --git a/app/scenes/RootScreen/saga.js b/app/scenes/RootScreen/saga.js index e9fa3e9..0eadf9b 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); } export default function* startUpSaga() { diff --git a/app/scenes/RootScreen/tests/index.test.js b/app/scenes/RootScreen/tests/index.test.js index a93ddc6..d363424 100644 --- a/app/scenes/RootScreen/tests/index.test.js +++ b/app/scenes/RootScreen/tests/index.test.js @@ -6,23 +6,26 @@ import React from 'react'; import { renderWithIntl } from 'app/utils/testUtils'; -import { RootScreenTest } from '../index'; -export const setupJest = () => ({ submitSpy: jest.fn() }); +import { RootScreen as RootScreenTest } from '../index'; + describe(' container', () => { + let submitSpy; + + beforeAll(() => { + submitSpy = jest.fn(); + }); + it('should render and match the snapshot', () => { - const { submitSpy } = setupJest(); const baseElement = renderWithIntl(); expect(baseElement).toMatchSnapshot(); }); it('should call the startup prop on mount', () => { - const { submitSpy } = setupJest(); renderWithIntl(); expect(submitSpy).toHaveBeenCalled(); }); it('should not render rootSceen Container', () => { - const { submitSpy } = setupJest(); const { getByTestId } = renderWithIntl( ); diff --git a/app/scenes/RootScreen/tests/reducer.test.js b/app/scenes/RootScreen/tests/reducer.test.js index 90666cb..40243db 100644 --- a/app/scenes/RootScreen/tests/reducer.test.js +++ b/app/scenes/RootScreen/tests/reducer.test.js @@ -6,15 +6,16 @@ import { /* eslint-disable default-case, no-param-reassign */ describe('Tests for RootScreen reducers', () => { - const setupTests = () => ({ state: initialState }); + let state; + beforeEach(() => { + state = initialState; + }); it('should return the initial state', () => { - const { state } = setupTests(); expect(rootContainerReducer(undefined, {})).toEqual(state); }); it('should return the initial state when an action of type STARTUP is dispatched', () => { - const { state } = setupTests(); // since startup is called to initiate screen navigation the store should remain intact expect( rootContainerReducer(state, { @@ -22,14 +23,4 @@ describe('Tests for RootScreen reducers', () => { }) ).toEqual(state); }); - - it('should return the initial state when an action of type NONEXIST is dispatched', () => { - const { state } = setupTests(); - // since startup is called to initiate screen navigation the store should remain intact - expect( - rootContainerReducer(state, { - type: rootScreenTypes.NONEXIST - }) - ).toEqual(state); - }); });