Skip to content

Commit 2a46f68

Browse files
committed
173169085-story(oneway-trip):create omeway trip
- Create the popup modal for inserting data - create the action creators for trip and Places - Link the created elements with their corresponding Components - test all functionality [Finishes #173169085]
1 parent 5735837 commit 2a46f68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2225
-34
lines changed

__tests__/Components/Auth/ResetPassword/changePassword.test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ import {
1010
const setup = props => {
1111
const { passwordResetAction, isPasswordUpdated, history, loading } = props;
1212

13+
let historyMock;
14+
if (history) {
15+
historyMock = history;
16+
} else {
17+
historyMock = {
18+
push: jest.fn(),
19+
replace: jest.fn()
20+
};
21+
}
22+
1323
const wrapper = shallow(
1424
<UpdatePassword
1525
passwordResetAction={passwordResetAction}
1626
isPasswordUpdated={isPasswordUpdated}
17-
history={history}
27+
history={historyMock}
1828
loading={loading}
1929
/>
2030
);

__tests__/Components/Auth/SignUp/SignUp.test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ import {
99

1010
const setup = props => {
1111
const { signUpAction, history, status, loading } = props;
12+
let historyMock;
13+
if (history) {
14+
historyMock = history;
15+
} else {
16+
historyMock = {
17+
push: jest.fn(),
18+
replace: jest.fn()
19+
};
20+
}
1221
const wrapper = shallow(
1322
<SignUp
1423
signUpAction={signUpAction}
15-
history={history}
24+
history={historyMock}
1625
status={status}
1726
loading={loading}
1827
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
import { shallow } from "enzyme";
3+
4+
import CreateTripModal from "../../../src/Components/CreateTripModal/CreateTripModal.jsx";
5+
import OneWayTripFormContainer from "../../../src/Components/OneWayTripForm/OneWayTripForm.jsx";
6+
7+
describe("CreateTripModal test suite", () => {
8+
let wrapper;
9+
beforeEach(() => {
10+
wrapper = shallow(<CreateTripModal showModal={jest.fn()} />);
11+
});
12+
it("should render with no errors and show one way trip form", () => {
13+
expect(wrapper.length).toBe(1);
14+
expect(wrapper.find(".modal").exists()).toBe(true);
15+
expect(wrapper.find(OneWayTripFormContainer).exists()).toBe(true);
16+
});
17+
18+
it("should simulate change one trip type select", () => {
19+
const tripTypeSelect = wrapper.find("#trip-type-select");
20+
expect(tripTypeSelect.exists()).toBe(true);
21+
tripTypeSelect.simulate("change", {
22+
target: {
23+
value: "return"
24+
}
25+
});
26+
expect(wrapper.find("p").text()).toBe("return form");
27+
tripTypeSelect.simulate("change", {
28+
target: {
29+
value: "multiCity"
30+
}
31+
});
32+
expect(wrapper.find("p").text()).toBe("Multi-city form");
33+
});
34+
35+
it("should simulate onclick event that closes the modal", () => {
36+
const showModal = jest.fn();
37+
const component = shallow(<CreateTripModal showModal={showModal} />);
38+
const closeButton = component.find(".modal-header__close-button");
39+
closeButton.simulate("click");
40+
expect(showModal).toHaveBeenCalledTimes(1);
41+
expect(showModal).toHaveBeenCalledWith(false);
42+
});
43+
});
+17-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import React from "react";
22
import { shallow } from "enzyme";
3+
4+
import LatestTripsContainer from "../../../src/Components/LatestTrips/LatestTrips.jsx";
5+
import CreateTripModal from "../../../src/Components/CreateTripModal/CreateTripModal.jsx";
36
import Home from "../../../src/Components/Home/Home";
47

58
describe("<Home />", () => {
6-
it("it renders home component", () => {
9+
it("renders home component", () => {
10+
const testHome = shallow(<Home />);
11+
expect(testHome.find(".main").length).toEqual(1);
12+
});
13+
it("renders LatestTrips component", () => {
714
const testHome = shallow(<Home />);
8-
expect(testHome.find("Fragment").length).toEqual(1);
15+
expect(testHome.find(LatestTripsContainer).exists()).toBe(true);
16+
});
17+
it("Should simulate on click metod and display createTripModal", () => {
18+
const wrapper = shallow(<Home />);
19+
expect(wrapper.find(CreateTripModal).exists()).toBe(false);
20+
const createTripButton = wrapper.find(".main__show-button");
21+
expect(createTripButton.exists()).toBe(true);
22+
createTripButton.simulate("click");
23+
expect(wrapper.find(CreateTripModal).exists()).toBe(true);
924
});
1025
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
import React from "react";
2+
import { shallow } from "enzyme";
3+
import sinon from "sinon";
4+
5+
import Trip from "../../../src/Components/Shared/TripContainer/TripContainer.jsx";
6+
import {
7+
LatestTrips,
8+
mapStateToProps,
9+
mapDispatchToProps
10+
} from "../../../src/Components/LatestTrips/LatestTrips.jsx";
11+
12+
const setup = props => shallow(<LatestTrips {...props} />);
13+
14+
describe("LatestTrips test suite", () => {
15+
const props = {
16+
allTrips: [
17+
{
18+
id: 8,
19+
userId: 8,
20+
tripType: "one-way",
21+
destination: [3],
22+
date: "2020-06-24T00:00:00.000Z",
23+
returnDate: null,
24+
reasons: "Fixing the branch's internet",
25+
status: "pending",
26+
createdAt: "2020-06-18T20:10:33.128Z",
27+
updatedAt: "2020-06-18T20:10:33.128Z",
28+
User: {
29+
id: 8,
30+
lineManager: 1,
31+
firstname: "chris",
32+
lastname: "meme",
33+
34+
role: "Requester"
35+
},
36+
Departure: {
37+
id: 1,
38+
name: "kigali branch",
39+
country: "Rwanda",
40+
city: "kigali city"
41+
}
42+
},
43+
{
44+
id: 7,
45+
userId: 8,
46+
tripType: "one-way",
47+
destination: [1],
48+
date: "2020-07-12T00:00:00.000Z",
49+
returnDate: null,
50+
reasons: "Being a manager of new trip",
51+
status: "pending",
52+
createdAt: "2020-06-18T20:06:54.409Z",
53+
updatedAt: "2020-06-18T20:06:54.409Z",
54+
User: {
55+
id: 8,
56+
lineManager: 1,
57+
firstname: "chris",
58+
lastname: "meme",
59+
60+
role: "Requester"
61+
},
62+
Departure: {
63+
id: 2,
64+
name: "new york branch",
65+
country: "USA",
66+
city: "new york"
67+
}
68+
},
69+
{
70+
id: 6,
71+
userId: 8,
72+
tripType: "one-way",
73+
destination: [],
74+
date: "2020-06-27T00:00:00.000Z",
75+
returnDate: null,
76+
reasons: "Moving from one branch",
77+
status: "pending",
78+
createdAt: "2020-06-18T15:05:36.068Z",
79+
updatedAt: "2020-06-18T15:05:36.068Z",
80+
User: {
81+
id: 8,
82+
lineManager: 1,
83+
firstname: "chris",
84+
lastname: "meme",
85+
86+
role: "Requester"
87+
},
88+
Departure: {
89+
id: 2,
90+
name: "new york branch",
91+
country: "USA",
92+
city: "new york"
93+
}
94+
},
95+
{
96+
id: 5,
97+
userId: 8,
98+
tripType: "one-way",
99+
destination: [1],
100+
date: "2020-06-28T00:00:00.000Z",
101+
returnDate: null,
102+
reasons: "Testing the Functionality of a new branch",
103+
status: "pending",
104+
createdAt: "2020-06-18T14:33:59.496Z",
105+
updatedAt: "2020-06-18T14:33:59.496Z",
106+
User: {
107+
id: 8,
108+
lineManager: 1,
109+
firstname: "chris",
110+
lastname: "meme",
111+
112+
role: "Requester"
113+
},
114+
Departure: {
115+
id: 2,
116+
name: "new york branch",
117+
country: "USA",
118+
city: "new york"
119+
}
120+
}
121+
],
122+
allPlaces: [
123+
{
124+
id: 1,
125+
name: "kigali branch",
126+
country: "Rwanda",
127+
city: "kigali city",
128+
createdAt: "2020-06-18T14:28:30.001Z",
129+
updatedAt: "2020-06-18T14:28:30.001Z"
130+
},
131+
{
132+
id: 2,
133+
name: "new york branch",
134+
country: "USA",
135+
city: "new york",
136+
createdAt: "2020-06-18T14:28:30.001Z",
137+
updatedAt: "2020-06-18T14:28:30.001Z"
138+
},
139+
{
140+
id: 3,
141+
name: "paris branch",
142+
country: "France",
143+
city: "paris",
144+
createdAt: "2020-06-18T14:28:30.001Z",
145+
updatedAt: "2020-06-18T14:28:30.001Z"
146+
}
147+
],
148+
getAllTrips: () => {},
149+
getPlacesAction: () => {}
150+
};
151+
let getPlaces;
152+
let getAllTrips;
153+
154+
afterEach(() => {
155+
getAllTrips.reset();
156+
getPlaces.reset();
157+
});
158+
159+
it("Should shallow The test component did shallow and all actions", () => {
160+
getAllTrips = sinon.stub(props, "getAllTrips");
161+
getPlaces = sinon.stub(props, "getPlacesAction");
162+
setup(props);
163+
expect(getAllTrips.calledOnce).toBe(true);
164+
expect(getPlaces.calledOnce).toBe(true);
165+
});
166+
167+
it("Should return null as there are no current trips", () => {
168+
const component = setup({ ...props, allTrips: [] });
169+
expect(component.find("div").exists()).toBe(false);
170+
expect(component.find(Trip).exists()).toBe(false);
171+
});
172+
it("Should render all trips without modifying them", () => {
173+
const component = setup({
174+
...props,
175+
allTrips: [
176+
{
177+
id: 8,
178+
userId: 8,
179+
tripType: "one-way",
180+
destination: [3],
181+
date: "2020-06-24T00:00:00.000Z",
182+
returnDate: null,
183+
reasons: "Fixing the branch's internet",
184+
status: "pending",
185+
createdAt: "2020-06-18T20:10:33.128Z",
186+
updatedAt: "2020-06-18T20:10:33.128Z",
187+
User: {
188+
id: 8,
189+
lineManager: 1,
190+
firstname: "chris",
191+
lastname: "meme",
192+
193+
role: "Requester"
194+
},
195+
Departure: {
196+
id: 1,
197+
name: "kigali branch",
198+
country: "Rwanda",
199+
city: "kigali city"
200+
}
201+
},
202+
{
203+
id: 7,
204+
userId: 8,
205+
tripType: "one-way",
206+
destination: [1],
207+
date: "2020-07-12T00:00:00.000Z",
208+
returnDate: null,
209+
reasons: "Being a manager of new trip",
210+
status: "pending",
211+
createdAt: "2020-06-18T20:06:54.409Z",
212+
updatedAt: "2020-06-18T20:06:54.409Z",
213+
User: {
214+
id: 8,
215+
lineManager: 1,
216+
firstname: "chris",
217+
lastname: "meme",
218+
219+
role: "Requester"
220+
},
221+
Departure: {
222+
id: 2,
223+
name: "new york branch",
224+
country: "USA",
225+
city: "new york"
226+
}
227+
}
228+
]
229+
});
230+
expect(component.find(Trip).exists()).toBe(true);
231+
});
232+
it("should render without errors", () => {
233+
const component = setup(props);
234+
expect(component.find("div").exists()).toBe(true);
235+
expect(component.find(Trip).exists()).toBe(true);
236+
});
237+
238+
test("mapStateToProps Should return an object", () => {
239+
const expectedObject = {
240+
allPlaces: props.allPlaces,
241+
allTrips: props.allTrips
242+
};
243+
const stateObject = {
244+
places: {
245+
places: props.allPlaces
246+
},
247+
trips: {
248+
allTrips: props.allTrips
249+
}
250+
};
251+
const returnedObject = mapStateToProps(stateObject);
252+
expect(returnedObject).toStrictEqual(expectedObject);
253+
});
254+
255+
it("should test the mapDispatchToProps", () => {
256+
const dispatch = jest.fn();
257+
mapDispatchToProps(dispatch).getPlacesAction();
258+
mapDispatchToProps(dispatch).getAllTrips();
259+
expect(dispatch.mock.calls[0][0]).toBeInstanceOf(Function);
260+
expect(dispatch.mock.calls[1][0]).toBeInstanceOf(Function);
261+
});
262+
});

0 commit comments

Comments
 (0)