-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathboards-auto-installer.test.ts
247 lines (229 loc) · 9.2 KB
/
boards-auto-installer.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
// const disableJSDOM = enableJSDOM();
// import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
// import { ApplicationProps } from '@theia/application-package/lib/application-props';
// FrontendApplicationConfigProvider.set({
// ...ApplicationProps.DEFAULT.frontend.config,
// });
// import { MessageService } from '@theia/core';
// import { BoardsServiceProvider } from '../../browser/boards/boards-service-provider';
// import { BoardsListWidgetFrontendContribution } from '../../browser/boards/boards-widget-frontend-contribution';
// import {
// Board,
// BoardsPackage,
// BoardsService,
// Port,
// ResponseServiceArduino,
// } from '../../common/protocol';
// import { IMock, It, Mock, Times } from 'typemoq';
// import { Container, ContainerModule } from 'inversify';
// import { BoardsAutoInstaller } from '../../browser/boards/boards-auto-installer';
// import { BoardsConfig } from '../../browser/boards/boards-config';
// import { tick } from '../utils';
// import { ListWidget } from '../../browser/widgets/component-list/list-widget';
// disableJSDOM();
// const aBoard: Board = {
// fqbn: 'some:board:fqbn',
// name: 'Some Arduino Board',
// port: { address: '/lol/port1234', protocol: 'serial' },
// };
// const aPort: Port = {
// address: aBoard.port!.address,
// protocol: aBoard.port!.protocol,
// };
// const aBoardConfig: BoardsConfig.Config = {
// selectedBoard: aBoard,
// selectedPort: aPort,
// };
// const aPackage: BoardsPackage = {
// author: 'someAuthor',
// availableVersions: ['some.ver.sion', 'some.other.version'],
// boards: [aBoard],
// deprecated: false,
// description: 'Some Arduino Board, Some Other Arduino Board',
// id: 'some:arduinoCoreId',
// installable: true,
// moreInfoLink: 'http://www.some-url.lol/',
// name: 'Some Arduino Package',
// summary: 'Boards included in this package:',
// };
// const anInstalledPackage: BoardsPackage = {
// ...aPackage,
// installedVersion: 'some.ver.sion',
// };
// describe('BoardsAutoInstaller', () => {
// let subject: BoardsAutoInstaller;
// let messageService: IMock<MessageService>;
// let boardsService: IMock<BoardsService>;
// let boardsServiceClient: IMock<BoardsServiceProvider>;
// let responseService: IMock<ResponseServiceArduino>;
// let boardsManagerFrontendContribution: IMock<BoardsListWidgetFrontendContribution>;
// let boardsManagerWidget: IMock<ListWidget<BoardsPackage>>;
// let testContainer: Container;
// beforeEach(() => {
// testContainer = new Container();
// messageService = Mock.ofType<MessageService>();
// boardsService = Mock.ofType<BoardsService>();
// boardsServiceClient = Mock.ofType<BoardsServiceProvider>();
// responseService = Mock.ofType<ResponseServiceArduino>();
// boardsManagerFrontendContribution =
// Mock.ofType<BoardsListWidgetFrontendContribution>();
// boardsManagerWidget = Mock.ofType<ListWidget<BoardsPackage>>();
// boardsManagerWidget.setup((b) =>
// b.refresh(aPackage.name.toLocaleLowerCase())
// );
// boardsManagerFrontendContribution
// .setup((b) => b.openView({ reveal: true }))
// .returns(async () => boardsManagerWidget.object);
// messageService
// .setup((m) => m.showProgress(It.isAny(), It.isAny()))
// .returns(async () => ({
// cancel: () => null,
// id: '',
// report: () => null,
// result: Promise.resolve(''),
// }));
// responseService
// .setup((r) => r.onProgressDidChange(It.isAny()))
// .returns(() => ({ dispose: () => null }));
// const module = new ContainerModule((bind) => {
// bind(BoardsAutoInstaller).toSelf();
// bind(MessageService).toConstantValue(messageService.object);
// bind(BoardsService).toConstantValue(boardsService.object);
// bind(BoardsServiceProvider).toConstantValue(boardsServiceClient.object);
// bind(ResponseServiceArduino).toConstantValue(responseService.object);
// bind(BoardsListWidgetFrontendContribution).toConstantValue(
// boardsManagerFrontendContribution.object
// );
// });
// testContainer.load(module);
// subject = testContainer.get(BoardsAutoInstaller);
// });
// context('when it starts', () => {
// it('should register to the BoardsServiceClient in order to check the packages every a new board is plugged in', () => {
// subject.onStart();
// boardsServiceClient.verify(
// (b) => b.onBoardsConfigChanged(It.isAny()),
// Times.once()
// );
// });
// context('and it checks the installable packages', () => {
// context(`and a port and a board a selected`, () => {
// beforeEach(() => {
// boardsServiceClient
// .setup((b) => b.boardsConfig)
// .returns(() => aBoardConfig);
// });
// context('if no package for the board is already installed', () => {
// context('if a candidate package for the board is found', () => {
// beforeEach(() => {
// boardsService
// .setup((b) => b.search(It.isValue({})))
// .returns(async () => [aPackage]);
// });
// it('should show a notification suggesting to install that package', async () => {
// messageService
// .setup((m) =>
// m.info(It.isAnyString(), It.isAnyString(), It.isAnyString())
// )
// .returns(() => Promise.resolve('Install Manually'));
// subject.onStart();
// await tick();
// messageService.verify(
// (m) =>
// m.info(It.isAnyString(), It.isAnyString(), It.isAnyString()),
// Times.once()
// );
// });
// context(`if the answer to the message is 'Yes'`, () => {
// beforeEach(() => {
// messageService
// .setup((m) =>
// m.info(It.isAnyString(), It.isAnyString(), It.isAnyString())
// )
// .returns(() => Promise.resolve('Yes'));
// });
// it('should install the package', async () => {
// subject.onStart();
// await tick();
// messageService.verify(
// (m) => m.showProgress(It.isAny(), It.isAny()),
// Times.once()
// );
// });
// });
// context(
// `if the answer to the message is 'Install Manually'`,
// () => {
// beforeEach(() => {
// messageService
// .setup((m) =>
// m.info(
// It.isAnyString(),
// It.isAnyString(),
// It.isAnyString()
// )
// )
// .returns(() => Promise.resolve('Install Manually'));
// });
// it('should open the boards manager widget', () => {
// subject.onStart();
// });
// }
// );
// });
// context('if a candidate package for the board is not found', () => {
// beforeEach(() => {
// boardsService
// .setup((b) => b.search(It.isValue({})))
// .returns(async () => []);
// });
// it('should do nothing', async () => {
// subject.onStart();
// await tick();
// messageService.verify(
// (m) =>
// m.info(It.isAnyString(), It.isAnyString(), It.isAnyString()),
// Times.never()
// );
// });
// });
// });
// context(
// 'if one of the packages for the board is already installed',
// () => {
// beforeEach(() => {
// boardsService
// .setup((b) => b.search(It.isValue({})))
// .returns(async () => [aPackage, anInstalledPackage]);
// messageService
// .setup((m) =>
// m.info(It.isAnyString(), It.isAnyString(), It.isAnyString())
// )
// .returns(() => Promise.resolve('Yes'));
// });
// it('should do nothing', async () => {
// subject.onStart();
// await tick();
// messageService.verify(
// (m) =>
// m.info(It.isAnyString(), It.isAnyString(), It.isAnyString()),
// Times.never()
// );
// });
// }
// );
// });
// context('and there is no selected board or port', () => {
// it('should do nothing', async () => {
// subject.onStart();
// await tick();
// messageService.verify(
// (m) => m.info(It.isAnyString(), It.isAnyString(), It.isAnyString()),
// Times.never()
// );
// });
// });
// });
// });
// });