1
1
import { expect } from 'chai' ;
2
2
import {
3
+ BoardListLabels ,
3
4
createBoardList ,
4
5
EditBoardsConfigActionParams ,
5
6
isInferredBoardListItem ,
8
9
} from '../../common/protocol/board-list' ;
9
10
import {
10
11
emptyBoardsConfig ,
12
+ notConnected ,
13
+ selectBoard ,
11
14
unconfirmedBoard ,
12
15
} from '../../common/protocol/boards-service' ;
13
16
import {
@@ -22,6 +25,7 @@ import {
22
25
esp32S3DevModule ,
23
26
history ,
24
27
mkr1000 ,
28
+ mkr1000NetworkPort ,
25
29
mkr1000SerialPort ,
26
30
nanoEsp32DetectsMultipleEsp32BoardsSerialPort ,
27
31
nanoEsp32SerialPort ,
@@ -32,6 +36,149 @@ import {
32
36
} from './fixtures' ;
33
37
34
38
describe ( 'board-list' , ( ) => {
39
+ describe ( 'boardList#labels' , ( ) => {
40
+ it ( 'should handle no selected board+port' , ( ) => {
41
+ const { labels } = createBoardList ( { } ) ;
42
+ const expected : BoardListLabels = {
43
+ boardLabel : selectBoard ,
44
+ portProtocol : undefined ,
45
+ selected : false ,
46
+ tooltip : selectBoard ,
47
+ } ;
48
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
49
+ } ) ;
50
+
51
+ it ( 'should handle port selected (port discovered)' , ( ) => {
52
+ const { labels } = createBoardList (
53
+ {
54
+ ...detectedPort ( unoSerialPort , uno ) ,
55
+ } ,
56
+ { selectedBoard : undefined , selectedPort : unoSerialPort }
57
+ ) ;
58
+ const expected : BoardListLabels = {
59
+ boardLabel : selectBoard ,
60
+ portProtocol : undefined ,
61
+ selected : false ,
62
+ tooltip : unoSerialPort . address ,
63
+ } ;
64
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
65
+ } ) ;
66
+
67
+ it ( 'should handle port selected (port not discovered)' , ( ) => {
68
+ const { labels } = createBoardList (
69
+ {
70
+ ...detectedPort ( mkr1000SerialPort , mkr1000 ) ,
71
+ } ,
72
+ { selectedBoard : undefined , selectedPort : unoSerialPort }
73
+ ) ;
74
+ const expected : BoardListLabels = {
75
+ boardLabel : selectBoard ,
76
+ portProtocol : undefined ,
77
+ selected : false ,
78
+ tooltip : `${ unoSerialPort . address } ${ notConnected } ` ,
79
+ } ;
80
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
81
+ } ) ;
82
+
83
+ it ( 'should handle board selected (with FQBN)' , ( ) => {
84
+ const { labels } = createBoardList (
85
+ { } ,
86
+ { selectedBoard : uno , selectedPort : undefined }
87
+ ) ;
88
+ const expected : BoardListLabels = {
89
+ boardLabel : uno . name ,
90
+ portProtocol : undefined ,
91
+ selected : false ,
92
+ tooltip : `${ uno . name } (${ uno . fqbn } )` ,
93
+ } ;
94
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
95
+ } ) ;
96
+
97
+ it ( 'should handle board selected (no FQBN)' , ( ) => {
98
+ const { labels } = createBoardList (
99
+ { } ,
100
+ {
101
+ selectedBoard : { name : 'my board' , fqbn : undefined } ,
102
+ selectedPort : undefined ,
103
+ }
104
+ ) ;
105
+ const expected : BoardListLabels = {
106
+ boardLabel : 'my board' ,
107
+ portProtocol : undefined ,
108
+ selected : false ,
109
+ tooltip : 'my board' ,
110
+ } ;
111
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
112
+ } ) ;
113
+
114
+ it ( 'should handle both selected (port not detected)' , ( ) => {
115
+ const { labels } = createBoardList (
116
+ {
117
+ ...detectedPort ( mkr1000SerialPort , mkr1000 ) ,
118
+ } ,
119
+ { selectedBoard : mkr1000 , selectedPort : unoSerialPort }
120
+ ) ;
121
+ const expected : BoardListLabels = {
122
+ boardLabel : mkr1000 . name ,
123
+ portProtocol : 'serial' ,
124
+ selected : false ,
125
+ tooltip : `${ mkr1000 . name } (${ mkr1000 . fqbn } )\n${ unoSerialPort . address } ${ notConnected } ` ,
126
+ } ;
127
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
128
+ } ) ;
129
+
130
+ it ( 'should handle both selected (board not discovered)' , ( ) => {
131
+ const { labels } = createBoardList (
132
+ {
133
+ ...detectedPort ( unoSerialPort , uno ) ,
134
+ } ,
135
+ { selectedBoard : mkr1000 , selectedPort : unoSerialPort }
136
+ ) ;
137
+ const expected : BoardListLabels = {
138
+ boardLabel : mkr1000 . name ,
139
+ portProtocol : 'serial' ,
140
+ selected : false ,
141
+ tooltip : `${ mkr1000 . name } (${ mkr1000 . fqbn } )\n${ unoSerialPort . address } ` ,
142
+ } ;
143
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
144
+ } ) ;
145
+
146
+ it ( 'should handle both selected (no FQBN)' , ( ) => {
147
+ const { labels } = createBoardList (
148
+ {
149
+ ...detectedPort ( unoSerialPort , { name : 'my board' , fqbn : undefined } ) ,
150
+ } ,
151
+ {
152
+ selectedBoard : { name : 'my board' , fqbn : undefined } ,
153
+ selectedPort : unoSerialPort ,
154
+ }
155
+ ) ;
156
+ const expected : BoardListLabels = {
157
+ boardLabel : 'my board' ,
158
+ portProtocol : 'serial' ,
159
+ selected : true ,
160
+ tooltip : `my board\n${ unoSerialPort . address } ` ,
161
+ } ;
162
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
163
+ } ) ;
164
+
165
+ it ( 'should handle both selected' , ( ) => {
166
+ const { labels } = createBoardList (
167
+ {
168
+ ...detectedPort ( mkr1000NetworkPort , mkr1000 ) ,
169
+ } ,
170
+ { selectedBoard : mkr1000 , selectedPort : mkr1000NetworkPort }
171
+ ) ;
172
+ const expected : BoardListLabels = {
173
+ boardLabel : mkr1000 . name ,
174
+ portProtocol : 'network' ,
175
+ selected : true ,
176
+ tooltip : `${ mkr1000 . name } (${ mkr1000 . fqbn } )\n${ mkr1000NetworkPort . address } ` ,
177
+ } ;
178
+ expect ( labels ) . to . be . deep . equal ( expected ) ;
179
+ } ) ;
180
+ } ) ;
181
+
35
182
describe ( 'createBoardList' , ( ) => {
36
183
it ( 'should sort the items deterministically' , ( ) => {
37
184
const { items } = createBoardList ( detectedPorts ) ;
0 commit comments