@@ -5,7 +5,7 @@ import { configureMockStore, extraDependenciesMock } from '@suite-common/test-ut
5
5
import { deviceActions } from '@suite-common/wallet-core' ;
6
6
import { Device } from '@trezor/connect' ;
7
7
8
- import { BluetoothDeviceState , bluetoothActions , prepareBluetoothReducerCreator } from '../src' ;
8
+ import { bluetoothActions , prepareBluetoothReducerCreator } from '../src' ;
9
9
import { BluetoothDeviceCommon , BluetoothState } from '../src/bluetoothReducer' ;
10
10
11
11
const bluetoothReducer =
@@ -14,38 +14,24 @@ const bluetoothReducer =
14
14
const initialState : BluetoothState < BluetoothDeviceCommon > = {
15
15
adapterStatus : 'unknown' ,
16
16
scanStatus : 'idle' ,
17
- nearbyDevices : [ ] as BluetoothDeviceState < BluetoothDeviceCommon > [ ] ,
17
+ nearbyDevices : [ ] as BluetoothDeviceCommon [ ] ,
18
18
knownDevices : [ ] as BluetoothDeviceCommon [ ] ,
19
19
} ;
20
20
21
- const bluetoothStateDeviceA : BluetoothDeviceState < BluetoothDeviceCommon > = {
22
- device : {
23
- id : 'A' ,
24
- data : [ ] ,
25
- name : 'Trezor A' ,
26
- lastUpdatedTimestamp : 1 ,
27
- } ,
28
- status : { type : 'pairing' } ,
21
+ const pairingDeviceA : BluetoothDeviceCommon = {
22
+ id : 'A' ,
23
+ data : [ ] ,
24
+ name : 'Trezor A' ,
25
+ lastUpdatedTimestamp : 1 ,
26
+ connectionStatus : { type : 'pairing' } ,
29
27
} ;
30
28
31
- const bluetoothStateDeviceB : BluetoothDeviceState < BluetoothDeviceCommon > = {
32
- device : {
33
- id : 'B' ,
34
- data : [ ] ,
35
- name : 'Trezor B' ,
36
- lastUpdatedTimestamp : 2 ,
37
- } ,
38
- status : null ,
39
- } ;
40
-
41
- const bluetoothStateDeviceC : BluetoothDeviceState < BluetoothDeviceCommon > = {
42
- device : {
43
- id : 'C' ,
44
- data : [ ] ,
45
- name : 'Trezor C' ,
46
- lastUpdatedTimestamp : 3 ,
47
- } ,
48
- status : null ,
29
+ const disconnectedDeviceB : BluetoothDeviceCommon = {
30
+ id : 'B' ,
31
+ data : [ ] ,
32
+ name : 'Trezor B' ,
33
+ lastUpdatedTimestamp : 2 ,
34
+ connectionStatus : { type : 'disconnected' } ,
49
35
} ;
50
36
51
37
describe ( 'bluetoothReducer' , ( ) => {
@@ -63,53 +49,27 @@ describe('bluetoothReducer', () => {
63
49
expect ( store . getState ( ) . bluetooth . adapterStatus ) . toEqual ( 'disabled' ) ;
64
50
} ) ;
65
51
66
- it ( 'sorts the devices based on the `lastUpdatedTimestamp` and keeps the status for already existing device' , ( ) => {
67
- const store = configureMockStore ( {
68
- extra : { } ,
69
- reducer : combineReducers ( { bluetooth : bluetoothReducer } ) ,
70
- preloadedState : {
71
- bluetooth : {
72
- ...initialState ,
73
- nearbyDevices : [ bluetoothStateDeviceB , bluetoothStateDeviceA ] ,
74
- } ,
75
- } ,
76
- } ) ;
77
-
78
- const nearbyDevices : BluetoothDeviceCommon [ ] = [
79
- bluetoothStateDeviceA . device ,
80
- bluetoothStateDeviceC . device ,
81
- ] ;
82
-
83
- store . dispatch ( bluetoothActions . nearbyDevicesUpdateAction ( { nearbyDevices } ) ) ;
84
- expect ( store . getState ( ) . bluetooth . nearbyDevices ) . toEqual ( [
85
- bluetoothStateDeviceC ,
86
- // No `B` device present, it was dropped
87
- {
88
- device : bluetoothStateDeviceA . device ,
89
- status : { type : 'pairing' } , // Keeps the pairing status
90
- } ,
91
- ] ) ;
92
- } ) ;
93
-
94
52
it ( 'changes the status of the given device during pairing process' , ( ) => {
95
53
const store = configureMockStore ( {
96
54
extra : { } ,
97
55
reducer : combineReducers ( { bluetooth : bluetoothReducer } ) ,
98
56
preloadedState : {
99
- bluetooth : { ...initialState , nearbyDevices : [ bluetoothStateDeviceA ] } ,
57
+ bluetooth : { ...initialState , nearbyDevices : [ pairingDeviceA ] } ,
100
58
} ,
101
59
} ) ;
102
60
103
61
store . dispatch (
104
62
bluetoothActions . connectDeviceEventAction ( {
105
- id : 'A' ,
106
- connectionStatus : { type : 'pairing' , pin : '12345' } ,
63
+ device : {
64
+ ...pairingDeviceA ,
65
+ connectionStatus : { type : 'pairing' , pin : '12345' } ,
66
+ } ,
107
67
} ) ,
108
68
) ;
109
69
expect ( store . getState ( ) . bluetooth . nearbyDevices ) . toEqual ( [
110
70
{
111
- device : bluetoothStateDeviceA . device ,
112
- status : { type : 'pairing' , pin : '12345' } ,
71
+ ... pairingDeviceA ,
72
+ connectionStatus : { type : 'pairing' , pin : '12345' } ,
113
73
} ,
114
74
] ) ;
115
75
} ) ;
@@ -121,10 +81,7 @@ describe('bluetoothReducer', () => {
121
81
preloadedState : { bluetooth : initialState } ,
122
82
} ) ;
123
83
124
- const knownDeviceToAdd : BluetoothDeviceCommon [ ] = [
125
- bluetoothStateDeviceA . device ,
126
- bluetoothStateDeviceB . device ,
127
- ] ;
84
+ const knownDeviceToAdd : BluetoothDeviceCommon [ ] = [ pairingDeviceA , disconnectedDeviceB ] ;
128
85
129
86
store . dispatch (
130
87
bluetoothActions . knownDevicesUpdateAction ( { knownDevices : knownDeviceToAdd } ) ,
@@ -133,15 +90,15 @@ describe('bluetoothReducer', () => {
133
90
134
91
store . dispatch ( bluetoothActions . removeKnownDeviceAction ( { id : 'A' } ) ) ;
135
92
136
- expect ( store . getState ( ) . bluetooth . knownDevices ) . toEqual ( [ bluetoothStateDeviceB . device ] ) ;
93
+ expect ( store . getState ( ) . bluetooth . knownDevices ) . toEqual ( [ disconnectedDeviceB ] ) ;
137
94
} ) ;
138
95
139
96
it ( 'removes device from nearbyDevices when the device is disconnected by TrezorConnect' , ( ) => {
140
97
const store = configureMockStore ( {
141
98
extra : { } ,
142
99
reducer : combineReducers ( { bluetooth : bluetoothReducer } ) ,
143
100
preloadedState : {
144
- bluetooth : { ...initialState , nearbyDevices : [ bluetoothStateDeviceA ] } ,
101
+ bluetooth : { ...initialState , nearbyDevices : [ pairingDeviceA ] } ,
145
102
} ,
146
103
} ) ;
147
104
@@ -154,9 +111,9 @@ describe('bluetoothReducer', () => {
154
111
} ) ;
155
112
156
113
it ( 'stores a device in `knownDevices` when device is connected by TrezorConnect' , ( ) => {
157
- const nearbyDevice : BluetoothDeviceState < BluetoothDeviceCommon > = {
158
- device : bluetoothStateDeviceA . device ,
159
- status : { type : 'connected' } ,
114
+ const nearbyDevice : BluetoothDeviceCommon = {
115
+ ... pairingDeviceA ,
116
+ connectionStatus : { type : 'connected' } ,
160
117
} ;
161
118
162
119
const store = configureMockStore ( {
@@ -177,6 +134,6 @@ describe('bluetoothReducer', () => {
177
134
settings : { defaultWalletLoading : 'passphrase' } ,
178
135
} ) ,
179
136
) ;
180
- expect ( store . getState ( ) . bluetooth . knownDevices ) . toEqual ( [ nearbyDevice . device ] ) ;
137
+ expect ( store . getState ( ) . bluetooth . knownDevices ) . toEqual ( [ nearbyDevice ] ) ;
181
138
} ) ;
182
139
} ) ;
0 commit comments