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

Unit test1 #42

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
104 changes: 101 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"coverage": "vitest run --coverage"
},
"dependencies": {
"@testing-library/jest-dom": "^6.6.2",
"bootstrap": "^5.3.3",
"bootstrap-icons": "^1.11.3",
"firebase": "^10.14.0",
Expand Down
4 changes: 2 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAuthState } from './utilities/firebase';
import { HashRouter as Router, Routes, Route } from 'react-router-dom';
import { HashRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import 'bootstrap-icons/font/bootstrap-icons.css';
import 'bootstrap/dist/css/bootstrap.min.css';

Expand Down Expand Up @@ -45,7 +45,7 @@ const App = () => {

<Navigationbar />
</>
)}
)}
</div>
</Router>
);
Expand Down
59 changes: 45 additions & 14 deletions src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
import {describe, expect, test} from 'vitest';
import { describe, it, expect, vi, test} from 'vitest';
import {fireEvent, render, screen} from '@testing-library/react';
import { MemoryRouter, Routes, Route } from 'react-router-dom';
import '@testing-library/jest-dom'; // Import jest-dom matchers

import { BrowserRouter as Router } from 'react-router-dom';
import App from './App';
import RequestFormPage from './components/pages/RequestForm';
import HomePage from './components/pages/HomePage';

describe('counter tests', () => {

test("Counter should be 0 at the start", () => {
render(<App />);
expect(screen.getByText('count is: 0')).toBeDefined();
});
describe('RequestFormPage', () => {
test('displays Meet Up textbox when Meet up option is selected', () => {
render(
<Router>
<RequestFormPage />
</Router>
);
const pickUpCheckbox = screen.getByTestId('checkbox-Meet up');
fireEvent.click(pickUpCheckbox);
expect(pickUpCheckbox.checked).toBe(true);
screen.getByLabelText('Meet-up Location:');

test("Counter should increment by one when clicked", async () => {
render(<App />);
const counter = screen.getByRole('button');
fireEvent.click(counter);
expect(await screen.getByText('count is: 1')).toBeDefined();
});
const input = screen.getByPlaceholderText(/Enter location/i)
expect(input).toBeInTheDocument();

})

})

});
describe('send text from home page to request form', () => {
it('should send the text in the textbox to the textbox on the request form', () => {
render(
<MemoryRouter initialEntries={['/']}>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/requestform" element={<RequestFormPage />} />
</Routes>
</MemoryRouter>
);
const input = screen.getByPlaceholderText(/How can your neighbors help?/i);
fireEvent.change(input, { target: { value: 'I need a hammer!' } });

const submitButton = screen.getByText(/Submit/i);
fireEvent.click(submitButton);

expect(screen.getByText(/New Request/i)).toBeInTheDocument();
expect(screen.getByLabelText(/Description/i)).toHaveValue('I need a hammer!');
});

})
4 changes: 3 additions & 1 deletion src/components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,14 @@ const MultiSelect = ({deliveryPref, setDeliveryPref, meetUp, setMeetUpLocation})
label={option}
checked={deliveryPref.includes(option)}
onChange={() => handleSelect(option)} // Handle checkbox change
data-testid={`checkbox-${option}`}
/>
))}
{deliveryPref.includes('Meet up') && (
<Form.Group className="mt-3">
<Form.Label>Meet-up Location:</Form.Label>
<Form.Label htmlFor="meetUpLocation">Meet-up Location:</Form.Label>
<Form.Control
id="meetUpLocation"
type="text"
placeholder="Enter location"
value={meetUp} // Updated to use meetUpLocation
Expand Down