Commit 060af8d0 authored by Tankred Hase's avatar Tankred Hase

Add missing unit tests

parent f8391f24
......@@ -256,6 +256,7 @@ class PaymentAction {
setTargetConf({ targetConf }) {
const { payment } = this._store;
payment.targetConf = targetConf;
if (!payment.feeEstimates.length) return;
payment.fee = payment.feeEstimates.find(
e => e.targetConf === targetConf
).fee;
......
......@@ -161,6 +161,7 @@ describe('Action Payments Unit Tests', () => {
store.payment.amount = 'bar';
store.payment.note = 'baz';
store.payment.fee = 'blub';
store.payment.targetConf = 1;
store.payment.useScanner = true;
store.payment.sendAll = true;
payment.init();
......@@ -168,12 +169,46 @@ describe('Action Payments Unit Tests', () => {
expect(store.payment.amount, 'to equal', '');
expect(store.payment.note, 'to equal', '');
expect(store.payment.fee, 'to equal', '');
expect(store.payment.useScanner, 'to equal', false);
expect(store.payment.fee, 'to equal', '');
expect(store.payment.targetConf, 'to equal', 16);
expect(store.payment.sendAll, 'to equal', false);
expect(nav.goPay, 'was called once');
});
});
describe('estimateFee()', () => {
beforeEach(() => {
store.payment.address = 'foo';
store.payment.amount = '2000';
grpc.sendCommand.withArgs('estimateFee').resolves({
feeSat: 10000,
});
});
it('should get three fee estimates', async () => {
await payment.estimateFee();
expect(grpc.sendCommand, 'was called thrice');
expect(store.payment.feeEstimates[0].prio, 'to equal', 'Low');
expect(store.payment.feeEstimates[1].prio, 'to equal', 'Med');
expect(store.payment.feeEstimates[2].prio, 'to equal', 'High');
});
});
describe('setTargetConf()', () => {
it('should set target conf and fee', async () => {
store.payment.feeEstimates = [{ targetConf: 6, fee: '42' }];
await payment.setTargetConf({ targetConf: 6 });
expect(store.payment.targetConf, 'to equal', 6);
expect(store.payment.fee, 'to equal', '42');
});
it('should set target conf but not fee if not estimates', async () => {
await payment.setTargetConf({ targetConf: 6 });
expect(store.payment.targetConf, 'to equal', 6);
expect(store.payment.fee, 'to equal', '');
});
});
describe('initPayBitcoinConfirm()', () => {
beforeEach(() => {
store.payment.address = 'foo';
......@@ -185,7 +220,7 @@ describe('Action Payments Unit Tests', () => {
it('should get estimate and navigate to confirm view', async () => {
await payment.initPayBitcoinConfirm();
expect(grpc.sendCommand, 'was called once');
expect(grpc.sendCommand, 'was called thrice');
expect(nav.goPayBitcoinConfirm, 'was called once');
expect(notification.display, 'was not called');
expect(store.payment.fee, 'to be', '0.0001');
......@@ -204,7 +239,7 @@ describe('Action Payments Unit Tests', () => {
it('should get estimate and navigate if fee is set', async () => {
store.payment.fee = '0.0002';
await payment.initPayBitcoinConfirm();
expect(grpc.sendCommand, 'was called once');
expect(grpc.sendCommand, 'was called thrice');
expect(nav.goPayBitcoinConfirm, 'was called once');
expect(notification.display, 'was not called');
expect(store.payment.fee, 'to be', '0.0001');
......@@ -213,7 +248,7 @@ describe('Action Payments Unit Tests', () => {
it('should get estimate and navigate if sendAll is set', async () => {
store.payment.sendAll = true;
await payment.initPayBitcoinConfirm();
expect(grpc.sendCommand, 'was called once');
expect(grpc.sendCommand, 'was called thrice');
expect(nav.goPayBitcoinConfirm, 'was called once');
expect(notification.display, 'was not called');
expect(store.payment.fee, 'to be', '0.0001');
......
......@@ -14,10 +14,29 @@ describe('Computed Payment Unit Tests', () => {
it('should work with initial store', () => {
ComputedPayment(store);
expect(store.paymentAmountLabel, 'to equal', '0');
expect(store.paymentFeeEstimateItems, 'to equal', []);
expect(store.paymentFeeLabel, 'to equal', '0');
expect(store.paymentTotalLabel, 'to equal', '0');
});
it('should calculate fee estimate label', () => {
store.unitLabel = 'sats';
store.payment.feeEstimates = [
{
fee: '10',
targetConf: 6,
prio: 'Med',
},
];
ComputedPayment(store);
expect(
store.paymentFeeEstimateItems[0].label,
'to match',
/^Med 10 sats$/
);
expect(store.paymentFeeEstimateItems[0].value, 'to equal', 6);
});
it('should calculate btc total', () => {
store.payment.fee = '0.0001';
store.payment.amount = '0.1';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment