-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
12,525 additions
and
8,756 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// __mocks__/axios.js | ||
export default { | ||
post: jest.fn() | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
presets: ['@babel/preset-env', '@babel/preset-react'], | ||
}; | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
lvlgg_frontend/src/Components/__tests__/ExplorePage.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}); | ||
}); | ||
}); |