From dbea22c951967c52ff4a770e6873843c5050856a Mon Sep 17 00:00:00 2001 From: HenryShan <zshan2@illinois.edu> Date: Tue, 23 Mar 2021 12:58:06 +0800 Subject: [PATCH] final commit --- src/App.js | 42 +++++++++++++---------- src/Components/DataGenerator.js | 23 +++++++++++++ src/Tests/UnitTest.js | 0 src/__tests__/App-test.js | 61 ++++++++++++++++++++++++++------- src/__tests__/UnitTest.js | 14 ++++++++ 5 files changed, 110 insertions(+), 30 deletions(-) create mode 100644 src/Components/DataGenerator.js delete mode 100644 src/Tests/UnitTest.js create mode 100644 src/__tests__/UnitTest.js diff --git a/src/App.js b/src/App.js index 3e53b29..fdc4270 100644 --- a/src/App.js +++ b/src/App.js @@ -6,6 +6,7 @@ import Loading from './Components/Loading' import Profile from './Components/Profile' import Repo from './Components/Repo' import Unfound from './Components/Unfound' +import DataGenerator from './Components/DataGenerator' const Stack = createStackNavigator(); const styles = StyleSheet.create({ @@ -19,23 +20,7 @@ const styles = StyleSheet.create({ marginHorizontal: 10, paddingVertical:10, paddingHorizontal: 50, alignItems: 'flex-start'} }); -/** Home page **/ -function HomeScreen({ navigation }) { - return ( - <View style={styles.container}> - <ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}> - <View style={styles.viewStyleVertical}> - <Pressable style={styles.pressableStyle} onPress={() => navigation.navigate('LoadingProfile')}> - <Text> Start </Text> - </Pressable> - </View> - </ImageBackground> - </View> - ); -} - -/** Profile page **/ -function ProfileScreen({ route, navigation }) { +function generateData(route, navigation) { const {name, login, avatarUrl, bio, createdAt, email, websiteUrl, repositories} = route.params; const dataFile = {} dataFile['navi'] = navigation @@ -46,7 +31,6 @@ function ProfileScreen({ route, navigation }) { dataFile['emailContent'] = 'Email: \n' + email dataFile['websiteLink'] = 'Website: \n' + websiteUrl dataFile['repoCount'] = 'Repository count: ' + repositories['nodes'].length - console.log(avatarUrl) var iconUrl if (avatarUrl != null) { iconUrl = { uri: avatarUrl } @@ -54,6 +38,28 @@ function ProfileScreen({ route, navigation }) { iconUrl = require('C:/Coding/cs242-assignment3/GitView/assets/default.png') } dataFile['iconUrl'] = iconUrl + return dataFile +} + + +/** Home page **/ +function HomeScreen({ navigation }) { + return ( + <View style={styles.container}> + <ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}> + <View style={styles.viewStyleVertical}> + <Pressable style={styles.pressableStyle} onPress={() => navigation.navigate('LoadingProfile')}> + <Text> Start </Text> + </Pressable> + </View> + </ImageBackground> + </View> + ); +} + +/** Profile page **/ +function ProfileScreen({ route, navigation }) { + var dataFile = generateData(route, navigation) return ( <Profile data={dataFile}/> ); diff --git a/src/Components/DataGenerator.js b/src/Components/DataGenerator.js new file mode 100644 index 0000000..744ec63 --- /dev/null +++ b/src/Components/DataGenerator.js @@ -0,0 +1,23 @@ + +function generateData(route, navigation) { + const {name, login, avatarUrl, bio, createdAt, email, websiteUrl, repositories} = route.params; + const dataFile = {} + dataFile['navi'] = navigation + dataFile['nameContent'] = 'Name: \n' + name + dataFile['userNameContent'] = 'UserName\n: ' + login + dataFile['bioContent'] = 'Bio: \n' + bio + dataFile['createDate'] = 'Create at: \n' + createdAt + dataFile['emailContent'] = 'Email: \n' + email + dataFile['websiteLink'] = 'Website: \n' + websiteUrl + dataFile['repoCount'] = 'Repository count: ' + repositories['nodes'].length + var iconUrl + if (avatarUrl != null) { + iconUrl = { uri: avatarUrl } + } else { + iconUrl = require('C:/Coding/cs242-assignment3/GitView/assets/default.png') + } + dataFile['iconUrl'] = iconUrl + return dataFile + } + +module.exports = generateData; \ No newline at end of file diff --git a/src/Tests/UnitTest.js b/src/Tests/UnitTest.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/__tests__/App-test.js b/src/__tests__/App-test.js index 81885a3..79c4721 100644 --- a/src/__tests__/App-test.js +++ b/src/__tests__/App-test.js @@ -6,23 +6,60 @@ import renderer from 'react-test-renderer'; import Loading from '../Components/Loading'; import Repo from '../Components/Repo'; import { createStackNavigator } from '@react-navigation/stack'; +import { NavigationContainer } from '@react-navigation/native'; +import Unfound from '../Components/Unfound'; const Stack = createStackNavigator(); -test('renders correctly', ({}) => { - // const dataFile = { - // iconUrl: "https://avatars.githubusercontent.com/u/42978932?u=b4a7beb2752bb6059cd13d12ca26d097767abf77&v=4", - // nameContent: null, - // userNameContent: null, - // bioContent: null, - // websiteLink: null, - // emailContent: null, - // createData: null, - // repoCount: 0, - // navigation: navigation - // } +test('renders correctly', () => { const tree = renderer.create( <Loading /> ).toJSON(); expect(tree).toMatchSnapshot(); + }); + + test('renders correctly', ({navigation}) => { + const dataFile = { + iconUrl: "https://avatars.githubusercontent.com/u/42978932?u=b4a7beb2752bb6059cd13d12ca26d097767abf77&v=4", + nameContent: null, + userNameContent: null, + bioContent: null, + websiteLink: null, + emailContent: null, + createData: null, + repoCount: 0, + navi: navigation + } + const tree = renderer.create( + <Profile data={dataFile}/> + ).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + test('renders correctly', ({navigation}) => { + const dataFile = { + iconUrl: "https://avatars.githubusercontent.com/u/42978932?u=b4a7beb2752bb6059cd13d12ca26d097767abf77&v=4", + nameContent: null, + userNameContent: null, + bioContent: null, + websiteLink: null, + emailContent: null, + createData: null, + repoCount: 0, + navi: navigation + } + const tree = renderer.create( + <Repo data={dataFile}/> + ).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + test('renders correctly', ({navigation}) => { + const dataFile = { + navi: navigation + } + const tree = renderer.create( + <Unfound data={dataFile}/> + ).toJSON(); + expect(tree).toMatchSnapshot(); }); \ No newline at end of file diff --git a/src/__tests__/UnitTest.js b/src/__tests__/UnitTest.js new file mode 100644 index 0000000..2a52498 --- /dev/null +++ b/src/__tests__/UnitTest.js @@ -0,0 +1,14 @@ +import 'react-native'; +import React from 'react'; +import Profile from '../Components/Profile'; +import App from '../App' +import renderer from 'react-test-renderer'; +import Loading from '../Components/Loading'; +import Repo from '../Components/Repo'; +import { createStackNavigator } from '@react-navigation/stack'; +import { NavigationContainer } from '@react-navigation/native'; +import Unfound from '../Components/Unfound'; + +const Stack = createStackNavigator(); + +const generateData = require() \ No newline at end of file -- GitLab