-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.test.js
75 lines (55 loc) · 2.04 KB
/
helpers.test.js
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
68
69
70
71
72
73
74
75
describe("Utilities test (with setup and tear-down)", function () {
beforeEach(function () {
billAmtInput.value = 100;
tipAmtInput.value = 20;
submitPaymentInfo();
});
it("should sum total tip amount of all payments on sumPaymentTotal()", function () {
expect(sumPaymentTotal("tipAmt")).toEqual(20);
billAmtInput.value = 200;
tipAmtInput.value = 40;
submitPaymentInfo();
expect(sumPaymentTotal("tipAmt")).toEqual(60);
});
it("should sum total bill amount of all payments on sumPaymentTotal()", function () {
expect(sumPaymentTotal("billAmt")).toEqual(100);
billAmtInput.value = 200;
tipAmtInput.value = 40;
submitPaymentInfo();
expect(sumPaymentTotal("billAmt")).toEqual(300);
});
it("should sum total tip percent on sumPaymentTotal()", function () {
expect(sumPaymentTotal("tipPercent")).toEqual(20);
billAmtInput.value = 100;
tipAmtInput.value = 20;
submitPaymentInfo();
expect(sumPaymentTotal("tipPercent")).toEqual(40);
});
it("should sum tip percent of a single tip on calculateTipPercent()", function () {
expect(calculateTipPercent(100, 23)).toEqual(23);
expect(calculateTipPercent(111, 11)).toEqual(10);
});
it("should generate new td from value and append to tr on appendTd(tr, value)", function () {
let newTr = document.createElement("tr");
appendTd(newTr, "test");
expect(newTr.children.length).toEqual(1);
expect(newTr.firstChild.innerHTML).toEqual("test");
});
it("should generate delete td and append to tr on appendDeleteBtn(tr, type)", function () {
let newTr = document.createElement("tr");
appendDeleteBtn(newTr);
expect(newTr.children.length).toEqual(1);
expect(newTr.firstChild.innerHTML).toEqual("X");
});
afterEach(function () {
billAmtInput.value = "";
tipAmtInput.value = "";
paymentTbody.innerHTML = "";
summaryTds[0].innerHTML = "";
summaryTds[1].innerHTML = "";
summaryTds[2].innerHTML = "";
serverTbody.innerHTML = "";
allPayments = {};
paymentId = 0;
});
});