From 6ce28402d297e7f09b8affe43a6ac5eff00843c9 Mon Sep 17 00:00:00 2001 From: HenryShan <zshan2@illinois.edu> Date: Tue, 30 Mar 2021 08:11:57 +0800 Subject: [PATCH] assignment3.0 ver3: all snapshot tests deployed, going for navigation test --- src/App.js | 271 ++++---------------------------------- src/Components/Loading.js | 2 +- src/Components/Profile.js | 4 +- src/Components/Repo.js | 4 +- src/Components/Unfound.js | 2 - src/package.json | 7 +- 6 files changed, 36 insertions(+), 254 deletions(-) diff --git a/src/App.js b/src/App.js index 32ca65a..b9549e1 100644 --- a/src/App.js +++ b/src/App.js @@ -7,7 +7,14 @@ import Profile from './Components/Profile' import Repo from './Components/Repo' import Unfound from './Components/Unfound' import Users from './Components/Users' -import DataGenerator from './Components/DataGenerator' +import LoadFollowingScreenModule from './Components/LoadFollowingScreenModule' +import LoadFollowersScreenModule from './Components/LoadFollowersScreenModule' +import LoadProfileScreenModule from './Components/LoadProfileScreenModule' +import LoadRepoScreenModule from './Components/LoadRepoScreenModule' +import Follower from './Components/Followers' +import Following from './Components/Following' + + const Stack = createStackNavigator(); const styles = StyleSheet.create({ @@ -35,9 +42,9 @@ function generateData(route, navigation) { dataFile['repoCount'] = 'Repository count: ' + repositories['nodes'].length var iconUrl if (avatarUrl != null) { - iconUrl = { uri: avatarUrl } + iconUrl = avatarUrl } else { - iconUrl = require('C:/Coding/cs242-assignment3/GitView/assets/default.png') + iconUrl = "https://png.pngtree.com/element_our/20200610/ourlarge/pngtree-cat-default-avatar-image_2246581.jpg" } dataFile['iconUrl'] = iconUrl return dataFile @@ -102,86 +109,13 @@ function RepoScreen({ route, navigation }) { /** Follower page **/ function FollowerScreen({ route, navigation }) { const user = route.params - const nodes = user['followers']['nodes'] - const login = user['login'] - let cards = [] - if (nodes.length === 0) { - cards.push( - <Pressable style={styles.textBox} key={'Nobody'}> - <Text style={{ fontSize: 30 }}> - Oops! Nobody is in this list! - </Text> - </Pressable> - ) - } else { - for (let i = 0; i < nodes.length; i++) { - var name = 'Name: \n' + nodes[i]['name'] + '\n' - var userName = 'Github Username: \n' + nodes[i]['login'] + '\n' - var key = 'user#' + i - var avatarUrl = nodes[i]['avatarUrl'] - cards.push( - <Pressable style={styles.textBox} key={key} onPress={()=>navigation.push('LoadingProfile', {login: nodes[i]['login']})}> - <View style={styles.viewStyleVertical}> - <Image style={{width:90, height:90}} source={{uri: avatarUrl}}/> - </View> - <View style={styles.viewStyleVertical}> - <Text> {name} </Text> - <Text> {userName} </Text> - </View> - </Pressable> - ) - } - } - const dataFile = {} - dataFile['cards'] = cards - dataFile['navi'] = navigation - dataFile['login'] = login - console.log(login) - return ( - <Users data={dataFile}/> - ); + return Follower(user, navigation) } /** Following page **/ function FollowingScreen({ route, navigation }) { const user = route.params - const nodes = user['following']['nodes'] - const login = user['login'] - let cards = [] - if (nodes.length === 0) { - cards.push( - <Pressable style={styles.textBox} key={'Nobody'}> - <Text style={{ fontSize: 30 }}> - Oops! Nobody is in this list! - </Text> - </Pressable> - ) - } else { - for (let i = 0; i < nodes.length; i++) { - var name = 'Name: \n' + nodes[i]['name'] + '\n' - var userName = 'Github Username: \n' + nodes[i]['login'] + '\n' - var key = 'user#' + i - var avatarUrl = nodes[i]['avatarUrl'] - cards.push( - <Pressable style={styles.textBox} key={key} onPress={()=>navigation.push('LoadingProfile', {login: nodes[i]['login']})}> - <View style={styles.viewStyleVertical}> - <Image style={{width:90, height:90}} source={{uri: avatarUrl}}/> - </View> - <View style={styles.viewStyleVertical}> - <Text> {name} </Text> - <Text> {userName} </Text> - </View> - </Pressable> - ) - } - } - const dataFile = {} - dataFile['cards'] = cards - dataFile['navi'] = navigation - dataFile['login'] = login - return ( - <Users data={dataFile}/> - ); + return Following(user, navigation) } /** Unfound page **/ @@ -201,48 +135,9 @@ function UnfoundScreen({ route, navigation }) { function LoadProfileScreen({route, navigation}) { const dataJson = require('C:/Coding/cs242-assignment3/env.json') const {login} = route.params - fetch(dataJson['endPoint'], { - method: 'POST', - headers: { - "Content-Type": "application/json", - "Authorization": dataJson['token'] - }, - body: JSON.stringify({ - query: ` - query { - user(login:"`+ login + `") { - name - login - avatarUrl - bio - createdAt - email - websiteUrl - repositories(last:100, privacy:PUBLIC){ - nodes{ - name - } - } - } - } - ` - }) - }) - .then(res => res.json()) - .then((data)=> { - if (data['data']['user'] === null) { - /** User not found! **/ - navigation.push('Unfound', {errorMsg: 'Wrong!'}) - console.log('Error, cannot find the github user by the login username:' + login + ', maybe this is an organization!') - } else { - navigation.push('Profile', data['data']['user']) - } - }) - .catch(error => { - console.error('Error:', error) - navigation.push('Unfound', {errorMsg: error}) - }) - + const endPoint = dataJson['endPoint'] + const token = dataJson['token'] + LoadProfileScreenModule(login, endPoint, token, navigation) return ( <Loading/> ); @@ -250,48 +145,11 @@ function LoadProfileScreen({route, navigation}) { /** Loading Repo page **/ function LoadRepoScreen({route, navigation}) { + const dataJson = require('C:/Coding/cs242-assignment3/env.json') const {login} = route.params - const dataJson = require('C:/Coding/cs242-assignment3/env.json'); - fetch(dataJson['endPoint'], { - method: 'POST', - headers: { - "Content-Type": "application/json", - "Authorization": dataJson['token'] - }, - body: JSON.stringify({ - query: ` - query { - user(login:"`+login+`"){ - login - repositories(last:100, privacy:PUBLIC){ - nodes{ - name - owner{ - login - } - description - } - } - } - } - ` - }) - }) - .then(res => res.json()) - .then((data)=> { - if (data['data']['user'] === null) { - /** User not found! **/ - navigation.push('Unfound', {errorMsg: 'Wrong!'}) - console.log('Error, cannot find the github user by the login username:' + login + ', maybe this is an organization!') - } else { - navigation.push('Repo', data['data']['user']) - } - }) - .catch(error => { - console.error('Error:', error) - navigation.push('Unfound', {errorMsg: error}) - }) - + const endPoint = dataJson['endPoint'] + const token = dataJson['token'] + LoadRepoScreenModule(login, endPoint, token, navigation) return ( <Loading/> ); @@ -301,94 +159,21 @@ function LoadRepoScreen({route, navigation}) { function LoadFollowersScreen({route, navigation}) { const {login} = route.params const dataJson = require('C:/Coding/cs242-assignment3/env.json'); - fetch(dataJson['endPoint'], { - method: 'POST', - headers: { - "Content-Type": "application/json", - "Authorization": dataJson['token'] - }, - body: JSON.stringify({ - query: ` - query { - user(login:"`+ login +`"){ - login - followers(last:100) { - nodes { - name - login - avatarUrl - } - } - } - } - ` - }) - }) - .then(res => res.json()) - .then((data)=> { - if (data['data']['user'] === null) { - /** User not found! **/ - navigation.push('Unfound', {errorMsg: 'Wrong!'}) - console.log('Error, cannot find the github user by the login username:' + login + ', maybe this is an organization!') - } else { - navigation.push('Followers', data['data']['user']) - } - }) - .catch(error => { - console.error('Error:', error) - navigation.push('Unfound', {errorMsg: error}) - }) - - return ( - <Loading/> - ); + const endPoint = dataJson['endPoint'] + const token = dataJson['token'] + /** Call function in module part to fetch data and send to view part */ + return LoadFollowersScreenModule(login, endPoint, token, navigation) } /** Loading Followings page **/ function LoadFollowingScreen({route, navigation}) { const {login} = route.params const dataJson = require('C:/Coding/cs242-assignment3/env.json'); - fetch(dataJson['endPoint'], { - method: 'POST', - headers: { - "Content-Type": "application/json", - "Authorization": dataJson['token'] - }, - body: JSON.stringify({ - query: ` - query { - user(login:"` + login + `"){ - login - following(last:100) { - nodes { - name - login - avatarUrl - } - } - } - } - ` - }) - }) - .then(res => res.json()) - .then((data)=> { - if (data['data']['user'] === null) { - /** User not found! **/ - navigation.push('Unfound', {errorMsg: 'Wrong!'}) - console.log('Error, cannot find the github user by the login username:' + login + ', maybe this is an organization!') - } else { - navigation.push('Following', data['data']['user']) - } - }) - .catch(error => { - console.error('Error:', error) - navigation.push('Unfound', {errorMsg: error}) - }) - - return ( - <Loading/> - ); + const endPoint = dataJson['endPoint'] + const token = dataJson['token'] + /** Call function in module part to fetch data and send to view part */ + return LoadFollowingScreenModule(login, endPoint, token, navigation) + } diff --git a/src/Components/Loading.js b/src/Components/Loading.js index 694ff72..0bc32a3 100644 --- a/src/Components/Loading.js +++ b/src/Components/Loading.js @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Pressable, View, Text, Image, StyleSheet, ImageBackground } from 'react-native'; +import { View, Text, Image, StyleSheet, ImageBackground } from 'react-native'; const styles = StyleSheet.create({ viewStyleVertical : { alignItems: 'center', justifyContent: 'center', margin: '10%' }, diff --git a/src/Components/Profile.js b/src/Components/Profile.js index 2856a2d..ea75c83 100644 --- a/src/Components/Profile.js +++ b/src/Components/Profile.js @@ -1,8 +1,6 @@ import * as React from 'react'; import { Pressable, View, Text, Image, StyleSheet, ImageBackground } from 'react-native'; -import { createStackNavigator } from '@react-navigation/stack'; -const Stack = createStackNavigator(); const styles = StyleSheet.create({ viewStyleVertical : { alignItems: 'center', justifyContent: 'center', margin: '10%' }, viewStyleHorizon : { flex: 1, flexDirection: 'row', justifyContent: 'space-between'}, @@ -31,7 +29,7 @@ const Profile = (props) => { <ImageBackground source={{uri: "https://www.fonewalls.com/wp-content/uploads/2020/04/Ice-Phone-Wallpaper.jpg"}} style={styles.image}> <View style={styles.viewStyleVertical}> <View style={styles.viewStyleVertical}> - <Image style={{width: 100, height: 100}} source={{uri: iconUrl}} /> + <Image style={{width: 120, height: 120}} source={{uri: iconUrl}}/> </View> <View style={styles.viewStyleHorizon}> <Pressable style={styles.pressableStyle} onPress={() => navigation.push('LoadingFollowers', {login: login})}> diff --git a/src/Components/Repo.js b/src/Components/Repo.js index 811276f..67038d8 100644 --- a/src/Components/Repo.js +++ b/src/Components/Repo.js @@ -1,8 +1,7 @@ import * as React from 'react'; import { Pressable, View, Text, Image, StyleSheet, ImageBackground } from 'react-native'; -import { createStackNavigator } from '@react-navigation/stack'; -const Stack = createStackNavigator(); + const styles = StyleSheet.create({ viewStyleVertical : { alignItems: 'center', justifyContent: 'center', margin: '10%' }, viewStyleHorizon : { flex: 1, flexDirection: 'row', justifyContent: 'space-between'}, @@ -18,7 +17,6 @@ const Repo = (props) => { const file = props.data const cards = file['cards'] const navigation = file['navi'] - const login = file['login'] return ( <View style={styles.container}> <ImageBackground source={{uri: "https://www.fonewalls.com/wp-content/uploads/2020/04/Ice-Phone-Wallpaper.jpg"}} style={styles.image}> diff --git a/src/Components/Unfound.js b/src/Components/Unfound.js index 6b3772a..7098417 100644 --- a/src/Components/Unfound.js +++ b/src/Components/Unfound.js @@ -1,8 +1,6 @@ import * as React from 'react'; import { Pressable, View, Text, Image, StyleSheet, ImageBackground } from 'react-native'; -import { createStackNavigator } from '@react-navigation/stack'; -const Stack = createStackNavigator(); const styles = StyleSheet.create({ viewStyleVertical : { alignItems: 'center', justifyContent: 'center', margin: '10%' }, viewStyleHorizon : { flex: 1, flexDirection: 'row', justifyContent: 'space-between'}, diff --git a/src/package.json b/src/package.json index 87fc242..9273acf 100644 --- a/src/package.json +++ b/src/package.json @@ -9,9 +9,10 @@ "test": "jest" }, "jest": { - "preset": "react-native", + "preset": "jest-expo", + "automock": false, "setupFiles": [ - "./node_modules/react-native-gesture-handler/jestSetup.js" + "./setupJest.js" ], "moduleNameMapper": { "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js", @@ -24,6 +25,8 @@ "@react-navigation/stack": "^5.14.3", "expo": "~40.0.0", "expo-status-bar": "~1.0.3", + "jest-expo": "^40.0.2", + "jest-fetch-mock": "^3.0.3", "react": "16.13.1", "react-dom": "16.13.1", "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz", -- GitLab