Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #77 from wednesday-solutions/feature/roots… #83

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions app/scenes/RootScreen/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<Container testID="root-screen">
<AppNavigator ref={setRefForTopLevelNavigtor} />
</Container>
);
};
setRefForTopLevelNavigtor = navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
};

render() {
return (
<Container testID="root-screen">
<AppNavigator />
</Container>
);
}

Check warning on line 26 in app/scenes/RootScreen/index.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹 Function is not covered

Warning! Not covered function
}

Check warning on line 27 in app/scenes/RootScreen/index.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 27 in app/scenes/RootScreen/index.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹 Function is not covered

Warning! Not covered function

Check warning on line 28 in app/scenes/RootScreen/index.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
RootScreen.propTypes = {
startup: PropTypes.func
Expand All @@ -26,5 +33,5 @@
const mapDispatchToProps = dispatch => ({
startup: () => dispatch(rootScreenActions.startup())
});

export default connect(null, mapDispatchToProps)(RootScreen);
export { RootScreen as RootScreenTest };
4 changes: 2 additions & 2 deletions app/scenes/RootScreen/saga.js
Original file line number Diff line number Diff line change
@@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using delay from redux-saga instead of setTimeout for better control and testability.

- setTimeout(() => NavigationService.navigateAndReset('MainScreen'), 1000);
+ yield delay(1000);
+ NavigationService.navigateAndReset('MainScreen');

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
setTimeout(() => NavigationService.navigateAndReset('MainScreen'), 1000);
yield delay(1000);
NavigationService.navigateAndReset('MainScreen');

}

export default function* startUpSaga() {
Expand Down
13 changes: 8 additions & 5 deletions app/scenes/RootScreen/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<HomeScreen /> container', () => {
let submitSpy;

beforeAll(() => {
submitSpy = jest.fn();
});

it('should render and match the snapshot', () => {
const { submitSpy } = setupJest();
const baseElement = renderWithIntl(<RootScreenTest startup={submitSpy} />);
expect(baseElement).toMatchSnapshot();
});

it('should call the startup prop on mount', () => {
const { submitSpy } = setupJest();
renderWithIntl(<RootScreenTest startup={submitSpy} />);
expect(submitSpy).toHaveBeenCalled();
});

it('should not render rootSceen Container', () => {
const { submitSpy } = setupJest();
const { getByTestId } = renderWithIntl(
<RootScreenTest startup={submitSpy} />
);
Expand Down
17 changes: 4 additions & 13 deletions app/scenes/RootScreen/tests/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@ 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, {
type: rootScreenTypes.STARTUP
})
).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);
});
});
Loading