Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Placeholder into develop #49

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lvlgg_frontend/__mocks__/axios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// __mocks__/axios.js
export default {
post: jest.fn()
};

5 changes: 5 additions & 0 deletions lvlgg_frontend/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
};


21,105 changes: 12,361 additions & 8,744 deletions lvlgg_frontend/package-lock.json

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions lvlgg_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,22 @@
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.16.0",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/preset-env": "^7.17.0",
"@babel/preset-react": "^7.16.7",
"@babel/preset-env": "^7.23.9",
"@babel/preset-react": "^7.23.3",
"@testing-library/react": "^14.2.1",
"babel-jest": "^27.4.6",
"babel-jest": "^27.5.1",
"file-loader": "^6.2.0",
"jest": "^27.5.1",
"jest": "^29.7.0",
"nth-check": ">=2.0.1",
"react-test-renderer": "^18.2.0"
},
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"moduleNameMapper": {
"^axios$": "<rootDir>/__mocks__/axios.js"
}

}
}
2 changes: 1 addition & 1 deletion lvlgg_frontend/src/Components/ExplorePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './ExplorePage.css'
function ExplorePage() {
return (
<div className='explore-container'>
<video src="/videos/video-6.mp4" autoPlay loop muted />
<video data-testid="video-element" src="/videos/video-6.mp4" autoPlay loop muted />
</div>
)
}
Expand Down
6 changes: 4 additions & 2 deletions lvlgg_frontend/src/Components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const closeDropdown = () => {
};

const handleSignOut = () => {
//localStorage.removeItem('token');
setIsSignedIn(false);
closeDropdown();
};

