Skip to content

Commit 34b9f5f

Browse files
committed
Fix fetch sideeffect of test libs, clean react browser libs
1 parent 506bbea commit 34b9f5f

File tree

6 files changed

+1153
-77
lines changed

6 files changed

+1153
-77
lines changed

.babelrc

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"presets": ["babel-preset-expo"],
3-
"env": {
4-
"development": {
5-
"plugins": ["transform-react-jsx-source"]
6-
}
7-
}
2+
"presets": ["babel-preset-expo"],
3+
"env": {
4+
"development": {
5+
"plugins": ["transform-react-jsx-source"]
6+
}
7+
}
88
}

package.json

+20-10
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,27 @@
1111
"react-navigation": "^1.5.9"
1212
},
1313
"scripts": {
14-
"start": "exp start -c --lan"
14+
"start": "exp start -c --lan",
15+
"test": "node_modules/.bin/jest"
16+
},
17+
"jest": {
18+
"preset": "jest-expo"
1519
},
1620
"devDependencies": {
17-
"babel-eslint": "^8.2.2",
18-
"eslint": "^4.19.1",
19-
"eslint-config-airbnb": "^16.1.0",
20-
"eslint-config-prettier": "^2.9.0",
21-
"eslint-plugin-import": "^2.9.0",
22-
"eslint-plugin-jsx-a11y": "^6.0.3",
23-
"eslint-plugin-prettier": "^2.6.0",
24-
"eslint-plugin-react": "^7.7.0",
25-
"prettier": "1.11.1"
21+
"babel-core": "^6.26.0",
22+
"babel-eslint": "^8.2.2",
23+
"babel-jest": "^22.4.3",
24+
"babel-preset-env": "^1.6.1",
25+
"babel-preset-react-native": "^4.0.0",
26+
"eslint": "^4.19.1",
27+
"eslint-config-airbnb": "^16.1.0",
28+
"eslint-config-prettier": "^2.9.0",
29+
"eslint-plugin-import": "^2.9.0",
30+
"eslint-plugin-jsx-a11y": "^6.0.3",
31+
"eslint-plugin-prettier": "^2.6.0",
32+
"eslint-plugin-react": "^7.7.0",
33+
"jest-expo": "^26.0.0",
34+
"prettier": "1.11.1",
35+
"regenerator-runtime": "^0.11.1"
2636
}
2737
}

src/__tests__/utils.test.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as utils from '../utils';
2+
3+
const inputMapping = {
4+
DataSearch: {
5+
screen: 'DefaultScreen',
6+
DataSearch_withTitle: {
7+
screen: 'DataSearch_withTitle',
8+
},
9+
DataSearch_withIcon: {
10+
screen: 'DataSearch_withIcon',
11+
},
12+
},
13+
TextField: {
14+
screen: 'DefaultScreen',
15+
TextField_withTitle: {
16+
screen: 'TextField_withTitle',
17+
},
18+
TextField_withIcon: {
19+
screen: 'TextField_withIcon',
20+
},
21+
},
22+
};
23+
24+
const outputOne = {
25+
DataSearch: { screen: 'DefaultScreen' },
26+
TextField: { screen: 'DefaultScreen' },
27+
};
28+
29+
const outputTwo = {
30+
DataSearch_withTitle: { screen: 'DataSearch_withTitle' },
31+
DataSearch_withIcon: { screen: 'DataSearch_withIcon' },
32+
TextField_withTitle: { screen: 'TextField_withTitle' },
33+
TextField_withIcon: { screen: 'TextField_withIcon' },
34+
};
35+
36+
const outputThree = {
37+
DataSearch_withTitle: {
38+
screen: 'DataSearch_withTitle',
39+
},
40+
DataSearch_withIcon: {
41+
screen: 'DataSearch_withIcon',
42+
},
43+
};
44+
45+
const outputFour = {
46+
TextField_withTitle: {
47+
screen: 'TextField_withTitle',
48+
},
49+
TextField_withIcon: {
50+
screen: 'TextField_withIcon',
51+
},
52+
};
53+
54+
/* eslint no-undef: 0 */
55+
test('Flattens MainDrawer Objects', () => {
56+
expect(utils.flattenMainDrawerObjects(inputMapping)).toEqual(outputOne);
57+
});
58+
59+
test('Flattens ChildDrawer Objects', () => {
60+
expect(utils.flattenChildDrawerObjects(inputMapping)).toEqual(outputTwo);
61+
});
62+
63+
test('Fetches ChildDrawer Options for DataSearch', () => {
64+
expect(utils.getChildDrawerOptions(inputMapping, 'DataSearch')).toEqual(
65+
outputThree
66+
);
67+
});
68+
69+
test('Fetches ChildDrawer Options for TextField', () => {
70+
expect(utils.getChildDrawerOptions(inputMapping, 'TextField')).toEqual(
71+
outputFour
72+
);
73+
});

src/drawers/MainDrawer.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DrawerItem from '../components/DrawerItem';
55
import ChildDrawer from './ChildDrawer';
66
import DrawerContainer from '../components/DrawerContainer';
77
import DrawerHeader from '../components/DrawerHeader';
8+
import screenMapping from './../screenMapping';
89

910
class MainDrawer extends Component {
1011
constructor(props) {
@@ -50,7 +51,10 @@ class MainDrawer extends Component {
5051
);
5152
}
5253

53-
const childDrawerItems = getChildDrawerOptions(currentComponent.key);
54+
const childDrawerItems = getChildDrawerOptions(
55+
screenMapping,
56+
currentComponent.key
57+
);
5458

5559
return (
5660
<ChildDrawer

src/utils.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import screenMapping from './screenMapping';
2-
31
/* Used in RootDrawer to register for each component individually
42
Flatten the screen mapping in form of:
53
{
@@ -56,7 +54,7 @@ export const flattenChildDrawerObjects = nestedObject => {
5654
}
5755
}
5856
*/
59-
export const getChildDrawerOptions = componentId => {
57+
export const getChildDrawerOptions = (screenMapping, componentId) => {
6058
const { screen, ...drawerOptions } = screenMapping[componentId];
6159
return drawerOptions;
6260
};

0 commit comments

Comments
 (0)