@@ -3,6 +3,7 @@ import { BuildSwapSteps, SwapDirection } from 'types/state';
3
3
import { grpc } from '@improbable-eng/grpc-web' ;
4
4
import { waitFor } from '@testing-library/react' ;
5
5
import Big from 'big.js' ;
6
+ import { BalanceMode } from 'util/constants' ;
6
7
import { injectIntoGrpcUnary } from 'util/tests' ;
7
8
import { lndChannel , loopTerms } from 'util/tests/sampleData' ;
8
9
import { BuildSwapStore , createStore , Store } from 'store' ;
@@ -38,12 +39,43 @@ describe('BuildSwapStore', () => {
38
39
expect ( store . selectedChanIds ) . toHaveLength ( 0 ) ;
39
40
} ) ;
40
41
41
- it ( 'should infer the swap direction based on the selected channels' , ( ) => {
42
+ it ( 'should infer the swap direction based on the selected channels (receiving mode)' , ( ) => {
43
+ rootStore . settingsStore . setBalanceMode ( BalanceMode . receive ) ;
42
44
const channels = rootStore . channelStore . sortedChannels ;
43
45
store . toggleSelectedChannel ( channels [ 0 ] . chanId ) ;
44
46
expect ( store . inferredDirection ) . toEqual ( SwapDirection . OUT ) ;
45
47
store . toggleSelectedChannel ( channels [ channels . length - 1 ] . chanId ) ;
48
+ expect ( store . inferredDirection ) . toEqual ( SwapDirection . OUT ) ;
49
+ } ) ;
50
+
51
+ it ( 'should infer the swap direction based on the selected channels (sending mode)' , ( ) => {
52
+ rootStore . settingsStore . setBalanceMode ( BalanceMode . send ) ;
53
+ const channels = rootStore . channelStore . sortedChannels ;
54
+ store . toggleSelectedChannel ( channels [ 0 ] . chanId ) ;
55
+ expect ( store . inferredDirection ) . toEqual ( SwapDirection . IN ) ;
56
+ store . toggleSelectedChannel ( channels [ channels . length - 1 ] . chanId ) ;
57
+ expect ( store . inferredDirection ) . toEqual ( SwapDirection . IN ) ;
58
+ } ) ;
59
+
60
+ it ( 'should infer the swap direction based on the selected channels (routing mode)' , ( ) => {
61
+ rootStore . settingsStore . setBalanceMode ( BalanceMode . routing ) ;
62
+ const channels = rootStore . channelStore . sortedChannels ;
63
+ let c = channels [ 0 ] ;
64
+ c . localBalance = c . capacity . mul ( 0.2 ) ;
65
+ c . remoteBalance = c . capacity . sub ( c . localBalance ) ;
66
+ store . toggleSelectedChannel ( c . chanId ) ;
46
67
expect ( store . inferredDirection ) . toEqual ( SwapDirection . IN ) ;
68
+
69
+ c = channels [ channels . length - 1 ] ;
70
+ c . localBalance = c . capacity . mul ( 0.85 ) ;
71
+ c . remoteBalance = c . capacity . sub ( c . localBalance ) ;
72
+ store . toggleSelectedChannel ( channels [ channels . length - 1 ] . chanId ) ;
73
+ expect ( store . inferredDirection ) . toEqual ( SwapDirection . OUT ) ;
74
+ } ) ;
75
+
76
+ it ( 'should not infer the swap direction with no selected channels (routing mode)' , ( ) => {
77
+ rootStore . settingsStore . setBalanceMode ( BalanceMode . routing ) ;
78
+ expect ( store . inferredDirection ) . toBeUndefined ( ) ;
47
79
} ) ;
48
80
49
81
it ( 'should fetch loop terms' , async ( ) => {
0 commit comments