-
-
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.
Merge pull request #25 from Pushkarm029/tests
[DRAFT] Frontend Tests implemented using JEST
- Loading branch information
Showing
9 changed files
with
3,771 additions
and
4,488 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.github/workflows/run-tests.yml → .github/workflows/run-frontend-tests.yml
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Run Test | ||
name: Running React Frontend Tests | ||
|
||
on: | ||
push: | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,4 @@ | ||
import '@testing-library/jest-dom' | ||
// import * as React from 'react' | ||
// import {render, fireEvent, screen} from '@testing-library/react' | ||
// import Login from '../components/auth/LoginAccountForm' | ||
|
||
// jest.mock('../firebase') | ||
|
||
// // const fakeUserResponse = {token: 'fake_user_token'} | ||
// // const server = setupServer( | ||
// // rest.post('/api/login', (req, res, ctx) => { | ||
// // return res(ctx.json(fakeUserResponse)) | ||
// // }), | ||
// // ) | ||
test('login test', () => { | ||
expect(true).toBe(true); | ||
}) | ||
|
||
|
||
|
||
// // beforeAll(() => server.listen()) | ||
// // afterEach(() => { | ||
// // server.resetHandlers() | ||
// // // window.localStorage.removeItem('token') | ||
// // }) | ||
// // afterAll(() => server.close()) | ||
|
||
|
||
// const username = 'demo'; | ||
// const password = 'demo1234'; | ||
|
||
// test('Login Test', async () => { | ||
// render(<Login />) | ||
// // fireEvent.change(screen.getByLabelText(/username/i), { | ||
// // target: {value: 'chuck'}, | ||
// // }) | ||
// // fireEvent.change(screen.getByLabelText(/password/i), { | ||
// // target: {value: 'norris'}, | ||
// // }) | ||
// const emailField = getByTestId('email'); | ||
// const passField = getByTestId('password'); | ||
// fireEvent.change(emailField, { target: { value: 'Hello, Jest!' } }); | ||
// fireEvent.change(passField, { target: { value: 'Hello, Jest!' } }); | ||
|
||
// expect(emailField.value).toBe('Hello, Jest!'); | ||
// expect(passField.value).toBe('Hello, Jest!'); | ||
|
||
|
||
// // fireEvent.click(screen.getByText(/submit/i)) | ||
// // const alert = await screen.findByRole('alert') | ||
// // expect(alert).toHaveTextContent(/congrats/i) | ||
// // expect(window.localStorage.getItem('token')).toEqual(fakeUserResponse.token) | ||
// }) | ||
|
||
// // test('handles server exceptions', async () => { | ||
// // // mock the server error response for this test suite only. | ||
// // server.use( | ||
// // rest.post('/api/login', (req, res, ctx) => { | ||
// // return res(ctx.status(500), ctx.json({message: 'Internal server error'})) | ||
// // }), | ||
// // ) | ||
|
||
// // render(<Login />) | ||
|
||
// // // fill out the form | ||
// // fireEvent.change(screen.getByLabelText(/username/i), { | ||
// // target: {value: 'chuck'}, | ||
// // }) | ||
// // fireEvent.change(screen.getByLabelText(/password/i), { | ||
// // target: {value: 'norris'}, | ||
// // }) | ||
|
||
// // fireEvent.click(screen.getByText(/submit/i)) | ||
|
||
// // // wait for the error message | ||
// // const alert = await screen.findByRole('alert') | ||
|
||
// // expect(alert).toHaveTextContent(/internal server error/i) | ||
// // expect(window.localStorage.getItem('token')).toBeNull() | ||
// // }) |
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,68 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import SearchPage from '../overlay/search/App'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import fetchMock from 'fetch-mock'; | ||
jest.setTimeout(20000) | ||
|
||
const mockAPIdata = [[ | ||
"kd", | ||
"0", | ||
"KD", | ||
"https://images.unsplash.com/photo-1691860305089-9a2566296202?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=385&q=80", | ||
"kd@gmail.com" | ||
], | ||
[ | ||
"test", | ||
"10001", | ||
"testingname", | ||
"https://images.unsplash.com/photo-1682314170732-2de75372c338?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHx0b3BpYy1mZWVkfDExOHx4SHhZVE1ITGdPY3x8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60", | ||
"test@insta.in" | ||
] | ||
] | ||
|
||
test('renders the SearchPage component', () => { | ||
render(<SearchPage />, { wrapper: BrowserRouter }); | ||
}); | ||
|
||
test('displays "No search results yet." with no input', () => { | ||
const { getByText } = render(<SearchPage />, { wrapper: BrowserRouter }); | ||
const noResultsMessage = getByText('No search results yet.'); | ||
expect(noResultsMessage).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays search results for a valid input', async () => { | ||
fetchMock.mock('/api/search/users', () => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
status: 200, | ||
body: mockAPIdata, | ||
}); | ||
}, 5000); | ||
}); | ||
}); | ||
const { getByTestId, getByPlaceholderText, getByText } = render(<SearchPage />, { wrapper: BrowserRouter }); | ||
const searchInput = getByPlaceholderText('Type to search...'); | ||
fireEvent.change(searchInput, { target: { value: 'kd' } }); | ||
await waitForElementToBeRemoved(() => screen.getByText("kd is currently not available on this platform"), { timeout: 10000 }); | ||
const searchResults = getByTestId("search-results"); | ||
expect(searchResults).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays a "not available" message when there are no results', () => { | ||
const { getByTestId, getByPlaceholderText, getByText } = render(<SearchPage />, { wrapper: BrowserRouter }); | ||
const searchInput = getByPlaceholderText('Type to search...'); | ||
fireEvent.change(searchInput, { target: { value: 'NonExistentUser' } }); | ||
const notAvailableMessage = getByText('NonExistentUser is currently not available on this platform'); | ||
expect(notAvailableMessage).toBeInTheDocument(); | ||
}); | ||
|
||
test('navigates to the profile page when a search result is clicked', async () => { | ||
const { getByTestId, getByPlaceholderText } = render(<SearchPage />, { wrapper: BrowserRouter }); | ||
const searchInput = getByPlaceholderText('Type to search...'); | ||
fireEvent.change(searchInput, { target: { value: 'kd' } }); | ||
await waitForElementToBeRemoved(() => screen.getByText("kd is currently not available on this platform"), { timeout: 10000 }); | ||
const searchResult = getByTestId("search-box-result"); | ||
fireEvent.click(searchResult); | ||
}); |
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
// const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
// module.exports = function (app) { | ||
// const target = process.env.API_PROXY_TARGET || 'http://localhost:8080'; // Default to localhost:8080 if the env variable is not set | ||
|
||
// app.use( | ||
// '/api', | ||
// createProxyMiddleware({ | ||
// target, | ||
// changeOrigin: true, | ||
// // secure: false, | ||
// }) | ||
// ); | ||
// }; | ||
|
||
const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
module.exports = function (app) { | ||
const target = process.env.API_PROXY_TARGET || 'http://localhost:8080'; // Default to localhost:8080 if the env variable is not set | ||
|
||
app.use( | ||
'/api', | ||
createProxyMiddleware({ | ||
target: 'http://localhost:8080', | ||
target, | ||
changeOrigin: true, | ||
// secure: false, | ||
}) | ||
); | ||
}; | ||
}; | ||
|
||
// const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
// module.exports = function (app) { | ||
// app.use( | ||
// '/api', | ||
// createProxyMiddleware({ | ||
// target: 'http://localhost:8080', | ||
// changeOrigin: true, | ||
// }) | ||
// ); | ||
// }; |