diff --git a/mobile/App.js b/mobile/App.js index 7c1f665..fad93d7 100644 --- a/mobile/App.js +++ b/mobile/App.js @@ -23,13 +23,12 @@ import JoinedWeek from './components/JoinedWeek'; import JoinedExercise from './components/JoinedExercise'; import JoinedProgramDetail from './components/JoinedProgramDetail'; import JoinedProgramCard from './components/JoinedProgramCard'; -import Survey from './components/Survey' +import Survey from './components/Survey'; import FeedbackCard from './components/FeedbackCard'; import FeedbackDetail from './components/FeedbackDetail'; import CreateFeedback from './components/CreateFeedback'; import SearchPage from './components/SearchPage'; - import { Provider as ReduxProvider } from 'react-redux'; import { QueryClient, @@ -95,10 +94,9 @@ const App = () => { - - + diff --git a/mobile/__tests__/App.test.js b/mobile/__tests__/App.test.js index 789d27a..b954974 100644 --- a/mobile/__tests__/App.test.js +++ b/mobile/__tests__/App.test.js @@ -8,30 +8,57 @@ import App from '../App'; // Note: import explicitly to use the types shipped with jest. import {it} from '@jest/globals'; +import jestConfig from '../jest.config'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; +import apiInstance from '../Api'; -import Login from '../Login' -import Register from '../Register'; -import SearchResult from '../SearchResult' -import CreatePost from '../CreatePost' -import CreateProgram from '../CreateProgram' +import Home from '../components/Home' +import Login from '../components/Login' +import Register from '../components/Register'; +import SearchPage from '../components/SearchPage' +import SearchResults from '../components/SearchResults' +import SearchBar from '../components/SearchBar' +import CreatePost from '../components/CreatePost' +import CreateProgram from '../components/CreateProgram' +import CreateFeedback from '../components/CreateFeedback'; +import Survey from '../components/Survey'; +import Feed from '../components/Feed'; +import JoinedExercise from '../components/JoinedExercise'; +import PostDetail from '../components/PostDetail'; +import FeedbackDetail from '../components/FeedbackDetail'; +import ProfilePage from '../components/ProfilePage'; +import ProgramCard from '../components/ProgramCard'; +import DietCard from '../components/DietCard'; +import ProgramDetail from '../components/ProgramDetail'; +import DietDetail from '../components/DietDetail'; +import UserProfile from '../components/UserProfile'; -it('renders correctly', () => { +/*it('Renders Whole Application Correctly', () => { renderer.create(); -}); +});*/ -const Login = require('../Login'); -const Register = require('../Register'); +test('Renders Home Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); test('Renders Login Page Correctly', () => { - const tree = renderer.create( {}} />).toJSON(); + const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); +test('Logs In Correctly', async () => { + const mockUsername = jest.fn(); + const mockPassword = jest.fn(); + + const response = await apiInstance().post("auth/login", { mockUsername, mockPassword }); + expect(response.status).toBe(200); +}); + test('Renders Register Page Correctly', () => { - const tree = renderer.create( {}} />).toJSON(); + const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); @@ -40,71 +67,270 @@ test('Registers Correctly', async () => { const mockUsername = jest.fn(); const mockPassword = jest.fn(); const mockEmail = jest.fn(); - const mockRole = "Trainee"; + const mockRole = "TRAINEE"; - const response = await apiInstance().post("register", { mockFullName, mockUsername, mockEmail, mockPassword, mockRole }); - expect(response).toBe( /* TODO: The Object That Returns */ ); + const response = await apiInstance().post("auth/register", { mockFullName, mockUsername, mockEmail, mockPassword, mockRole }); + expect(response.status).toBe(201); }); -const SearchResult = require('../SearchResult'); +test('Renders Search Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); -test('Renders Search Result Page Correctly', () => { - const tree = renderer.create( {}} />).toJSON(); +test('Renders Search Results Correctly', () => { + const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); -test('Searches Correctly', async () => { - const mockTitle = jest.fn(); - const mockImage = jest.fn(); - 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(); +test('Renders Search Bar Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); - const response = await apiInstance().post("search", { mockTitle, mockImage, mockExercies, mockName, mockEquipment, mockBodyPart, mockInstruction, mockTargetMuscle, mockSecondaryMuscles }); - expect(response).toBe( /* TODO: The Object That Returns */ ); +test('Gets Exercises Correctly', async () => { + const response = await apiInstance().get("api/exercises"); + expect(response).not.toBeNull(); }); -const CreatePost = require('../CreatePost'); +test('Searches for a Query Correctly', async () => { + const sessionToken = jest.fn(); + const searchQuery = "BACK"; + const titleString = (str) => { + return str.toLowerCase().split(' ').map(word => word.charAt(0).toUpperCase() + word.substring(1)).join(' '); + } + const response = await apiInstance(sessionToken).get(`/api/search`, { + params: { + q: titleString(searchQuery) + } + }); + + expect(response.status).toBe(200); +}); test('Renders Create Post Page Correctly', () => { - const tree = renderer.create( {}} />).toJSON(); + const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); test('Create Post Correctly', async () => { - const mockTitle = jest.fn(); - const mockPost = jest.fn(); - const mockDescription = jest.fn(); - const mockImage = jest.fn(); + const mockContent = jest.fn(); + const mockTrainingProgramId = jest.fn(); const mockLabels = jest.fn(); - const mockLabelTest = jest.fn(); - const mockProfile = jest.fn(); - const mockPassword = jest.fn(); - const mockSessionToken = jest.fn(); + const mockToken = jest.fn(); + //const mockProfile = jest.fn(); - const response = await apiInstance().post("createPost", { mockTitle, mockPost, mockDescription, mockImage, mockLabels, mockLabelTest, mockProfile, mockPassword, mockSessionToken }); - expect(response).toBe( /* TODO: The Object That Returns */ ); + const response = await apiInstance(mockToken).post("api/posts", {mockContent, mockTrainingProgramId, mockLabels }); + expect(response.status).toBe(200); +}); + +test('Delete Post Correctly', async () => { + const postId = jest.fn(); + const mockToken = jest.fn(); + +const response = await apiInstance(mockToken).delete(`api/posts/${postId}`); + expect(response.status).toBe(200); }); -const CreateProgram = require('../CreateProgram'); test('Renders Create Program Page Correctly', () => { - const tree = renderer.create( {}} />).toJSON(); + const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); test('Create Program Correctly', async () => { const mockTitle = jest.fn(); const mockDescription = jest.fn(); - const mockLabels = jest.fn(); - const mockLabelTest = jest.fn(); - const mockExercises = jest.fn(); - const mockExercise = jest.fn(); + const mockType = "BODY_BUILDING"; + const mockLevel = "PROFESSIONAL"; + const mockInterval = jest.fn(); + const mockWeeks = jest.fn(); + + const response = await apiInstance().post("createProgram", { mockTitle, mockDescription, mockType, mockLevel, mockInterval, mockWeeks }); + expect(response.status).toBe(201); +}); + +test('Renders Create Feedback Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Create Feedback Correctly', async() =>{ + const trainingProgram = jest.fn(); + const bodyPart = jest.fn(); + const weekNumber = jest.fn(); + const exerciseNumber = jest.fn(); + const feedbackText = jest.fn(); + + const response = await apiInstance().post("api/feedback", { trainingProgram, bodyPart, weekNumber, exerciseNumber, feedbackText}); + expect(response.status).toBe(201); +}); + +test('Renders Survey Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Survey Correctly', async() =>{ + const fitnessGoals = jest.fn(); + const fitnessLevel = jest.fn(); + + const response = await apiInstance().post("api/surveys", { fitnessGoals, fitnessLevel}); + expect(response.status).toBe(201); +}); + +test('Renders Feed Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Training Programs in Feed Working Correctly', async () => { + const response = await apiInstance().get('api/training-programs'); + expect(response.data).not.toBeNull(); +}); + +test('Training Program Card in Profile Working Correctly', async () => { + const programId = jest.fn(); + const response = await apiInstance().get(`api/training-programs/${programId}`); + expect(response.data).not.toBeNull(); +}); + + + +test('Random Posts in Feed Working Correctly', async () => { + const response = await apiInstance().get('api/posts/random'); + expect(response.data).not.toBeNull(); +}); + +// Joined Exercis +test('Renders Joined Exercise Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Progress Submission in Joined Exercise Correctly', async () => { + const programId = jest.fn(); + const exerciseId = jest.fn(); + const newInputs = jest.fn(); + const mockToken = jest.fn(); + // TODO: This creates mock data, maybe we should change to real values + + const response = await apiInstance(mockToken).post(`/api/training-programs/${programId}/workout-exercises/${exerciseId}/complete`, newInputs); + expect(response.status).toBe(200); +}); + +// Post Detail + +test('Renders Post Detail Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +// Feedback Detail + +test('Renders Feedback Detail Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('User Following Data Works Correctly', async () => { + const ownUsername = jest.fn(); + const mockToken = jest.fn(); + // TODO: This creates mock data, maybe we should change to a real ownUsername + + const response = await apiInstance(mockToken).get(`api/user/${ownUsername}/following`); + expect(response.data).not.toBeNull(); +}); + +test('Follow User Works Correctly', async () => { + const username = "mockusername1111"; + const mockToken = jest.fn(); + // TODO: This creates mock data, maybe we should change to a real ownUsername + +const response = await apiInstance(mockToken).post(`api/user/${username}/follow`, {}) + expect(response.status).toBe(200); +}); + +test('Unfollow User Works Correctly', async () => { + const username = "mockusername1111"; + const mockToken = jest.fn(); + // TODO: This creates mock data, maybe we should change to a real ownUsername + +const response = await apiInstance(mockToken).delete(`api/user/${username}/follow`, {}) + expect(response.status).toBe(200); +}); + +// Profile Page + +test('Renders Profile Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +// Program Card +test('Renders Program Card Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Renders Diet Card Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Renders Diet Detail Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Joined Training Programs Correctly', async () => { + const username = jest.fn(); + // TODO: This creates mock data, maybe we should change to a real username + + const response = await apiInstance().get(`api/training-programs/joined/${username}`); + expect(response.data).not.toBeNull(); +}); + +// Program Detail +test('Renders Program Detail Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('Join Program Correctly', async () => { + const programId = jest.fn(); + const mockToken = jest.fn(); + // TODO: This creates mock data, maybe we should change to a real progam_ID + + const response = await apiInstance(mockToken).post(`api/training-programs/${programId}/join`); + expect(response.status).toBe(200); +}); + +test('Leave Program Correctly', async () => { + const programId = jest.fn(); + const mockToken = jest.fn(); + // TODO: This creates mock data, maybe we should change to a real progam_ID + + const response = await apiInstance(mockToken).delete(`api/training-programs/${programId}/leave`); + expect(response.status).toBe(200); +}); + +test('Rate Program Correctly', async () => { + const programId = 1; + const rating = 3; + const mockToken = jest.fn(); + // TODO: This creates mock data, maybe we should change to a real progam_ID + + const response = await apiInstance(mockToken).post(`api/training-programs/${programId}/rate?rating=${rating}`, { + + }); + expect(response.status).toBe(200); +}); + + +// User Profile +test('Renders User Profile Page Correctly', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); - const response = await apiInstance().post("createProgram", { mockTitle, mockDescription, mockLabels, mockLabelTest, mockExercies, mockExercise }); - expect(response).toBe( /* TODO: The Object That Returns */ ); -}); \ No newline at end of file diff --git a/mobile/components/SearchPage.js b/mobile/components/SearchPage.js index 229c810..d5aae62 100644 --- a/mobile/components/SearchPage.js +++ b/mobile/components/SearchPage.js @@ -125,7 +125,7 @@ const SearchPage = () => { ))} - + {/* Selected Muscle Info */} {selectedMuscle && ( @@ -168,7 +168,6 @@ const SearchPage = () => { {!selectedMuscle && Click on any muscle to see related exercises} - ); }; @@ -263,4 +262,6 @@ flexDirection: 'column' , marginTop: 16, }, }); + export default SearchPage; +