@@ -160,32 +160,69 @@ describe('Action Payments Unit Tests', () => {
160160 store . payment . address = 'foo' ;
161161 store . payment . amount = 'bar' ;
162162 store . payment . note = 'baz' ;
163+ store . payment . fee = 'blub' ;
164+ store . payment . useScanner = true ;
165+ store . payment . sendAll = true ;
163166 payment . init ( ) ;
164167 expect ( store . payment . address , 'to equal' , '' ) ;
165168 expect ( store . payment . amount , 'to equal' , '' ) ;
166169 expect ( store . payment . note , 'to equal' , '' ) ;
170+ expect ( store . payment . fee , 'to equal' , '' ) ;
171+ expect ( store . payment . useScanner , 'to equal' , false ) ;
172+ expect ( store . payment . sendAll , 'to equal' , false ) ;
167173 expect ( nav . goPay , 'was called once' ) ;
168174 } ) ;
169175 } ) ;
170176
171177 describe ( 'initPayBitcoinConfirm()' , ( ) => {
172- it ( 'should get estimate and navigate to confirm view' , async ( ) => {
178+ beforeEach ( ( ) => {
173179 store . payment . address = 'foo' ;
174180 store . payment . amount = '2000' ;
175181 grpc . sendCommand . withArgs ( 'estimateFee' ) . resolves ( {
176182 feeSat : 10000 ,
177183 } ) ;
184+ } ) ;
185+
186+ it ( 'should get estimate and navigate to confirm view' , async ( ) => {
187+ await payment . initPayBitcoinConfirm ( ) ;
188+ expect ( grpc . sendCommand , 'was called once' ) ;
189+ expect ( nav . goPayBitcoinConfirm , 'was called once' ) ;
190+ expect ( notification . display , 'was not called' ) ;
191+ expect ( store . payment . fee , 'to be' , '0.0001' ) ;
192+ } ) ;
193+
194+ it ( 'should not get estimate and navigate if fee and sendAll are set' , async ( ) => {
195+ store . payment . fee = '0.0002' ;
196+ store . payment . sendAll = true ;
178197 await payment . initPayBitcoinConfirm ( ) ;
198+ expect ( grpc . sendCommand , 'was not called' ) ;
199+ expect ( nav . goPayBitcoinConfirm , 'was called once' ) ;
200+ expect ( notification . display , 'was not called' ) ;
201+ expect ( store . payment . fee , 'to be' , '0.0002' ) ;
202+ } ) ;
203+
204+ it ( 'should get estimate and navigate if fee is set' , async ( ) => {
205+ store . payment . fee = '0.0002' ;
206+ await payment . initPayBitcoinConfirm ( ) ;
207+ expect ( grpc . sendCommand , 'was called once' ) ;
208+ expect ( nav . goPayBitcoinConfirm , 'was called once' ) ;
209+ expect ( notification . display , 'was not called' ) ;
210+ expect ( store . payment . fee , 'to be' , '0.0001' ) ;
211+ } ) ;
212+
213+ it ( 'should get estimate and navigate if sendAll is set' , async ( ) => {
214+ store . payment . sendAll = true ;
215+ await payment . initPayBitcoinConfirm ( ) ;
216+ expect ( grpc . sendCommand , 'was called once' ) ;
179217 expect ( nav . goPayBitcoinConfirm , 'was called once' ) ;
180218 expect ( notification . display , 'was not called' ) ;
181219 expect ( store . payment . fee , 'to be' , '0.0001' ) ;
182220 } ) ;
183221
184222 it ( 'should display notification on error' , async ( ) => {
185- store . payment . address = 'foo' ;
186- store . payment . amount = '2000' ;
187223 grpc . sendCommand . withArgs ( 'estimateFee' ) . rejects ( ) ;
188224 await payment . initPayBitcoinConfirm ( ) ;
225+ expect ( grpc . sendCommand , 'was called once' ) ;
189226 expect ( nav . goPayBitcoinConfirm , 'was not called' ) ;
190227 expect ( notification . display , 'was called once' ) ;
191228 expect ( store . payment . fee , 'to be' , '' ) ;
@@ -209,6 +246,13 @@ describe('Action Payments Unit Tests', () => {
209246 payment . setAmount ( { amount : 'some-amount' } ) ;
210247 expect ( store . payment . amount , 'to equal' , 'some-amount' ) ;
211248 } ) ;
249+
250+ it ( 'should reset sendAll if set' , ( ) => {
251+ store . payment . sendAll = true ;
252+ payment . setAmount ( { amount : 'some-amount' } ) ;
253+ expect ( store . payment . amount , 'to equal' , 'some-amount' ) ;
254+ expect ( store . payment . sendAll , 'to be false' ) ;
255+ } ) ;
212256 } ) ;
213257
214258 describe ( 'checkType()' , ( ) => {
@@ -295,6 +339,27 @@ describe('Action Payments Unit Tests', () => {
295339 } ) ;
296340 } ) ;
297341
342+ describe ( 'toggleMax()' , ( ) => {
343+ it ( 'should set the payment amount to the wallet balance minus fee' , async ( ) => {
344+ store . payment . address = 'some-address' ;
345+ store . balanceSatoshis = 100000 ;
346+ grpc . sendCommand . resolves ( { feeSat : 100 } ) ;
347+ await payment . toggleMax ( ) ;
348+ expect ( store . payment . amount , 'to match' , / ^ 0 [ , . ] 0 { 3 } 9 { 3 } $ / ) ;
349+ expect ( store . payment . sendAll , 'to be true' ) ;
350+ } ) ;
351+
352+ it ( 'should disable sendAll and reset amount' , async ( ) => {
353+ store . payment . sendAll = true ;
354+ store . payment . amount = 1000 ;
355+ store . payment . address = 'some-address' ;
356+ store . balanceSatoshis = 100000 ;
357+ await payment . toggleMax ( ) ;
358+ expect ( store . payment . amount , 'to be' , '0' ) ;
359+ expect ( store . payment . sendAll , 'to be false' ) ;
360+ } ) ;
361+ } ) ;
362+
298363 describe ( 'payBitcoin()' , ( ) => {
299364 it ( 'should send on-chain transaction' , async ( ) => {
300365 store . payment . amount = '0.00001' ;
@@ -305,6 +370,23 @@ describe('Action Payments Unit Tests', () => {
305370 expect ( grpc . sendCommand , 'was called with' , 'sendCoins' , {
306371 addr : 'some-address' ,
307372 amount : 1000 ,
373+ sendAll : false ,
374+ } ) ;
375+ expect ( nav . goPayBitcoinDone , 'was called once' ) ;
376+ expect ( notification . display , 'was not called' ) ;
377+ } ) ;
378+
379+ it ( 'should set amount to 0 on sendAll' , async ( ) => {
380+ store . payment . sendAll = true ;
381+ store . payment . amount = '0.00001' ;
382+ store . payment . address = 'some-address' ;
383+ grpc . sendCommand . withArgs ( 'sendCoins' ) . resolves ( ) ;
384+ await payment . payBitcoin ( ) ;
385+ expect ( nav . goWait , 'was called once' ) ;
386+ expect ( grpc . sendCommand , 'was called with' , 'sendCoins' , {
387+ addr : 'some-address' ,
388+ amount : 0 ,
389+ sendAll : true ,
308390 } ) ;
309391 expect ( nav . goPayBitcoinDone , 'was called once' ) ;
310392 expect ( notification . display , 'was not called' ) ;
0 commit comments