Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 060af8d

Browse files
committed
Add missing unit tests
1 parent f8391f2 commit 060af8d

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

src/action/payment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class PaymentAction {
256256
setTargetConf({ targetConf }) {
257257
const { payment } = this._store;
258258
payment.targetConf = targetConf;
259+
if (!payment.feeEstimates.length) return;
259260
payment.fee = payment.feeEstimates.find(
260261
e => e.targetConf === targetConf
261262
).fee;

test/unit/action/payment.spec.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,54 @@ describe('Action Payments Unit Tests', () => {
161161
store.payment.amount = 'bar';
162162
store.payment.note = 'baz';
163163
store.payment.fee = 'blub';
164+
store.payment.targetConf = 1;
164165
store.payment.useScanner = true;
165166
store.payment.sendAll = true;
166167
payment.init();
167168
expect(store.payment.address, 'to equal', '');
168169
expect(store.payment.amount, 'to equal', '');
169170
expect(store.payment.note, 'to equal', '');
170171
expect(store.payment.fee, 'to equal', '');
171-
expect(store.payment.useScanner, 'to equal', false);
172+
expect(store.payment.fee, 'to equal', '');
173+
expect(store.payment.targetConf, 'to equal', 16);
172174
expect(store.payment.sendAll, 'to equal', false);
173175
expect(nav.goPay, 'was called once');
174176
});
175177
});
176178

179+
describe('estimateFee()', () => {
180+
beforeEach(() => {
181+
store.payment.address = 'foo';
182+
store.payment.amount = '2000';
183+
grpc.sendCommand.withArgs('estimateFee').resolves({
184+
feeSat: 10000,
185+
});
186+
});
187+
188+
it('should get three fee estimates', async () => {
189+
await payment.estimateFee();
190+
expect(grpc.sendCommand, 'was called thrice');
191+
expect(store.payment.feeEstimates[0].prio, 'to equal', 'Low');
192+
expect(store.payment.feeEstimates[1].prio, 'to equal', 'Med');
193+
expect(store.payment.feeEstimates[2].prio, 'to equal', 'High');
194+
});
195+
});
196+
197+
describe('setTargetConf()', () => {
198+
it('should set target conf and fee', async () => {
199+
store.payment.feeEstimates = [{ targetConf: 6, fee: '42' }];
200+
await payment.setTargetConf({ targetConf: 6 });
201+
expect(store.payment.targetConf, 'to equal', 6);
202+
expect(store.payment.fee, 'to equal', '42');
203+
});
204+
205+
it('should set target conf but not fee if not estimates', async () => {
206+
await payment.setTargetConf({ targetConf: 6 });
207+
expect(store.payment.targetConf, 'to equal', 6);
208+
expect(store.payment.fee, 'to equal', '');
209+
});
210+
});
211+
177212
describe('initPayBitcoinConfirm()', () => {
178213
beforeEach(() => {
179214
store.payment.address = 'foo';
@@ -185,7 +220,7 @@ describe('Action Payments Unit Tests', () => {
185220

186221
it('should get estimate and navigate to confirm view', async () => {
187222
await payment.initPayBitcoinConfirm();
188-
expect(grpc.sendCommand, 'was called once');
223+
expect(grpc.sendCommand, 'was called thrice');
189224
expect(nav.goPayBitcoinConfirm, 'was called once');
190225
expect(notification.display, 'was not called');
191226
expect(store.payment.fee, 'to be', '0.0001');
@@ -204,7 +239,7 @@ describe('Action Payments Unit Tests', () => {
204239
it('should get estimate and navigate if fee is set', async () => {
205240
store.payment.fee = '0.0002';
206241
await payment.initPayBitcoinConfirm();
207-
expect(grpc.sendCommand, 'was called once');
242+
expect(grpc.sendCommand, 'was called thrice');
208243
expect(nav.goPayBitcoinConfirm, 'was called once');
209244
expect(notification.display, 'was not called');
210245
expect(store.payment.fee, 'to be', '0.0001');
@@ -213,7 +248,7 @@ describe('Action Payments Unit Tests', () => {
213248
it('should get estimate and navigate if sendAll is set', async () => {
214249
store.payment.sendAll = true;
215250
await payment.initPayBitcoinConfirm();
216-
expect(grpc.sendCommand, 'was called once');
251+
expect(grpc.sendCommand, 'was called thrice');
217252
expect(nav.goPayBitcoinConfirm, 'was called once');
218253
expect(notification.display, 'was not called');
219254
expect(store.payment.fee, 'to be', '0.0001');

test/unit/computed/payment.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,29 @@ describe('Computed Payment Unit Tests', () => {
1414
it('should work with initial store', () => {
1515
ComputedPayment(store);
1616
expect(store.paymentAmountLabel, 'to equal', '0');
17+
expect(store.paymentFeeEstimateItems, 'to equal', []);
1718
expect(store.paymentFeeLabel, 'to equal', '0');
1819
expect(store.paymentTotalLabel, 'to equal', '0');
1920
});
2021

22+
it('should calculate fee estimate label', () => {
23+
store.unitLabel = 'sats';
24+
store.payment.feeEstimates = [
25+
{
26+
fee: '10',
27+
targetConf: 6,
28+
prio: 'Med',
29+
},
30+
];
31+
ComputedPayment(store);
32+
expect(
33+
store.paymentFeeEstimateItems[0].label,
34+
'to match',
35+
/^Med 10 sats$/
36+
);
37+
expect(store.paymentFeeEstimateItems[0].value, 'to equal', 6);
38+
});
39+
2140
it('should calculate btc total', () => {
2241
store.payment.fee = '0.0001';
2342
store.payment.amount = '0.1';

0 commit comments

Comments
 (0)