Skip to content

Commit 0fc9422

Browse files
committed
100% test coverage
1 parent 1a0271d commit 0fc9422

4 files changed

Lines changed: 238 additions & 214 deletions

File tree

src/App.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const Step1 = (props) => {
2222
<input
2323
type="checkbox"
2424
name="over18"
25+
data-testid="checkbox"
2526
checked={props.getState("over18")}
2627
onChange={props.handleChange}
2728
/>
@@ -140,6 +141,14 @@ const Step4 = (props) => {
140141
Next
141142
</button>
142143
}
144+
<div>
145+
{props.allSteps().map(({ order, title }) => (
146+
<p key={order}>
147+
<span data-testid={`order ${order}`}>{order}</span>{" "}
148+
<span data-testid={`title ${order}`}>{title}</span>
149+
</p>
150+
))}
151+
</div>
143152
</div>
144153
);
145154
};

tests/StepBuilder.test.js

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,104 @@ const { StepBuilder, StepNode } = require("../src/lib/StepBuilder");
22

33
const test_steps = ["Step1", "Step2", "Step3"];
44
describe("StepBuilder", () => {
5-
describe("constructor()", () => {
6-
const steps = StepBuilder();
7-
it("creates the object with start=1, current=1, size=null properties", () => {
8-
expect(steps.start).toBe(1);
9-
expect(steps.current).toBe(1);
10-
expect(steps.size).toBe(null);
11-
});
12-
});
5+
describe("constructor()", () => {
6+
const steps = StepBuilder();
7+
it("creates the object with start=1, current=1, size=null properties", () => {
8+
expect(steps.start).toBe(1);
9+
expect(steps.current).toBe(1);
10+
expect(steps.size).toBe(null);
11+
});
12+
});
1313

14-
describe(".build()", () => {
15-
const steps = StepBuilder();
16-
const built = steps.build(test_steps);
14+
describe(".build()", () => {
15+
const steps = StepBuilder();
16+
const built = steps.build(test_steps);
1717

18-
it("sets steps.size to the step count", () => {
19-
expect(steps.size).toBe(test_steps.length);
20-
});
18+
it("sets steps.size to the step count", () => {
19+
expect(steps.size).toBe(test_steps.length);
20+
});
2121

22-
it("returns an array of StepNode objects", () => {
23-
expect(Array.isArray(built)).toBe(true);
24-
});
22+
it("returns an array of StepNode objects", () => {
23+
expect(Array.isArray(built)).toBe(true);
24+
});
2525

26-
it("StepNodes have order, nextStep, prevStep properties", () => {
27-
built.forEach((node) => {
28-
expect(node.order).toEqual(expect.any(Number));
29-
expect(node).toHaveProperty("order");
30-
expect(node).toHaveProperty("nextStep");
31-
expect(node).toHaveProperty("prevStep");
32-
});
33-
});
26+
it("StepNodes have order, nextStep, prevStep properties", () => {
27+
built.forEach((node) => {
28+
expect(node.order).toEqual(expect.any(Number));
29+
expect(node).toHaveProperty("order");
30+
expect(node).toHaveProperty("nextStep");
31+
expect(node).toHaveProperty("prevStep");
32+
});
33+
});
3434

35-
it("StepNodes methods isFirst, isLast, hasPrev, hasNext", () => {
36-
built.forEach((node, i) => {
37-
let order = i + 1;
38-
if (order === 1) {
39-
expect(node.isFirst()).toBe(true);
40-
expect(node.isLast()).toBe(false);
41-
expect(node.hasPrev()).toBe(false);
42-
expect(node.hasNext()).toBe(true);
43-
} else if (order === 3) {
44-
expect(node.isFirst()).toBe(false);
45-
expect(node.isLast()).toBe(true);
46-
expect(node.hasPrev()).toBe(true);
47-
expect(node.hasNext()).toBe(false);
48-
} else {
49-
expect(node.isFirst()).toBe(false);
50-
expect(node.isLast()).toBe(false);
51-
expect(node.hasPrev()).toBe(true);
52-
expect(node.hasNext()).toBe(true);
53-
}
54-
});
55-
});
56-
});
35+
it("StepNodes methods isFirst, isLast, hasPrev, hasNext", () => {
36+
built.forEach((node, i) => {
37+
let order = i + 1;
38+
if (order === 1) {
39+
expect(node.isFirst()).toBe(true);
40+
expect(node.isLast()).toBe(false);
41+
expect(node.hasPrev()).toBe(false);
42+
expect(node.hasNext()).toBe(true);
43+
} else if (order === 3) {
44+
expect(node.isFirst()).toBe(false);
45+
expect(node.isLast()).toBe(true);
46+
expect(node.hasPrev()).toBe(true);
47+
expect(node.hasNext()).toBe(false);
48+
} else {
49+
expect(node.isFirst()).toBe(false);
50+
expect(node.isLast()).toBe(false);
51+
expect(node.hasPrev()).toBe(true);
52+
expect(node.hasNext()).toBe(true);
53+
}
54+
});
55+
});
56+
});
5757

58-
describe(".next()", () => {
59-
const steps = StepBuilder();
60-
steps.build(test_steps);
61-
it("sets this.current to +1", () => {
62-
expect(steps.current).toBe(1);
63-
steps.next();
64-
expect(steps.current).toBe(2);
65-
});
66-
it("this.current remains same if it's last step", () => {
67-
steps.next();
68-
expect(steps.current).toBe(3);
69-
steps.next();
70-
expect(steps.current).toBe(3);
71-
});
72-
});
58+
describe(".next()", () => {
59+
const steps = StepBuilder();
60+
steps.build(test_steps);
61+
it("sets this.current to +1", () => {
62+
expect(steps.current).toBe(1);
63+
steps.next();
64+
expect(steps.current).toBe(2);
65+
});
66+
it("this.current remains same if it's last step", () => {
67+
steps.next();
68+
expect(steps.current).toBe(3);
69+
steps.next();
70+
expect(steps.current).toBe(3);
71+
});
72+
});
7373

74-
describe(".prev()", () => {
75-
const steps = StepBuilder();
76-
steps.build(test_steps);
77-
it("sets this.current to -1", () => {
78-
steps.next(); // 2
79-
steps.next(); // 3
80-
steps.prev(); // 2
81-
expect(steps.current).toBe(2);
82-
});
83-
it("this.current remains same if it's first step", () => {
84-
steps.prev(); // 1
85-
expect(steps.current).toBe(1);
86-
steps.prev(); // 1
87-
expect(steps.current).toBe(1);
88-
});
89-
});
74+
describe(".prev()", () => {
75+
const steps = StepBuilder();
76+
steps.build(test_steps);
77+
it("sets this.current to -1", () => {
78+
steps.next(); // 2
79+
steps.next(); // 3
80+
steps.prev(); // 2
81+
expect(steps.current).toBe(2);
82+
});
83+
it("this.current remains same if it's first step", () => {
84+
steps.prev(); // 1
85+
expect(steps.current).toBe(1);
86+
steps.prev(); // 1
87+
expect(steps.current).toBe(1);
88+
});
89+
});
9090

91-
describe(".jump(step_id)", () => {
92-
const steps = StepBuilder();
93-
steps.build(test_steps);
94-
it("sets this.current to step_id", () => {
95-
steps.jump(3);
96-
expect(steps.current).toBe(3);
97-
steps.jump(2);
98-
expect(steps.current).toBe(2);
99-
});
100-
it("this.current remains same if step_id doesn't exist", () => {
101-
steps.jump(5); // still 2 from previous jump
102-
expect(steps.current).toBe(2);
103-
});
104-
});
91+
describe(".jump(step_id)", () => {
92+
const steps = StepBuilder();
93+
steps.build(test_steps);
94+
it("sets this.current to step_id", () => {
95+
steps.jump(3);
96+
expect(steps.current).toBe(3);
97+
steps.jump(2);
98+
expect(steps.current).toBe(2);
99+
});
100+
it("this.current remains same if step_id doesn't exist", () => {
101+
steps.jump(5); // still 2 from previous jump
102+
expect(steps.current).toBe(2);
103+
});
104+
});
105105
});

0 commit comments

Comments
 (0)