-
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 #13 from tan12082001/component-tests
Add Test suites for components using Jest
- Loading branch information
Showing
18 changed files
with
15,538 additions
and
9,621 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import AddNewCarForm from '../pages/UserDashboard/AddNewCar/AddNewCarForm'; | ||
import store from '../redux/store'; | ||
|
||
describe('AddNewCarForm Component', () => { | ||
it('renders AddNewCarForm', () => { | ||
const component = render( | ||
<React.StrictMode> | ||
<Provider store={store}> | ||
<BrowserRouter> | ||
<AddNewCarForm /> | ||
</BrowserRouter> | ||
</Provider> | ||
</React.StrictMode>, | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
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,53 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import Router from '../routes/routes'; | ||
import { USERS_DASHBOARD } from '../routes/routeConstants'; | ||
|
||
const mockStore = configureMockStore(); | ||
|
||
describe('DashboardHome Component', () => { | ||
it('renders cars present', () => { | ||
const store = mockStore({ | ||
authentication: { | ||
authenticatedUser: { | ||
username: 'testuser', | ||
}, | ||
status: 'succeeded', | ||
}, | ||
cars: { | ||
cars: [ | ||
{ | ||
id: 1, | ||
name: 'Test Vehicle', | ||
description: 'Test Description', | ||
pricePerHr: 20, | ||
seating_capacity: 4, | ||
image: 'test_image.png', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Vehicle two', | ||
descrrption: 'Vehicle two Description', | ||
pricePerHr: 10, | ||
seating_capacity: 6, | ||
image: 'test_image.png', | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const { container } = render( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={[`${USERS_DASHBOARD}`]}> | ||
<Router /> | ||
</MemoryRouter> | ||
</Provider>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
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,48 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import DeleteList from '../components/DeleteCars/DeleteList'; | ||
|
||
const mockStore = configureMockStore(); | ||
|
||
describe('DeleteList Component', () => { | ||
it('renders cars present to delete', () => { | ||
const store = mockStore({ | ||
authentication: { | ||
authenticatedUser: { | ||
username: 'testuser', | ||
}, | ||
status: 'succeeded', | ||
}, | ||
cars: { | ||
cars: [ | ||
{ | ||
id: 1, | ||
name: 'Test Vehicle', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Vehicle two', | ||
}, | ||
{ | ||
id: 3, | ||
name: 'Vehicle three', | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const { container } = render( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<DeleteList /> | ||
</MemoryRouter> | ||
</Provider>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
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,57 @@ | ||
import '@testing-library/jest-dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { Provider } from 'react-redux'; | ||
import Router from '../routes/routes'; | ||
import { USERS_DASHBOARD } from '../routes/routeConstants'; | ||
|
||
const mockStore = configureMockStore(); | ||
|
||
describe('ItemDetail Page', () => { | ||
it('renders ItemDetail page for car ID 1', async () => { | ||
const store = mockStore({ | ||
authentication: { | ||
authenticatedUser: { | ||
username: 'testuser', | ||
}, | ||
status: 'succeeded', | ||
}, | ||
cars: { | ||
cars: [ | ||
{ | ||
id: 1, | ||
name: 'Test Vehicle', | ||
description: 'Test Description', | ||
pricePerHr: 20, | ||
seating_capacity: 4, | ||
image: 'test_image.png', | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Vehicle two', | ||
description: 'Vehicle two Description', | ||
pricePerHr: 10, | ||
seating_capacity: 6, | ||
image: 'test_image.png', | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
render( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={[`${USERS_DASHBOARD}`]}> | ||
<Router /> | ||
</MemoryRouter> | ||
</Provider>, | ||
); | ||
|
||
userEvent.click(screen.getByTestId('each-item-container-link-1')); | ||
await waitFor(() => { | ||
expect(screen.getByText('Test Vehicle')).toBeInTheDocument(); | ||
expect(screen.getByText('Test Description')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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,44 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import MyReservations from '../pages/LandingPage/MyReservation/MyReservation'; | ||
|
||
const mockStore = configureMockStore(); | ||
|
||
describe('MyReservations Component', () => { | ||
it('renders reservations present', () => { | ||
const store = mockStore({ | ||
authentication: { | ||
authenticatedUser: { | ||
username: 'testuser', | ||
}, | ||
status: 'succeeded', | ||
}, | ||
reservation: { | ||
reservations: [ | ||
{ | ||
date: '2023-10-10', | ||
city: 'City A', | ||
}, | ||
{ | ||
date: '2022-11-11', | ||
city: 'City B', | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const { container } = render( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<MyReservations /> | ||
</MemoryRouter> | ||
</Provider>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
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,35 @@ | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import ReserveCarFrom from '../components/ReserveCars/ReserveCarForm'; | ||
|
||
const mockStore = configureMockStore(); | ||
|
||
describe('ReserveCarForm Component', () => { | ||
it('renders ReserveCarForm correctly', () => { | ||
const store = mockStore({ | ||
reservation: { | ||
status: 'idle', | ||
}, | ||
}); | ||
|
||
render( | ||
<Provider store={store}> | ||
<MemoryRouter> | ||
<ReserveCarFrom id={1} username="testuser" name="Test Car" /> | ||
</MemoryRouter> | ||
</Provider>, | ||
); | ||
|
||
expect(screen.getByText('Username')).toBeInTheDocument(); | ||
expect(screen.getByText('Car Name')).toBeInTheDocument(); | ||
expect(screen.getByText('Select Date')).toBeInTheDocument(); | ||
expect(screen.getByText('Select City')).toBeInTheDocument(); | ||
expect(screen.getByText('Book Now')).toBeInTheDocument(); | ||
expect(screen.getByDisplayValue('testuser')).toBeInTheDocument(); | ||
expect(screen.getByDisplayValue('Test Car')).toBeInTheDocument(); | ||
}); | ||
}); |
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,22 @@ | ||
import '@testing-library/jest-dom/'; | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { render } from '@testing-library/react'; | ||
import store from '../redux/store'; | ||
import SignIn from '../pages/Auth/SignIn/SignIn'; | ||
|
||
describe('Login component', () => { | ||
test('should render login page', () => { | ||
const component = render( | ||
<React.StrictMode> | ||
<Provider store={store}> | ||
<Router> | ||
<SignIn /> | ||
</Router> | ||
</Provider> | ||
</React.StrictMode>, | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
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,22 @@ | ||
import '@testing-library/jest-dom/'; | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { render } from '@testing-library/react'; | ||
import store from '../redux/store'; | ||
import SignUp from '../pages/Auth/SignUp/SignUp'; | ||
|
||
describe('SignUp component', () => { | ||
test('should render SignUp page', () => { | ||
const component = render( | ||
<React.StrictMode> | ||
<Provider store={store}> | ||
<Router> | ||
<SignUp /> | ||
</Router> | ||
</Provider> | ||
</React.StrictMode>, | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.