Skip to content

Commit

Permalink
feature(chat): Users should be able to chat on Barefoot Nomad
Browse files Browse the repository at this point in the history
[Start #168049979]
  • Loading branch information
RUGUMBIRA Jordy Bastien authored and RUGUMBIRA Jordy Bastien committed Dec 4, 2019
1 parent 81ff5b2 commit f9e0637
Show file tree
Hide file tree
Showing 30 changed files with 1,078 additions and 188 deletions.
433 changes: 267 additions & 166 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"axios": "^0.19.0",
"draft-js": "^0.11.0",
"draftjs-to-html": "^0.8.4",
"react-draft-wysiwyg": "^1.13.2",
"focus-trap-react": "^6.0.0",
"google-maps-react": "^2.0.2",
"history": "^4.10.1",
Expand All @@ -30,7 +29,9 @@
"prop-types": "^15.7.2",
"query-string": "^6.9.0",
"react": "^16.11.0",
"react-content-loader": "^4.3.2",
"react-dom": "^16.11.0",
"react-draft-wysiwyg": "^1.13.2",
"react-redux": "^7.1.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0",
Expand All @@ -40,8 +41,8 @@
"redux-devtools-extension": "^2.13.8",
"redux-mock-store": "^1.5.3",
"redux-thunk": "^2.3.0",
"socket.io-client": "^2.3.0",
"reselect": "^4.0.0"
"reselect": "^4.0.0",
"socket.io-client": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down Expand Up @@ -84,8 +85,8 @@
]
},
"devDependencies": {
"axios-mock-adapter": "^1.17.0",
"@testing-library/react": "^9.3.2",
"axios-mock-adapter": "^1.17.0",
"coveralls": "^3.0.7",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.15.1",
Expand All @@ -98,6 +99,7 @@
"eslint-plugin-react-hooks": "^1.7.0",
"jest": "^24.9.0",
"jest-enzyme": "^7.1.2",
"jsdom": "^15.2.1",
"moxios": "^0.4.0",
"react-test-renderer": "^16.11.0",
"redux-mock-store": "^1.5.3",
Expand Down
23 changes: 23 additions & 0 deletions src/__mocks__/browserMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const localStorageMock = (function() {
let store = {};

return {
getItem: function(key) {
return store[key] || null;
},
setItem: function(key, value) {
store[key] = value.toString();
},
removeItem: function(key) {
delete store[key]
},
clear: function() {
store = {};
}
};

})();

Object.defineProperty(window, 'localStorage', {
value: localStorageMock
});
135 changes: 135 additions & 0 deletions src/__mocks__/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

export const loginPayload = {
token: "test token",
user: { email: "test user" },
Expand Down Expand Up @@ -113,3 +114,137 @@ export const notifications = {
notPaneDisplay: false,
notificationCount: 1,
};

export const messages = {
messages: [
{
id: 1,
message: "test",
User: {
firstname: "user",
lastname: "test",
image_url: "image",
id: 1
},
createdAt: "Tes"
}
]
}
export const propsTemplate = {
loading: false,
showState: true,
newMessage: true,
scrollToBottom: jest.fn(),
fetchAllMessages: jest.fn(),
messages,
notifications: {
notifications: [
{
createdAt: "2019-11-13T10:07:21.401Z",
id: 8,
message: "visit nairobi",
request_id: 12,
seen: "false",
type: "ReturnTrip",
updatedAt: "2019-11-15T13:13:44.347Z",
user_id: 49,
notPaneDisplay: false,
},
],
markThisRead: jest.fn(),
toggleNotDisplay: jest.fn(),
notPaneDisplay: false,
notificationCount: 1,
},
loginState: {
isAuthenticated: true,
},
profile: {
user: {
firstname: "Rugumbira",
image_url:
"https://res.cloudinary.com/dodfpnbik/image/upload/v1574070442/Screen_Shot_2019-11-18_at_11.44.38_bdjv7r.png",
role_value: 7,
},
},
user: {
firstname: "Rugumbira",
image_url:
"https://res.cloudinary.com/dodfpnbik/image/upload/v1574070442/Screen_Shot_2019-11-18_at_11.44.38_bdjv7r.png",
role_value: 7,
},
postsPerPage: 4,
currentPage: 1,
errors: {},
addHost:jest.fn(),
retrieveProfile: jest.fn(),
requests: {
requestFound: true,
requests: [
{
id: 8,
user_id: 9,
request_type: "OneWay",
location_id: 3,
departure_date: "2019-11-16",
return_date: null,
destinations: [
{
room_id: 2,
check_in: "2019-11-18T15:16:38.447Z",
check_out: "2019-12-27T15:16:38.447Z",
destination_id: 4,
accomodation_id: 1,
},
],
reason: "Visit Lagos",
status: "Pending",
createdAt: "2019-11-11T06:53:54.602Z",
updatedAt: "2019-11-11T06:53:54.602Z",
User: {
image_url: "image",
email: "usertest@gmail.com",
phone: "123456",
gender: "male",
address: "address",
country: "country",
language: "language",
company: "company",
department: "department",
},
},
{
id: 8,
user_id: 9,
request_type: "OneWay",
location_id: 3,
departure_date: "2019-11-16",
return_date: null,
destinations: [
{
room_id: 2,
check_in: "2019-11-18T15:16:38.447Z",
check_out: "2019-12-27T15:16:38.447Z",
destination_id: 4,
accomodation_id: 1,
},
],
reason: "Visit Lagos",
status: "Accepted",
createdAt: "2019-11-11T06:53:54.602Z",
updatedAt: "2019-11-11T06:53:54.602Z",
User: {
image_url: "image",
email: "usertest@gmail.com",
phone: "123456",
gender: "male",
address: "address",
country: "country",
language: "language",
company: "company",
department: "department",
},
},
],
},
};
2 changes: 2 additions & 0 deletions src/__tests__/components/ProfilePage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ProfileComponent, {
} from "../../components/profile-page/ProfilePage";
import Select from "../../components/profile-page/Select";
import user from "../../__mocks__/__profile_data_success__.json";
import { messages } from "../../__mocks__/fixtures";

const mockedStore = configureStore([thunk]);

Expand Down Expand Up @@ -116,6 +117,7 @@ describe("profile unit tests", () => {
describe("profile integration tests", () => {
beforeEach(() => {
const store = mockedStore({
messages,
profile: {
status: {
message: "updated profile successful!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { Provider } from "react-redux";
import mockStore from "../../../__mocks__/mockStore";
import AccommodationsComponent, { AccommodationsPage } from "../../../components/accommodation/AccommodationsPage";
import { accommodations, user } from "../../../__mocks__/fixtures";

import { messages } from "../../../__mocks__/fixtures";
const props = {
messages,
user,
accommodations,
getAccommodations: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Provider } from "react-redux";
import { mount } from "enzyme";
import { MemoryRouter } from "react-router-dom";
import mockStore from "../../../__mocks__/mockStore";
import { accommodation, user } from "../../../__mocks__/fixtures";
import { accommodation, user, messages } from "../../../__mocks__/fixtures";
import AccPage, {
AnAccommodationPage,
} from "../../../components/accommodation/AnAccommodationPage";
Expand All @@ -16,6 +16,7 @@ const props = {
user,
getAccommodation: jest.fn(),
retrieveProfile: jest.fn(),
messages,
};

describe("An Accommodation page", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/components/admin-requests/AdminRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import AdminRequests, {
AdminRequests as AdminRequestsComponent,
} from "../../../components/admin-requests/AdminRequests";
import successresponse from "../../../__mocks__/__get_user_request_success__.json";
import { messages } from "../../../__mocks__/fixtures";

Enzyme.configure({ adapter: new Adapter() });
const mockedStore = configureStore([thunk]);
const props = {
messages,
notifications: {
notifications: [
{
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/components/admin/AddHost.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import AddHost, {
AddHost as AddHostComponent,
} from "../../../components/admin/AddHost";
import successresponse from "../../../__mocks__/__get_user_request_success__.json";

import { messages } from "../../../__mocks__/fixtures";
const validateHost = jest.fn();

Enzyme.configure({ adapter: new Adapter() });
const mockedStore = configureStore([thunk]);
const addHost = jest.fn();
const props = {
messages,
notifications: {
notifications: [
{
Expand Down
101 changes: 101 additions & 0 deletions src/__tests__/components/chat/Chat.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* eslint-disable import/no-named-as-default */
/* eslint-disable react/jsx-props-no-spreading */
/* eslint-disable no-unused-vars */
/* eslint-disable no-multi-assign */
/* eslint-disable no-undef */
import React from "react";
import Enzyme, { mount, shallow } from "enzyme";
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import Adapter from "enzyme-adapter-react-16/build";
import { Provider } from "react-redux";
import { BrowserRouter as Router } from "react-router-dom";
import { JSDOM } from "jsdom";
import Chat, { Chat as ChatComponent } from "../../../components/chat";
import { propsTemplate, messages } from "../../../__mocks__/fixtures";

Enzyme.configure({ adapter: new Adapter() });
const mockedStore = configureStore([thunk]);

const store = mockedStore(propsTemplate);

describe("Chat component", () => {
const wrapper = mount(
<Provider store={store}>
<Router>
<ChatComponent {...propsTemplate} history={{ push: jest.fn() }} />
</Router>
,
</Provider>
);
const component = mount(
<ChatComponent {...propsTemplate} store={store} history={{ push: jest.fn() }} />
);
const component2 = shallow(
<ChatComponent {...propsTemplate} history={{ push: jest.fn() }} />
);
it("should render without crashing to cover mapStateToProps", () => {
const nextPropsSuccess = { ...propsTemplate };
wrapper.setProps(nextPropsSuccess);
expect(wrapper).toHaveLength(1);
});
beforeEach(() => {
window.HTMLElement.prototype.scrollIntoView = jest.fn();
})
it("should set the props", () => {
const nextPropsError = {
errors: {
errors: [{ message: "error message" }, { message: "error message" }]
},
user: {
role_value: 7
},
messages: {}
};
component2.setProps(nextPropsError);
expect(component2.state()).toHaveProperty("user", { role_value: 7 });
});
it("should set the showState to true", () => {
component.setState({ showState: true });
expect(component.state()).toHaveProperty("showState", true);
});
it("should set the loading state to true", () => {
component.setState({ loading: true });
expect(component.state()).toHaveProperty("loading", true);
});
it("should set the loading state to false", () => {
component.setState({ loading: false });
expect(component.state()).toHaveProperty("loading", false);
});
it("should set the newMessage state to false", () => {
component.setState({ newMessage: false });
expect(component.state()).toHaveProperty("newMessage", false);
});
it("should set the newMessage state to true", () => {
component.setState({ newMessage: true });
expect(component.state()).toHaveProperty("newMessage", true);
});
it("should trigger close button", () => {

const closebtn = component.find(".close-icon").at(1);
closebtn.props().onClick();
expect(component.state()).toHaveProperty("showState", false);
});
it("should trigger send message button", () => {
component.setState({ loading: false, showState: true });
const chatBtn = component.find(".chat-btn").at(1);
chatBtn.props().onClick();
});
// it("should trigger new-message-alert button", () => {
// // component.setState({ loading: false, showState: true, newMessage: true});
// // console.log(component.props().store.getState())
// console.log(component.props().children[0].props)
// const newMessageBtn = component.find(".new-message-alert");
// newMessageBtn.props().onClick();
// expect(component.state()).toHaveProperty("newMessage", false);
// });
it("should set the showState to false", () => {
component.setState({ showState: false });
expect(component.state()).toHaveProperty("showState", false);
});
});
Loading

0 comments on commit f9e0637

Please sign in to comment.