-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.test.js
More file actions
67 lines (51 loc) · 1.98 KB
/
Copy pathcalculator.test.js
File metadata and controls
67 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @jest-environment jsdom
*/
import {
handleCurrentItem,
updateSequenceOnceReady,
handleOperatorCase,
} from "./calculator.helper.js";
describe("calculator", () => {
beforeAll(() => {
document.body.innerHTML = `<div class="calculator"></div>`;
});
it("should return the correct item, either a number or an operator or null if there is an operator already", () => {
const twoProps = { currentValue: 2, lastSequenceValue: 3 };
const two = handleCurrentItem(twoProps);
expect(two.innerHTML).toEqual("2");
const operatorProps = { currentValue: "-", lastSequenceValue: "3" };
const operator = handleCurrentItem(operatorProps);
expect(operator.innerHTML).toEqual("-");
const zeroNumberAfterOperatorProps = {
currentValue: "0",
lastSequenceValue: "+",
};
const zeroNumberAfterOperator = handleCurrentItem(
zeroNumberAfterOperatorProps
);
expect(zeroNumberAfterOperator).toEqual(null);
});
it("should handle updateSequenceOnceReady", () => {
const screenSequence = ["22", "+", "2"];
const result = updateSequenceOnceReady(screenSequence);
const screenSequence2 = ["22", "/", "2"];
const result2 = updateSequenceOnceReady(screenSequence2);
expect(result).toEqual([24]);
expect(result2).toEqual([11]);
});
it("Should handle handleOperatorCase when the current value is = and the sequence is complete", () => {
const screenSequence = ["22", "+", "2"];
const itemValue = "=";
const result = handleOperatorCase({ screenSequence, itemValue });
expect(result).toEqual([24]);
});
it("Should handle handleOperatorCase when the current value is = and the sequence is not complete", () => {
const screenSequence = ["22", "+"];
const itemValue = "=";
const result = handleOperatorCase({ screenSequence, itemValue });
expect(result).toEqual(["22"]);
const result2 = handleOperatorCase({ screenSequence, itemValue: "-" });
expect(result2).toEqual(["22", "-"]);
});
});