Skip to content

Commit

Permalink
ft(a user should be able to book an accommodation facility):
Browse files Browse the repository at this point in the history
- designed a UI which is based on the reuasble pop up component that is already in the code base
- connected the UI component to the redux store,
- validate the data entered by the user using HTML5 validations
- send data to backend using an asyncronous function
- display all accommodations by a user
[Finishes #169258604]
  • Loading branch information
hezzie committed Feb 5, 2020
1 parent 30e76f0 commit eb5ba06
Show file tree
Hide file tree
Showing 24 changed files with 990 additions and 127 deletions.
12 changes: 9 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dotenv.config();

axios.defaults.BASE_URL = process.env.BASE_URL;


const App = () => (
<Provider store={store}>
<Router>
Expand Down Expand Up @@ -87,13 +86,20 @@ const App = () => (
/>
<Route path="/trips/oneway" exact component={OneWayTrip} />
<Route path="/trips/approval" exact component={ApprovalRequests} />
<Route path="/trips/approval/:tripRequestId" exact component={SingleRequest} />
<Route
path="/trips/approval/:tripRequestId"
exact
component={SingleRequest}
/>
<Route path="/trips/multicity" exact component={MulticityTrip} />
<Route
path="/admin/roles"
exact
render={() => (checkPrevilege(1) ? (
<UserRolesView />) : (<Redirect to="/Dashboard" />))}
<UserRolesView />
) : (
<Redirect to="/Dashboard" />
))}
/>
<Route path="/accommodations" exact component={ViewAccomodation} />
<Route component={Notfound} />
Expand Down
7 changes: 7 additions & 0 deletions src/__mocks__/accommodation/viewAccommodation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const viewAccommodationProps = {

allLikesDislakes: [
{
likeCounter: 1,
Expand Down Expand Up @@ -121,6 +122,12 @@ export const viewAccommodationProps = {
],
viewActionAccommodation: jest.fn(),
accommodation: {
display: {
deleteComment: 'none',
editTrip: 'none',
currentPopUp: 'editTrip',
bookAccommodation: 'none',
},
allAccomodation: [
{
id: 45,
Expand Down
70 changes: 68 additions & 2 deletions src/__mocks__/trips/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,77 @@ export const entities = [
],
];
export const init = {
allAccomodation: {
accommodations: [
{
id: 46,
userId: 15,
name: 'Victor Palace',
cityId: 5,
address: 'Lagos',
description: ' Queens palace is the best accomodation facility you could ever get',
googleCoordinates: '-77, -56',
accommodationRooms: [
{
id: 90,
accommodationId: 46,
name: '12',
roomType: 'single',
},
{
id: 91,
accommodationId: 46,
name: '13',
roomType: 'single',
},
{
id: 92,
accommodationId: 46,
name: '14',
roomType: 'single',
},
],
imagesAccommodation: [
{
id: 63,
accommodationId: 46,
imageUrl: 'https://images.unsplash.com/photo-1549638441-b787d2e11f14?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80',
},
],
city: {
id: 2,
city: 'Kigali',
},
ratings: [
{
id: 28,
userId: 153,
accommodationId: 46,
rating: '5',
review: 'It has wifi issue',
},
],
}],
},
bookings: {
bookAccommodation: {
bookAccommodationInput: {
destination: 'Kigali',
accommodationId: 45,
roomType: 'single',
roomId: 23,
checkOutDate: '2020-12-11',
checkInDate: '2022-12-11',
tripId: 21,
},
},
},
search: {
key: '',
payload: [],
},
popUpsDisplay: {
bookAccommodation: 'none',
deleteComment: 'none',
editTrip: 'none',
currentPopUp: 'editTrip',
Expand Down Expand Up @@ -78,8 +144,8 @@ export const init = {
{
id: 6,
tripRequestId: 5,
originId: 1,
destinationId: 2,
originId: 'Nairobi',
destinationId: 'Kigali',
reason: 'kimjong',
startDate: '2029-12-23',
returnDate: null,
Expand Down
100 changes: 100 additions & 0 deletions src/__tests__/actions/bookings/bookAccommodationActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import moxios from 'moxios';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import {
updateBookAccommodationInput,
bookAccommodationAction,
} from '../../../redux/actions/bookings/bookAnAccommodation';
import {
BOOK_ACCOMMODATION_SUCCESS,
BOOK_ACCOMMODATION_ERROR,
UPDATE_INPUT,
} from '../../../redux/actionTypes/bookingActionTypes';
import apiCall from '../../../helpers/apiCall';
import {
errorTypeResponse,
errorResponse,
errorRequest,
} from '../../../__mocks__/auth/authMock';

let store;
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

describe('Signup Tests ', () => {
beforeEach(() => {
moxios.install(apiCall);
});

afterEach(() => {
moxios.uninstall(apiCall);
});

it('it Should dispatch book accommodation Errror', async () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 400,
response: {
message: 'first name should be valid',
},
});
});

store = mockStore({});
const { dispatch } = store;
await dispatch(bookAccommodationAction({ tripId: 90 })).then(async () => {
const calledActions = store.getActions();

expect(calledActions).toEqual([
{
type: 'BOOK_ACCOMMODATION_ERROR',
payload: {
message: 'first name should be valid',
},
},
]);
});
});
it('it Should dispatch book accommodation success', async () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 200,
response: {
message: 'first name should be valid',
},
});
});

store = mockStore({});
const { dispatch } = store;
await dispatch(bookAccommodationAction({ tripId: 90 })).then(async () => {
const calledActions = store.getActions();

expect(calledActions).toEqual([
{
type: 'BOOK_ACCOMMODATION_SUCCESS',
payload: {
message: 'first name should be valid',
},
},
]);
});
});
it('it Should dispatchupdate inputs success', async () => {
store = mockStore({});
const { dispatch } = store;
dispatch(updateBookAccommodationInput({ paginationEnd: 5, paginationStart: 0 }));
const calledActions = store.getActions();
expect(calledActions).toEqual([
{
payload: {
paginationEnd: 5,
paginationStart: 0,
},
type: UPDATE_INPUT,
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe('Expect to mock accommodation state', () => {
const component = shallow(<ViewAccomodationView {...viewAccommodationProps} />);
it('Should simulate on change paginate by arrow function', () => {
const addButton = component.find('button').at(0);
const showBookingPopUp = component.find('#showBookingPopUp');
showBookingPopUp.simulate('click');
addButton.simulate('click');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Common Single Request page it Should dispatch reject button successfully 1`] = `ReactWrapper {}`;

exports[`Common Single Request page it Should dispatch reject button successfully 2`] = `ReactWrapper {}`;
72 changes: 72 additions & 0 deletions src/__tests__/containers/bookings/bookAccommodation.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import dotenv from 'dotenv';
import { mount, shallow } from 'enzyme';
import configureStore from 'redux-mock-store';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import BookAccommodation from '../../../views/accommodation/BookAccommodation';
import initialState from '../../../redux/store/initialState';
import {
init,
} from '../../../__mocks__/trips/requests';
import 'jest-localstorage-mock';

dotenv.config();
const mockStore = configureStore([]);
let wrapper;
let store;

describe('Common Single Request page ', () => {
it('it Should dispatch reject button successfully', async () => {
store = mockStore(init);
localStorage.setItem('token', process.env.TESTING_TOKEN);

wrapper = mount(
<Provider store={store}>
<Router>
<BookAccommodation />
</Router>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
const SelectTrip = wrapper.find('#SelectTrip');
const selectRoomType = wrapper.find('#selectRoomType');
const selectRoomName = wrapper.find('#selectRoomName');
const checkInDate = wrapper.find('#checkInDate');
const checkOutDate = wrapper.find('#checkOutDate');
const save = wrapper.find('#save');
const cancel = wrapper.find('#cancel');
SelectTrip.simulate('change');
selectRoomType.simulate('change');
selectRoomName.simulate('change');
checkOutDate.simulate('change');
checkInDate.simulate('change');
save.simulate('click');
cancel.simulate('click');
expect(jest.fn().mock.calls).toBeDefined();
});
it('it Should dispatch reject button successfully', async () => {
store = mockStore({
popUpsDisplay: {
bookAccommodation: 'none',
deleteComment: 'none',
editTrip: 'none',
currentPopUp: 'editTrip',
},
viewProfile: { profile: '' },
trips: { requests: { requestsData: [] }, tripRequests: { getCity: [] } },
allAccomodation: { accommodations: [] },
bookings: { bookAccommodation: { bookAccommodationInput: {} } },
});
localStorage.setItem('token', process.env.TESTING_TOKEN);

wrapper = mount(
<Provider store={store}>
<Router>
<BookAccommodation />
</Router>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
48 changes: 48 additions & 0 deletions src/__tests__/reducers/bookings/bookAccommodation.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import bookAccommodationReducer from '../../../redux/reducers/bookings/bookAccommodationReducer';
import initialState from '../../../redux/store/initialState';
import {
signupSuccessAction, signupInputAction, signupErrorAction, spinnerStatusAction,
} from '../../../__mocks__/auth/authMock';


describe('Book accommodation test', () => {
it('Should handle booking success', () => {
const newState = bookAccommodationReducer({}, {
type: 'BOOK_ACCOMMODATION_SUCCESS',
payload: {
message: 'Updated your password successful',
},
});
expect(newState).toEqual({
bookAccommodationData: {
message: 'Updated your password successful',
},
});
});
it('Should handle booking error', () => {
const newState = bookAccommodationReducer({}, {
type: 'BOOK_ACCOMMODATION_ERROR',
payload: {
message: 'Updated your password successful',
},
});
expect(newState).toEqual({
bookAccommodationError: {
message: 'Updated your password successful',
},
});
});
it('Should handle updating accommodation input', () => {
const newState = bookAccommodationReducer({}, {
type: 'UPDATE_INPUT',
payload: {
message: 'Updated your password successful',
},
});
expect(newState).toEqual({
bookAccommodationInput: {
message: 'Updated your password successful',
},
});
});
});
1 change: 1 addition & 0 deletions src/__tests__/reducers/popUp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Pop up tests ', () => {
payload: 2,
});
expect(newState).toEqual({
bookAccommodation: 'none',
currentPopUp: 'editTrip',
deleteComment: 'none',
editTrip: 'none',
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/views/trips/CommonSingleRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ describe('Common Single Request page ', () => {
it('it Should dispatch reject button successfully', async () => {
store = mockStore(init);
localStorage.setItem('token', process.env.TESTING_TOKEN);
console.log('{{{{}}}}{{{{{{', init.trips.tripRequests.getCity);

wrapper = mount(
<Provider store={store}>
Expand Down
Loading

0 comments on commit eb5ba06

Please sign in to comment.