return (
<>
<nav className='navbar'>
<div className='navbar-container'>
<div data-testid="Navbar-1" className='navbar-container'>
<Link to="/" className="navbar-logo">
LVLUP <i className="fa-solid fa-arrow-up"></i>
</Link>
Expand Down Expand Up @@ -60,7 +62,7 @@ const handleSignOut = () => {
</button>
{isDropdownOpen && (
<div className="dropdown-content">
<button onClick={() => { handleSignOut(); closeDropdown(); }}>Sign Out</button>
<button onClick={() => { handleSignOut(); }}>Sign Out</button>
</div>
)}
</div>
Expand Down
20 changes: 13 additions & 7 deletions lvlgg_frontend/src/Components/Pages/SignIn.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState } from "react";
import React, {useContext, useState} from 'react';
import { Link, useHistory } from "react-router-dom";
import axios from "axios";
import { AuthContext } from '../../Contexts/AuthContext'

const SignIn = () => {
const {setIsSignedIn} = useContext(AuthContext);
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const history = useHistory();
Expand All @@ -15,16 +17,20 @@ const SignIn = () => {
username,
password,
})
.then((response) => {
.then(response => {
if (response.status === 200) {
console.log("Account created successfully:", response.data);
history.push("/");
console.log('Successful login:', response.data);
setIsSignedIn(true);
history.push('/')
} else {
console.error("Unexpected response status:", response.status);
console.error('Unexpected response status:', response.status);
}
})
.catch((error) => {
console.error("Error:", error);
.catch(error => {
if (error.response.status === 401) {
console.error('error:', error.response.data);
alert(JSON.stringify(error.response.data));
}
});
};

Expand Down
8 changes: 6 additions & 2 deletions lvlgg_frontend/src/Components/Pages/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ const SignUp = () => {
.then(response => {
if (response.status === 200) {
console.log('Account created successfully:', response.data);
history.push('/')
alert('account created successfully');
history.push('/signin')
} else {
console.error('Unexpected response status:', response.status);
}

// Redirect or perform other actions upon successful account creation
})
.catch(error => {
console.error('Error:', error);
if (error.response && error.response.status === 400) {
console.error('error:', error.response.data);
alert(JSON.stringify(error.response.data));
}
});
};

Expand Down
27 changes: 27 additions & 0 deletions lvlgg_frontend/src/Components/__tests__/Button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { BrowserRouter as Router } from 'react-router-dom'
import { MemoryRouter } from 'react-router-dom';
import { Button } from '../../Components/Button.js';

test('renders button component', () => {
const { getByText } = render(
<MemoryRouter>
<Button>Click me</Button>
</MemoryRouter>
);
const buttonElement = getByText('Click me');
expect(buttonElement).toBeInTheDocument();
});

test('renders button component with correct style and size', () => {
const { container } = render(
<Router>
<Button buttonStyle="btn--primary" buttonSize="btn--medium">Click me</Button>
</Router>
);
const buttonElement = container.querySelector('button');
expect(buttonElement).toHaveClass('btn');
expect(buttonElement).toHaveClass('btn--primary');
});
21 changes: 21 additions & 0 deletions lvlgg_frontend/src/Components/__tests__/ExplorePage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect'; // import the extend-expect library
import ExplorePage from '../../Components/ExplorePage.js';

test('renders ExplorePage component', () => {
const { getByTestId } = render(<ExplorePage />);
const videoElement = getByTestId('video-element');
expect(videoElement).toBeInTheDocument();
});


test('renders video element with correct attributes', () => {
const { getByTestId } = render(<ExplorePage />);
const videoElement = getByTestId('video-element');
expect(videoElement).toBeInTheDocument();
expect(videoElement).toHaveAttribute('src', '/videos/video-6.mp4');
expect(videoElement).toHaveAttribute('autoplay');
expect(videoElement).toHaveAttribute('loop');
});

3 changes: 0 additions & 3 deletions lvlgg_frontend/src/Components/__tests__/NavBar.test.js

This file was deleted.

36 changes: 36 additions & 0 deletions lvlgg_frontend/src/Components/__tests__/SignIn.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { BrowserRouter as Router } from 'react-router-dom';
import SignIn from '../../Components/Pages/SignIn';
import axios from 'axios';
import { AuthProvider } from '../../Contexts/AuthContext';

jest.mock('axios');

test('allows user to sign in', async () => {
render(
<Router> {/* Wrap your component tree with Router */}
<AuthProvider>
<SignIn />
</AuthProvider>
</Router>
);
const usernameInput = screen.getByLabelText('Username:');
const passwordInput = screen.getByLabelText('Password:');
const button = screen.getByText('Sign In');

fireEvent.change(usernameInput, { target: { value: 'testuser' } });
fireEvent.change(passwordInput, { target: { value: 'testpassword' } });

axios.post.mockResolvedValueOnce({ status: 200, data: { message: 'Successful login' } });

fireEvent.click(button);

await waitFor(() => {
expect(axios.post).toHaveBeenCalledWith('http://localhost:8000/account/signin/', {
username: 'testuser',
password: 'testpassword',
});
});
});
54 changes: 54 additions & 0 deletions lvlgg_frontend/src/Components/__tests__/SignUp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import SignUp from '../../Components/Pages/SignUp.js';
import axios from 'axios';

jest.mock('axios');

test('renders SignUp component', () => {
render(<SignUp />);
const usernameInput = screen.getByLabelText('Username:');
const emailInput = screen.getByLabelText('Email:');
const passwordInput = screen.getByLabelText('Password:');
const firstNameInput = screen.getByLabelText('First:');
const lastNameInput = screen.getByLabelText('Last:');
const button = screen.getByText('Create Account');

expect(usernameInput).toBeInTheDocument();
expect(emailInput).toBeInTheDocument();
expect(passwordInput).toBeInTheDocument();
expect(firstNameInput).toBeInTheDocument();
expect(lastNameInput).toBeInTheDocument();
expect(button).toBeInTheDocument();
});

test('allows user to sign up', async () => {
render(<SignUp />);
const usernameInput = screen.getByLabelText('Username:');
const emailInput = screen.getByLabelText('Email:');
const passwordInput = screen.getByLabelText('Password:');
const firstNameInput = screen.getByLabelText('First:');
const lastNameInput = screen.getByLabelText('Last:');
const button = screen.getByText('Create Account');

fireEvent.change(usernameInput, { target: { value: 'testuser' } });
fireEvent.change(emailInput, { target: { value: 'test@example.com' } });
fireEvent.change(passwordInput, { target: { value: 'testpassword' } });
fireEvent.change(firstNameInput, { target: { value: 'Test' } });
fireEvent.change(lastNameInput, { target: { value: 'User' } });

axios.post.mockResolvedValueOnce({ status: 200, data: { message: 'Account created successfully' } });

fireEvent.click(button);

await waitFor(() => {
expect(axios.post).toHaveBeenCalledWith('http://localhost:8000/account/signup/', {
username: 'testuser',
email: 'test@example.com',
password: 'testpassword',
firstname: 'Test',
lastname: 'User'
});
});
});
13 changes: 0 additions & 13 deletions lvlgg_frontend/src/reportWebVitals.js

This file was deleted.

Loading