Skip to content

Commit 324f361

Browse files
author
Akos Kitta
committed
fix: startup task arg changes on data store change
Signed-off-by: Akos Kitta <[email protected]>
1 parent 81f48ca commit 324f361

File tree

3 files changed

+161
-11
lines changed

3 files changed

+161
-11
lines changed

arduino-ide-extension/src/browser/boards/boards-data-store.ts

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ export class BoardsDataStore
9191
this.fireChanged(...changes);
9292
}
9393
}),
94+
this.onDidChange((event) => {
95+
const selectedFqbn =
96+
this.boardsServiceProvider.boardsConfig.selectedBoard?.fqbn;
97+
if (event.changes.find((change) => change.fqbn === selectedFqbn)) {
98+
this.updateSelectedBoardData(selectedFqbn);
99+
}
100+
}),
94101
]);
95102

96103
Promise.all([

arduino-ide-extension/src/node/boards-service-impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
BoardWithPackage,
1111
BoardsPackage,
1212
BoardsService,
13+
CheckDebugEnabledParams,
1314
ConfigOption,
1415
ConfigValue,
15-
CheckDebugEnabledParams,
1616
DetectedPorts,
1717
Installable,
1818
NotificationServiceServer,

arduino-ide-extension/src/test/browser/boards-data-store.test.ts

+153-10
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('boards-data-store', function () {
8484
it('should update board details of selected board (selected with FQBN)', async () => {
8585
const updated = boardsServiceProvider.updateConfig(board);
8686
expect(updated).to.be.ok;
87-
await wait(50);
87+
await wait(1);
8888

8989
const selectedBoardData = boardsDataStore['_selectedBoardData'];
9090
expect(selectedBoardData).to.be.deep.equal({
@@ -102,7 +102,7 @@ describe('boards-data-store', function () {
102102
const board = { name, fqbn };
103103
const updated = boardsServiceProvider.updateConfig(board);
104104
expect(updated).to.ok;
105-
await wait(50);
105+
await wait(1);
106106

107107
const selectedBoardData = boardsDataStore['_selectedBoardData'];
108108
expect(selectedBoardData).to.be.undefined;
@@ -111,7 +111,7 @@ describe('boards-data-store', function () {
111111
it('should unset the the board details of selected board when no board was selected', async () => {
112112
let updated = boardsServiceProvider.updateConfig(board);
113113
expect(updated).to.ok;
114-
await wait(50);
114+
await wait(1);
115115

116116
let selectedBoardData = boardsDataStore['_selectedBoardData'];
117117
expect(selectedBoardData).to.be.deep.equal({
@@ -124,18 +124,18 @@ describe('boards-data-store', function () {
124124

125125
updated = boardsServiceProvider.updateConfig('unset-board');
126126
expect(updated).to.be.true;
127-
await wait(50);
127+
await wait(1);
128128

129129
selectedBoardData = boardsDataStore['_selectedBoardData'];
130130
expect(selectedBoardData).to.be.undefined;
131131
});
132132

133133
it('should provide startup tasks when the data is available for the selected board', async () => {
134-
const updated = boardsServiceProvider.updateConfig(board);
134+
let updated = boardsServiceProvider.updateConfig(board);
135135
expect(updated).to.be.true;
136-
await wait(50);
136+
await wait(1);
137137

138-
const tasks = boardsDataStore.tasks();
138+
let tasks = boardsDataStore.tasks();
139139
expect(tasks).to.be.deep.equal([
140140
{
141141
command: 'arduino-use-inherited-boards-data',
@@ -150,13 +150,156 @@ describe('boards-data-store', function () {
150150
],
151151
},
152152
]);
153+
154+
updated = boardsServiceProvider.updateConfig('unset-board');
155+
expect(updated).to.be.true;
156+
await wait(1);
157+
158+
tasks = boardsDataStore.tasks();
159+
expect(tasks).to.be.empty;
153160
});
154161

155162
it('should not provide any startup tasks when no data is available for the selected board', async () => {
156163
const tasks = boardsDataStore.tasks();
157164
expect(tasks).to.be.empty;
158165
});
159166

167+
it('should update the startup task arg when the selected programmer changes', async () => {
168+
let tasks = boardsDataStore.tasks();
169+
expect(tasks).to.be.empty;
170+
171+
let data = await boardsDataStore.getData(fqbn);
172+
expect(data).to.be.deep.equal({
173+
configOptions: [configOption1],
174+
programmers: [edbg, jlink],
175+
});
176+
177+
const updated = boardsServiceProvider.updateConfig(board);
178+
expect(updated).to.be.ok;
179+
await wait(1);
180+
181+
tasks = boardsDataStore.tasks();
182+
expect(tasks).to.be.deep.equal([
183+
{
184+
command: 'arduino-use-inherited-boards-data',
185+
args: [
186+
{
187+
fqbn,
188+
data: {
189+
configOptions: [configOption1],
190+
programmers: [edbg, jlink],
191+
},
192+
},
193+
],
194+
},
195+
]);
196+
197+
const result = await boardsDataStore.selectProgrammer({
198+
fqbn,
199+
selectedProgrammer: edbg,
200+
});
201+
expect(result).to.be.ok;
202+
203+
data = await boardsDataStore.getData(fqbn);
204+
expect(data).to.be.deep.equal({
205+
configOptions: [configOption1],
206+
programmers: [edbg, jlink],
207+
selectedProgrammer: edbg,
208+
});
209+
tasks = boardsDataStore.tasks();
210+
expect(tasks).to.be.deep.equal([
211+
{
212+
command: 'arduino-use-inherited-boards-data',
213+
args: [
214+
{
215+
fqbn,
216+
data: {
217+
configOptions: [configOption1],
218+
programmers: [edbg, jlink],
219+
selectedProgrammer: edbg,
220+
},
221+
},
222+
],
223+
},
224+
]);
225+
});
226+
227+
it('should update the startup task arg when the config options change', async () => {
228+
let tasks = boardsDataStore.tasks();
229+
expect(tasks).to.be.empty;
230+
231+
let data = await boardsDataStore.getData(fqbn);
232+
expect(data).to.be.deep.equal({
233+
configOptions: [configOption1],
234+
programmers: [edbg, jlink],
235+
});
236+
237+
const updated = boardsServiceProvider.updateConfig(board);
238+
expect(updated).to.be.ok;
239+
await wait(1);
240+
241+
tasks = boardsDataStore.tasks();
242+
expect(tasks).to.be.deep.equal([
243+
{
244+
command: 'arduino-use-inherited-boards-data',
245+
args: [
246+
{
247+
fqbn,
248+
data: {
249+
configOptions: [configOption1],
250+
programmers: [edbg, jlink],
251+
},
252+
},
253+
],
254+
},
255+
]);
256+
257+
const result = await boardsDataStore.selectConfigOption({
258+
fqbn,
259+
option: configOption1.option,
260+
selectedValue: configOption1.values[1].value,
261+
});
262+
expect(result).to.be.ok;
263+
264+
data = await boardsDataStore.getData(fqbn);
265+
expect(data).to.be.deep.equal({
266+
configOptions: [
267+
{
268+
...configOption1,
269+
values: [
270+
{ label: 'C1V1', selected: false, value: 'v1' },
271+
{ label: 'C1V2', selected: true, value: 'v2' },
272+
],
273+
},
274+
],
275+
programmers: [edbg, jlink],
276+
});
277+
278+
tasks = boardsDataStore.tasks();
279+
expect(tasks).to.be.deep.equal([
280+
{
281+
command: 'arduino-use-inherited-boards-data',
282+
args: [
283+
{
284+
fqbn,
285+
data: {
286+
configOptions: [
287+
{
288+
...configOption1,
289+
values: [
290+
{ label: 'C1V1', selected: false, value: 'v1' },
291+
{ label: 'C1V2', selected: true, value: 'v2' },
292+
],
293+
},
294+
],
295+
programmers: [edbg, jlink],
296+
},
297+
},
298+
],
299+
},
300+
]);
301+
});
302+
160303
it('should select the default programmer', async () => {
161304
const storedData = await getStoredData(fqbn);
162305
expect(storedData).to.be.undefined;
@@ -349,7 +492,7 @@ describe('boards-data-store', function () {
349492
boardsDataStore.onDidChange(() => didChangeCounter++)
350493
);
351494
notificationCenter.notifyPlatformDidInstall({ item: boardsPackage });
352-
await wait(50);
495+
await wait(1);
353496
expect(didChangeCounter).to.be.equal(0);
354497

355498
storedData = await getStoredData(fqbn);
@@ -369,7 +512,7 @@ describe('boards-data-store', function () {
369512
boardsDataStore.onDidChange(() => didChangeCounter++)
370513
);
371514
notificationCenter.notifyPlatformDidInstall({ item: boardsPackage });
372-
await wait(50);
515+
await wait(1);
373516
expect(didChangeCounter).to.be.equal(1);
374517

375518
storedData = await getStoredData(fqbn);
@@ -402,7 +545,7 @@ describe('boards-data-store', function () {
402545
boardsDataStore.onDidChange(() => didChangeCounter++)
403546
);
404547
notificationCenter.notifyPlatformDidInstall({ item: boardsPackage });
405-
await wait(50);
548+
await wait(1);
406549
expect(didChangeCounter).to.be.equal(1);
407550

408551
storedData = await boardsDataStore.getData(fqbn);

0 commit comments

Comments
 (0)