Skip to content
This repository was archived by the owner on Jan 8, 2021. It is now read-only.

Commit b13309d

Browse files
author
andela-akhenda
committed
feat(auth): create homepage screen
1 parent 44588ef commit b13309d

File tree

8 files changed

+119
-9
lines changed

8 files changed

+119
-9
lines changed

__tests__/unit/src/Child.spec.js renamed to __tests__/unit/src/components/Child.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { shallow } from 'enzyme';
44
import renderer from 'react-test-renderer';
55

6-
import Child from 'src/Child';
6+
import Child from 'src/components/Child';
77
import * as Utils from 'src/utils/capitalize';
88

99

__tests__/unit/src/__snapshots__/Child.spec.js.snap renamed to __tests__/unit/src/components/__snapshots__/Child.spec.js.snap

File renamed without changes.

__tests__/unit/src/App.spec.js renamed to __tests__/unit/src/containers/HomeScreen.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import React from 'react';
33
import { shallow } from 'enzyme';
44
import renderer from 'react-test-renderer';
55

6-
import App from 'src/App';
7-
import Child from 'src/Child';
6+
import HomeScreen from 'src/containers/HomeScreen';
7+
import Child from 'src/components/Child';
88

99

10-
describe('App', () => {
10+
describe('HomeScreen', () => {
1111
let component;
1212
let textInput;
1313
const defaultState = { text: '' };
1414

1515
test('renders correctly', () => {
16-
const tree = renderer.create(<App />).toJSON();
16+
const tree = renderer.create(<HomeScreen />).toJSON();
1717
expect(tree).toMatchSnapshot();
1818
});
1919

2020
beforeEach(() => {
21-
component = shallow(<App />);
21+
component = shallow(<HomeScreen />);
2222
textInput = component.find('TextInput');
2323
});
2424

__tests__/unit/src/__snapshots__/App.spec.js.snap renamed to __tests__/unit/src/containers/__snapshots__/HomeScreen.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`App renders correctly 1`] = `
3+
exports[`HomeScreen renders correctly 1`] = `
44
<View
55
style={
66
Object {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@
136136
"collectCoverage": true,
137137
"preset": "react-native",
138138
"testRegex": "/__tests__/unit/.*\\.spec\\.js$",
139-
"setupTestFrameworkScriptFile": "./__tests__/unit/setup.js"
139+
"setupTestFrameworkScriptFile": "./__tests__/unit/setup.js",
140+
"transformIgnorePatterns": ["node_modules/(?!react-native|native-base|react-navigation|mobx-react)"]
140141
},
141142
"detox": {
142143
"test-runner": "jest",

src/Child.js renamed to src/components/Child.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
44

5-
import { capitalizeWords } from './utils/capitalize';
5+
import { capitalizeWords } from 'src/utils/capitalize';
66

77
export default class Child extends Component {
88
getCapitalizedText() {

src/containers/HomeScreen.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Platform, Text, View, TextInput } from 'react-native';
4+
import { connect } from 'react-redux';
5+
6+
import Child from 'src/components/Child';
7+
import LoadingIndicator from 'src/components/LoadingIndicator';
8+
import { getUserInfo } from 'src/state/actions/auth';
9+
import styles from './styles/HomeScreenStyles';
10+
11+
const instructions = Platform.select({
12+
ios: 'Press Cmd+R to reload,\n' +
13+
'Cmd+D or shake for dev menu',
14+
android: 'Double tap R on your keyboard to reload,\n' +
15+
'Shake or press menu button for dev menu',
16+
});
17+
18+
class HomeScreen extends Component {
19+
constructor(props) {
20+
super(props);
21+
22+
this.state = { text: '' };
23+
}
24+
25+
setText(text) {
26+
this.setState({ text });
27+
}
28+
29+
handleTextChange(text) {
30+
this.setText(text);
31+
}
32+
33+
clearText() {
34+
this.setText('');
35+
}
36+
37+
render() {
38+
const { user } = this.props;
39+
const { text } = this.state;
40+
41+
if (user === null) return <LoadingIndicator />;
42+
43+
return (
44+
<View testID='Welcome' style={styles.container}>
45+
<Text testID='WelcomeTitle' style={styles.welcome}>
46+
Welcome to React Native!
47+
</Text>
48+
<Text testID='WelcomeInstruction' style={styles.instructions}>
49+
To get started, edit App.js
50+
</Text>
51+
<Text testID='Instructions' style={styles.instructions}>
52+
{instructions}
53+
</Text>
54+
<TextInput
55+
value={text}
56+
testID='TextInput'
57+
style={styles.input}
58+
placeholder={'Write something...'}
59+
onChangeText={txt => this.handleTextChange(txt)}
60+
/>
61+
<Child text={text} onClear={() => this.clearText()} />
62+
</View>
63+
);
64+
}
65+
}
66+
67+
HomeScreen.propTypes = {
68+
user: PropTypes.object,
69+
token: PropTypes.string,
70+
getUserInfo: PropTypes.func,
71+
};
72+
73+
const mapStateToProps = (state) => {
74+
return {
75+
user: state.auth.user,
76+
token: state.auth.token,
77+
};
78+
};
79+
80+
export default connect(mapStateToProps, { getUserInfo })(HomeScreen);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { StyleSheet } from 'react-native';
2+
3+
const styles = StyleSheet.create({
4+
container: {
5+
flex: 1,
6+
justifyContent: 'center',
7+
alignItems: 'center',
8+
backgroundColor: '#F5FCFF',
9+
},
10+
welcome: {
11+
fontSize: 20,
12+
textAlign: 'center',
13+
margin: 10,
14+
},
15+
instructions: {
16+
textAlign: 'center',
17+
color: '#333333',
18+
marginBottom: 5,
19+
},
20+
input: {
21+
width: '80%',
22+
height: 60,
23+
padding: 10,
24+
marginTop: 30,
25+
alignSelf: 'center',
26+
},
27+
});
28+
29+
export default styles;

0 commit comments

Comments
 (0)