@robotical/martyblocksjr 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/martyblocksjr",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "ScratchJr",
5
5
  "repository": {
6
6
  "type": "git",
@@ -197,6 +197,51 @@ describe('Marty connection UI', () => {
197
197
  expect(button.classList.contains('connectButtonConnected')).toBe(false);
198
198
  expect(button.querySelector('.iconButtonContainer').classList.contains('notConnectedButtonContainer')).toBe(true);
199
199
  });
200
+
201
+ it('clears the Marty button after confirmed host-context removal without waiting for the RAFT event', async () => {
202
+ const button = createConnectionButton();
203
+ const oldOnClick = vi.fn();
204
+ button.onclick = oldOnClick;
205
+ const raft = createMartyRaft();
206
+ window.applicationManager.connectedRaftsContext = [{ id: raft.id }];
207
+ window.applicationManager.disconnectGeneric = vi.fn(() => {
208
+ window.applicationManager.connectedRaftsContext = [];
209
+ });
210
+
211
+ UI.setupMartyConnectionButton(button, raft);
212
+
213
+ button.onclick();
214
+ await Promise.resolve();
215
+ vi.advanceTimersByTime(1000);
216
+
217
+ expect(window.applicationManager.disconnectGeneric).toHaveBeenCalledWith(raft);
218
+ expect(window.martyManager.removeMarty).toHaveBeenCalledWith(raft);
219
+ expect(button.onclick).toBe(oldOnClick);
220
+ expect(button.classList.contains('connectButtonConnected')).toBe(false);
221
+ expect(button.querySelector('.iconButtonContainer').classList.contains('notConnectedButtonContainer')).toBe(true);
222
+ expect(raft.__disconnectedUnsubscribed).toBe(true);
223
+ });
224
+
225
+ it('keeps the Marty button connected when the disconnect confirmation is cancelled', async () => {
226
+ const button = createConnectionButton();
227
+ const oldOnClick = vi.fn();
228
+ button.onclick = oldOnClick;
229
+ const raft = createMartyRaft();
230
+ window.applicationManager.connectedRaftsContext = [{ id: raft.id }];
231
+ window.applicationManager.disconnectGeneric = vi.fn();
232
+
233
+ UI.setupMartyConnectionButton(button, raft);
234
+
235
+ button.onclick();
236
+ vi.advanceTimersByTime(31000);
237
+ await Promise.resolve();
238
+
239
+ expect(window.applicationManager.disconnectGeneric).toHaveBeenCalledWith(raft);
240
+ expect(window.martyManager.removeMarty).not.toHaveBeenCalled();
241
+ expect(button.onclick).not.toBe(oldOnClick);
242
+ expect(button.classList.contains('connectButtonConnected')).toBe(true);
243
+ expect(button.querySelector('.iconButtonContainer').classList.contains('connectedButtonContainer')).toBe(true);
244
+ });
200
245
  });
201
246
 
202
247
  function createMartyRaft() {