Skip to content

Commit

Permalink
Merge pull request #250 from bounswe/fix-unit-tests-and-programs-in-p…
Browse files Browse the repository at this point in the history
…rofile

Bug fix and updates
  • Loading branch information
erenpakelgil authored Nov 25, 2024
2 parents 0fbb948 + 20337da commit e08a2ef
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 13 deletions.
22 changes: 16 additions & 6 deletions mobile/__tests__/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ test('Renders Search Result Page Correctly', () => {
expect(tree).toMatchSnapshot();
});

test('Searches Correctly', async () => { /* TODO: Change the endpoints */
test('Searches Correctly', async () => {
const mockTitle = jest.fn();
const mockImage = jest.fn();
const mockCreator = jest.fn();
const mockType = jest.fn();

const response = await apiInstance().post("search", { mockTitle, mockImage, mockCreator, mockType });
const mockExercies = jest.fn();
const mockName = jest.fn();
const mockEquipment = jest.fn();
const mockBodyPart = jest.fn();
const mockInstruction = jest.fn();
const mockTargetMuscle = jest.fn();
const mockSecondaryMuscles = jest.fn();

const response = await apiInstance().post("search", { mockTitle, mockImage, mockExercies, mockName, mockEquipment, mockBodyPart, mockInstruction, mockTargetMuscle, mockSecondaryMuscles });
expect(response).toBe( /* TODO: The Object That Returns */ );
});

Expand All @@ -72,11 +77,16 @@ test('Renders Create Post Page Correctly', () => {

test('Create Post Correctly', async () => {
const mockTitle = jest.fn();
const mockPost = jest.fn();
const mockDescription = jest.fn();
const mockImage = jest.fn();
const mockLabels = jest.fn();
const mockLabelTest = jest.fn();
const mockProfile = jest.fn();
const mockPassword = jest.fn();
const mockSessionToken = jest.fn();

const response = await apiInstance().post("createPost", { mockTitle, mockDescription, mockLabels, mockLabelTest });
const response = await apiInstance().post("createPost", { mockTitle, mockPost, mockDescription, mockImage, mockLabels, mockLabelTest, mockProfile, mockPassword, mockSessionToken });
expect(response).toBe( /* TODO: The Object That Returns */ );
});

Expand Down
20 changes: 17 additions & 3 deletions mobile/components/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ useEffect(() => {
const programs = [
{ id: 1, title: "Full Body Workout",
description: "This is a comprehensive program targeting all major muscle groups.",
trainerUsername: "fitness_guru_123",
trainerUsername: "sametalan",
participants:[
"sametalan2",
"Hanaaa",
"deno",
"fit_deniz"
],
createdAt:'2024-11-25T13:52:56.512941',
exercises: [
{ exercise:{
name: "Push-Up",
Expand Down Expand Up @@ -204,7 +211,14 @@ useEffect(() => {
]},
{ id: 2, title: "Full Body Workout",
description: "This is a comprehensive program targeting all major muscle groups.",
trainerUsername: "fitness_guru_123",
trainerUsername: "fit_deniz",
participants:[
"sametalan2",
"Hanaaa",
"deno",
"fit_deniz"
],
createdAt:'2024-11-25T13:52:56.512941',
exercises: [
{ exercise:{
name: "Push-Up",
Expand Down Expand Up @@ -353,7 +367,7 @@ useEffect(() => {
{/* Profile Header */}
<View style={styles.header}>
<Image
source={{ uri: 'https://via.placeholder.com/150' }} // Mock profile image
source={{ uri: 'https://example.com/push-up.gif' }} // Mock profile image
style={styles.profileImage}
/>
<Text style={styles.profileName}>{username}</Text>
Expand Down
2 changes: 1 addition & 1 deletion mobile/components/ProgramCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ProgramCard = ({ trainerUsername, title, description, exercises, date, par
return (
<TouchableOpacity
style={styles.card}
onPress={() => navigation.navigate('ProgramDetail', { trainerUsername, title, description, exercises, navigation })}
onPress={() => navigation.navigate('ProgramDetail', { trainerUsername, title, description, exercises, participants, date, navigation })}
>
<TouchableOpacity onPress={() => navigation.navigate('UserProfile', { username: trainerUsername })}>
<Text style={styles.owner}>{trainerUsername}</Text>
Expand Down
44 changes: 41 additions & 3 deletions mobile/components/ProgramDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'react-native';

const ProgramDetail = ({ route }) => {
const { title, description, trainerUsername, exercises } = route.params;
const { trainerUsername, title, description, exercises, date, participants, navigation } = route.params;
/*const {title, description, trainerUsername, exercises} = {
title: "Full Body Workout",
description: "This is a comprehensive program targeting all major muscle groups.",
Expand Down Expand Up @@ -43,11 +43,19 @@ const ProgramDetail = ({ route }) => {
}
],
}*/
console.log(participants);
const [expandedExercise, setExpandedExercise] = useState(null);

const toggleExerciseDetails = (index) => {
setExpandedExercise(expandedExercise === index ? null : index);
};
const renderParticipant = ({ item, index }) => {
return(
<TouchableOpacity onPress={() => navigation.navigate('UserProfile', { username: item })}>
<Text style={styles.owner}>{item}</Text>
</TouchableOpacity>
);
}

const renderExercise = ({ item, index }) => {
const isExpanded = expandedExercise === index;
Expand Down Expand Up @@ -100,11 +108,21 @@ const ProgramDetail = ({ route }) => {
return (
<ScrollView contentContainerStyle={styles.container}>
<View style={styles.postContainer}>
{/* Program Info */}
{/* Participant Info */}
<Text style={styles.title}>{title}</Text>
<Text style={styles.owner}>{trainerUsername}</Text>
<Text style={styles.description}>{description}</Text>
</View>
<View style={styles.participantsContainer}>
<Text style={styles.participantListTitle}>Participants:</Text>
<FlatList
data={participants}
keyExtractor={(item, index) => index.toString()}
renderItem={renderParticipant}
contentContainerStyle={styles.participantsList}
/>
</View>

{/* Exercises List */}
<View style={styles.exercisesContainer}>
<Text style={styles.exerciseListTitle}>Exercises:</Text>
Expand Down Expand Up @@ -185,7 +203,26 @@ container: {
shadowColor: '#000',
shadowOpacity: 0.1,
shadowRadius: 5,
marginBottom: 20},
marginBottom: 20
},
participantListTitle: {
fontSize: 18,
fontWeight: 'bold',
color: '#333',
marginBottom: 10,
},
participantsList: {
paddingBottom: 20,
},
participantsContainer:{
backgroundColor: '#FFFFFF',
borderRadius: 12,
padding: 15,
shadowColor: '#000',
shadowOpacity: 0.1,
shadowRadius: 5,
marginBottom: 20
},
exerciseContainer: {
backgroundColor: '#f9f9f9',
borderRadius: 10,
Expand All @@ -196,6 +233,7 @@ container: {
shadowRadius: 5,
elevation: 2,
},

exerciseHeader: {
flexDirection: 'row',
justifyContent: 'space-between',
Expand Down

0 comments on commit e08a2ef

Please sign in to comment.