mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 18:46:17 +00:00
hub/sagas: fix error message not shown when starting repl
- Add check for repl start command success/fail. - Show error message on fail. - Rename start repl action. - Add new did start/did fail to start repl actions. - Change terminal saga to use did start repl action to focus terminal. - Add more tests.
This commit is contained in:
committed by
David Lechner
parent
70020275a7
commit
be3afa167a
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
// Copyright (c) 2020-2023 The Pybricks Authors
|
||||
|
||||
import PushStream from 'zen-push';
|
||||
import { AsyncSaga, delay } from '../../test';
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
didWrite,
|
||||
write,
|
||||
} from '../ble-nordic-uart-service/actions';
|
||||
import { checksum } from '../hub/actions';
|
||||
import { checksum, hubDidStartRepl } from '../hub/actions';
|
||||
import { HubRuntimeState } from '../hub/reducers';
|
||||
import { createCountFunc } from '../utils/iter';
|
||||
import { receiveData, sendData } from './actions';
|
||||
@@ -179,3 +179,16 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
await saga.end();
|
||||
});
|
||||
});
|
||||
|
||||
it('should focus terminal when repl is started', async () => {
|
||||
const dispatchEventSpy = jest.spyOn(window, 'dispatchEvent');
|
||||
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
saga.put(hubDidStartRepl());
|
||||
|
||||
// https://stackoverflow.com/a/64787979/1976323
|
||||
expect(dispatchEventSpy.mock.calls[0][0].type).toBe('pb-terminal-focus');
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
// Copyright (c) 2020-2023 The Pybricks Authors
|
||||
|
||||
import { AnyAction } from 'redux';
|
||||
import {
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
write,
|
||||
} from '../ble-nordic-uart-service/actions';
|
||||
import { nordicUartSafeTxCharLength } from '../ble-nordic-uart-service/protocol';
|
||||
import { checksum, repl } from '../hub/actions';
|
||||
import { checksum, hubDidStartRepl } from '../hub/actions';
|
||||
import { HubRuntimeState } from '../hub/reducers';
|
||||
import { RootState } from '../reducers';
|
||||
import { defined } from '../utils';
|
||||
@@ -109,7 +109,7 @@ function* sendTerminalData(action: ReturnType<typeof sendData>): Generator {
|
||||
dataSource.next(action.value);
|
||||
}
|
||||
|
||||
function handleRepl(): void {
|
||||
function handleHubDidStartRepl(): void {
|
||||
dispatchEvent(new CustomEvent('pb-terminal-focus'));
|
||||
}
|
||||
|
||||
@@ -117,5 +117,5 @@ export default function* (): Generator {
|
||||
yield* takeEvery(didNotify, receiveUartData);
|
||||
yield* fork(receiveTerminalData);
|
||||
yield* takeEvery(sendData, sendTerminalData);
|
||||
yield* takeEvery(repl, handleRepl);
|
||||
yield* takeEvery(hubDidStartRepl, handleHubDidStartRepl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user