Skip to content

Commit

Permalink
Changes to better support testing
Browse files Browse the repository at this point in the history
In connected components, export the base component (not connected), so
that it can be tested without re-testing connect.

This is possible, because in mapStateToProps, state is accessed via
selectors, which can be tested separately.

Also, in mapDispatchToProps, actions are defined by action creators
that can also be tested separately.

Some discussions on this matter:
reduxjs/react-redux#325 (comment)
reduxjs/redux#1534
https://jsramblings.com/2018/01/15/3-ways-to-test-mapStateToProps-and-mapDispatchToProps.html

Ref #14
  • Loading branch information
jbrodriguez committed Mar 30, 2018
1 parent b65f2ee commit 654e76d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/containers/cities.header.js
Expand Up @@ -15,7 +15,7 @@ type Props = {
settings: () => Dispatch<any>,
}

const HeaderRightBase = ({ gui: { s, c }, search, settings }: Props) => (
export const HeaderRightBase = ({ gui: { s, c }, search, settings }: Props) => (
<View style={[s.flx_row, s.aic]}>
<TouchableOpacity onPress={search}>
<Text style={[s.f2, s.mr2, c.c_secondary]}>+</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.js
@@ -1,6 +1,6 @@
// @flow

import { TTempUnit } from '../typings'
import type { TTempUnit } from '../typings'

const find = /[!'()~]|%20|%00/g
const replace = {
Expand Down
23 changes: 10 additions & 13 deletions src/modules/env.js
Expand Up @@ -2,7 +2,8 @@

import { StyleSheet } from 'react-native'

import { takeLatest, put, select, call } from 'redux-saga/effects'
import type { Saga } from 'redux-saga'
import { takeLatest, put, call } from 'redux-saga/effects'
import { NavigationActions } from 'react-navigation'
import Tachyons from 'react-native-style-tachyons'
import pick from 'lodash.pick'
Expand Down Expand Up @@ -37,7 +38,7 @@ export const setPotentials = (payload: TCity[]): ASetPotentials => ({ type: Acti
Tachyons.build({ rem: 16 }, StyleSheet)

// REDUCER
const initialState: TEnvState = {
export const initialState: TEnvState = {
loaded: false,
version: '1.0.0',
gui: { s: Tachyons.styles, c: colors, z: Tachyons.sizes },
Expand Down Expand Up @@ -97,26 +98,22 @@ export const getPotentials = (state: TAppState): TCity[] => state.env.potentials
export const getVersion = (state: TAppState): string => state.env.version

// SAGAS
const SStart = function* GSStart() {
export const SStart = function* GSStart(): Saga<void> {
// // get binary version info from the device itself ...
// let version = DeviceInfo.getVersion()
// if (codePushUpdateMetadata) {
// // ... but update it from codePush if available
// version = codePushUpdateMetadata.description
// }
const version = '1.0.0'

yield put(setup({ version }))

const loaded = yield select(getLoaded)
if (loaded) {
yield put(
NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Cities' })],
}),
)
}
yield put(
NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Cities' })],
}),
)
}

// This handles the debounced input from the user, when searching for a city name in the Search screen
Expand Down
2 changes: 1 addition & 1 deletion src/modules/settings.js
Expand Up @@ -12,7 +12,7 @@ export const tempUnits = {
metric: { label: 'Celsius', value: 'metric' },
}

const initialState: TSettingsState = {
export const initialState: TSettingsState = {
tempUnit: 'metric',
}

Expand Down

0 comments on commit 654e76d

Please sign in to comment.