-
Notifications
You must be signed in to change notification settings - Fork 0
/
payments.test.js
67 lines (54 loc) · 2.17 KB
/
payments.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
describe("Payments test (with setup and tear-down)", function() {
beforeEach(function () {
billAmtInput.value = 100;
tipAmtInput.value = 20;
});
it('should add a new payment to allPayments on submitPaymentInfo()', function () {
submitPaymentInfo();
expect(Object.keys(allPayments).length).toEqual(1);
expect(allPayments['payment1'].billAmt).toEqual('100');
expect(allPayments['payment1'].tipAmt).toEqual('20');
expect(allPayments['payment1'].tipPercent).toEqual(20);
});
it('should not add a new payment on submitPaymentInfo() with empty input', function () {
billAmtInput.value = '';
submitPaymentInfo();
expect(Object.keys(allPayments).length).toEqual(0);
});
it('should payment update #paymentTable on appendPaymentTable()', function () {
let curPayment = createCurPayment();
allPayments['payment1'] = curPayment;
appendPaymentTable(curPayment);
let curTdList = document.querySelectorAll('#paymentTable tbody tr td');
expect(curTdList.length).toEqual(4);
expect(curTdList[0].innerText).toEqual('$100');
expect(curTdList[1].innerText).toEqual('$20');
expect(curTdList[2].innerText).toEqual('%20');
expect(curTdList[3].innerText).toEqual('X');
});
it('should create a new payment on createCurPayment()', function () {
let expectedPayment = {
billAmt: '100',
tipAmt: '20',
tipPercent: 20,
}
expect(createCurPayment()).toEqual(expectedPayment);
});
it('should not create payment with empty input on createCurPayment()', function () {
billAmtInput.value = '';
tipAmtInput.value = '';
let curPayment = createCurPayment();
expect(curPayment).toEqual(undefined);
});
afterEach(function() {
billAmtInput.value = '';
tipAmtInput.value = '';
paymentTbody.innerHTML = '';
summaryTds[0].innerHTML = '';
summaryTds[1].innerHTML = '';
summaryTds[2].innerHTML = '';
serverTbody.innerHTML = '';
paymentId = 0;
allPayments = {};
});
});