diff --git a/src/App.js b/src/App.js index 3e53b295e39830c29ca6374549ff0e6182758de2..fdc4270fcbb337f71d1ff06471019d504d6be49c 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 0000000000000000000000000000000000000000..744ec6363685848ca9b2305f924ed102ef6b5420 --- /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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/__tests__/App-test.js b/src/__tests__/App-test.js index 81885a3766615c074ec9f2e8496beb68af6a9c32..79c4721138f1ec19a2b1b602a773699cfb9b03c3 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 0000000000000000000000000000000000000000..2a52498cac4316899884e347f2a45ef6faa88568 --- /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