Skip to content

Commit

Permalink
feat: refactor file names
Browse files Browse the repository at this point in the history
  • Loading branch information
alichherawalla committed Apr 15, 2024
1 parent 8c78a99 commit 451b0fe
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 23 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: react-native-template
on:
pull_request_target:
pull_request:
branches: [ master ]
jobs:
install-and-test:
Expand All @@ -19,3 +19,15 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
threshold: 80
package-manager: yarn
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
Original file line number Diff line number Diff line change
Expand Up @@ -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 NavigationService from '../services/NavigationService';
import { setTopLevelNavigator } from '@services/navigationService';
const Stack = createStackNavigator();
/**
* The root screen contains the application's navigation.
Expand All @@ -12,7 +12,7 @@ const Stack = createStackNavigator();
*/
export default function AppNavigator() {
return (
<NavigationContainer ref={NavigationService.setTopLevelNavigator}>
<NavigationContainer ref={setTopLevelNavigator}>
<Stack.Navigator headerMode="none" initialRouteName="SplashScreen">
<Stack.Screen name="SplashScreen" component={SplashScreen} />
<Stack.Screen name="MainScreen" component={ExampleScreen} />
Expand Down
2 changes: 1 addition & 1 deletion app/scenes/ExampleScreen/saga.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { put, call, takeLatest } from 'redux-saga/effects';
import { get } from 'lodash';
import { getUser } from '@app/services/UserService';
import { getUser } from '@app/services/userService';
import { exampleScreenActions, exampleScreenTypes } from './reducer';

/**
Expand Down
2 changes: 1 addition & 1 deletion app/scenes/ExampleScreen/tests/saga.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable redux-saga/yield-effects */

import { takeLatest, call, put } from 'redux-saga/effects';
import { getUser } from 'app/services/UserService';
import { getUser } from 'app/services/userService';
import { apiResponseGenerator } from 'app/utils/testUtils';
import exampleScreenSaga, { fetchUser } from '../saga';
import { exampleScreenTypes } from '../reducer';
Expand Down
4 changes: 2 additions & 2 deletions app/scenes/RootScreen/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import { PropTypes } from 'prop-types';
import AppNavigator from '@navigators/AppNavigator';
import AppNavigator from '@navigators/appNavigator';
import Container from '@atoms/Container';
import React, { useEffect } from 'react';
import { setRefForTopLevelNavigtor } from '@app/services/NavigationService';
import { setRefForTopLevelNavigtor } from '@app/services/navigationService';
import { rootScreenActions } from './reducer';

const RootScreen = props => {
Expand Down
2 changes: 1 addition & 1 deletion app/scenes/RootScreen/saga.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { takeLatest } from 'redux-saga/effects';
import { navigateAndReset } from '@app/services/NavigationService';
import { navigateAndReset } from '@app/services/navigationService';
import { rootScreenTypes } from './reducer';

/**
Expand Down
10 changes: 5 additions & 5 deletions app/scenes/RootScreen/tests/saga.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable redux-saga/yield-effects */

import { takeLatest } from 'redux-saga/effects';
import NavigationService from 'app/services/NavigationService';
import { setTopLevelNavigator } from 'app/services/navigationService';
import { timeout } from 'app/utils/testUtils';
import rootScreenSaga, { startup } from '../saga';
import { rootScreenTypes } from '../reducer';
Expand All @@ -25,17 +25,17 @@ describe('Tests for RootScreen sagas', () => {
);
});

it('should ensure that the navigation service is called after waiting for 1000ms', async () => {
it('should ensure that the navigation service is called after waiting for 1000ms11', async () => {

Check failure on line 28 in app/scenes/RootScreen/tests/saga.test.js

View workflow job for this annotation

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

Tests for RootScreen sagas > should ensure that the navigation service is called after waiting for 1000ms

TypeError: (0 , _NavigationService.navigateAndReset) is not a function at Timeout._onTimeout (/home/runner/work/react-native-template/react-native-template/app/scenes/RootScreen/saga.js:9:20) at listOnTimeout (node:internal/timers:569:17) at processTimers (node:internal/timers:512:7) Error: expect(jest.fn()).toHaveBeenCalled() Expected number of calls: >= 1 Received number of calls: 0 at call (/home/runner/work/react-native-template/react-native-template/app/scenes/RootScreen/tests/saga.test.js:33:23) at tryCatch (/home/runner/work/react-native-template/react-native-template/node_modules/regenerator-runtime/runtime.js:63:40) at Generator._invoke (/home/runner/work/react-native-template/react-native-template/node_modules/regenerator-runtime/runtime.js:293:22) at Generator.call (/home/runner/work/react-native-template/react-native-template/node_modules/regenerator-runtime/runtime.js:118:21) at tryCatch (/home/runner/work/react-native-template/react-native-template/node_modules/regenerator-runtime/runtime.js:63:40) at invoke (/home/runner/work/react-native-template/react-native-template/node_modules/regenerator-runtime/runtime.js:154:20) at fn (/home/runner/work/react-native-template/react-native-template/node_modules/regenerator-runtime/runtime.js:164:13) at tryCallOne (/home/runner/work/react-native-template/react-native-template/node_modules/react-native/node_modules/promise/lib/core.js:37:12) at call (/home/runner/work/react-native-template/react-native-template/node_modules/react-native/node_modules/promise/lib/core.js:123:15) at flush (/home/runner/work/react-native-template/react-native-template/node_modules/asap/raw.js:50:29)
const method = startup();
NavigationService.navigateAndReset = submitSpy;
setTopLevelNavigator({ dispatch: submitSpy });
method.next();
await timeout(1000);
await timeout(2000);
expect(submitSpy).toHaveBeenCalled();
});

it('should ensure that the navigation service is called after waiting for 1000ms', async () => {
const method = startup();
NavigationService.navigateAndReset = submitSpy;
setTopLevelNavigator({ dispatch: submitSpy });
method.next();
await timeout(650);
expect(submitSpy).not.toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let navigator;
/**
* This function is called when the RootScreen is created to set the navigator instance to use.
*/
function setTopLevelNavigator(navigatorRef) {
export function setTopLevelNavigator(navigatorRef) {
navigator = navigatorRef;
}

Expand All @@ -21,7 +21,7 @@ function setTopLevelNavigator(navigatorRef) {
* @param routeName The name of the route to navigate to. Routes are defined in RootScreen using createStackNavigator()
* @param params Route parameters.
*/
function navigate(routeName, params) {
export function navigate(routeName, params) {

Check warning on line 24 in app/services/navigationService.js

View workflow job for this annotation

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

🕹 Function is not covered

Warning! Not covered function
navigator.dispatch(
NavigationActions.navigate({
routeName,
Expand All @@ -39,17 +39,11 @@ function navigate(routeName, params) {
* @param routeName The name of the route to navigate to. Routes are defined in RootScreen using createStackNavigator()
* @param params Route parameters.
*/
function navigateAndReset(routeName, params) {
export function navigateAndReset(routeName, params) {
navigator.dispatch(
StackActions.replace({
routeName,
params
})
);
}

export default {
navigate,
navigateAndReset,
setTopLevelNavigator
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerRootComponent } from 'expo';

import App from './App';

// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
4 changes: 4 additions & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

module.exports = getDefaultConfig(__dirname);

0 comments on commit 451b0fe

Please sign in to comment.