mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
use new app startup action in terminal sagas
This commit is contained in:
committed by
David Lechner
parent
72a90df92a
commit
3f80374215
@@ -3,6 +3,7 @@
|
||||
|
||||
import { AsyncSaga, delay } from '../../test';
|
||||
|
||||
import { startup } from '../actions/app';
|
||||
import {
|
||||
BleUartActionType,
|
||||
BleUartWriteAction,
|
||||
@@ -30,9 +31,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('normal message - no status', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
// sending ASCII space character
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Unknown } });
|
||||
saga.put(notify(new DataView(new Uint8Array([0x20]).buffer)));
|
||||
@@ -47,9 +45,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('checksum message', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Loading } });
|
||||
saga.put(notify(new DataView(new Uint8Array([0xaa]).buffer)));
|
||||
|
||||
@@ -63,9 +58,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('idle message', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
// '>>>> IDLE'
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Unknown } });
|
||||
saga.put(
|
||||
@@ -98,9 +90,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('idle message with extra text', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
// '0>>>> IDLE1'
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Unknown } });
|
||||
saga.put(
|
||||
@@ -145,9 +134,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('error message', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
// '>>>> ERROR'
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Unknown } });
|
||||
saga.put(
|
||||
@@ -181,9 +167,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('error message with extra text', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
// '0>>>> ERROR1'
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Unknown } });
|
||||
saga.put(
|
||||
@@ -229,9 +212,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('running message', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
// '>>>> ERROR'
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Unknown } });
|
||||
saga.put(
|
||||
@@ -267,9 +247,6 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('running message with extra text', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
// '0>>>> RUNNING1'
|
||||
saga.setState({ hub: { runtime: HubRuntimeState.Unknown } });
|
||||
saga.put(
|
||||
@@ -318,6 +295,7 @@ describe('Data receiver filters out hub status', () => {
|
||||
test('Terminal data source responds to send data actions', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
saga.put(startup());
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
@@ -344,10 +322,6 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
test('basic function works', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
// set data source is always first action so we have to take it
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
|
||||
const action = await saga.take();
|
||||
@@ -360,10 +334,6 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
test('messages are queued until previous has completed', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
// set data source is always first action so we have to take it
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
await delay(50); // without delay, messages are combined
|
||||
saga.put(receiveData('test1234'));
|
||||
@@ -392,10 +362,6 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
test('messages are queued until previous has failed', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
// set data source is always first action so we have to take it
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
await delay(50); // without delay, messages are combined
|
||||
saga.put(receiveData('test1234'));
|
||||
@@ -426,10 +392,6 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
test('small messages are combined', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
// set data source is always first action so we have to take it
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
saga.put(receiveData('test1234'));
|
||||
saga.put(receiveData('test1234'));
|
||||
|
||||
@@ -445,10 +407,6 @@ describe('Terminal data source responds to receive data actions', () => {
|
||||
test('long messages are split', async () => {
|
||||
const saga = new AsyncSaga(terminal);
|
||||
|
||||
// set data source is always first action so we have to take it
|
||||
const dataSourceAction = await saga.take();
|
||||
expect(dataSourceAction.type).toBe(TerminalActionType.SetDataSource);
|
||||
|
||||
saga.put(receiveData('012345678901234567890123456789'));
|
||||
|
||||
const action = await saga.take();
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
} from 'redux-saga/effects';
|
||||
import PushStream from 'zen-push';
|
||||
import { Action } from '../actions';
|
||||
import { AppActionType, AppStartupAction } from '../actions/app';
|
||||
import {
|
||||
BleUartActionType,
|
||||
BleUartNotifyAction,
|
||||
@@ -35,6 +36,10 @@ const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
const terminalDataSource = new PushStream<string>();
|
||||
|
||||
function* startup(_action: AppStartupAction): Generator {
|
||||
yield put(setDataSource(terminalDataSource.observable));
|
||||
}
|
||||
|
||||
function* handleMatch(
|
||||
match: RegExpMatchArray | null,
|
||||
status: HubRuntimeStatusType,
|
||||
@@ -141,8 +146,8 @@ function sendTerminalData(action: TerminalDataReceiveDataAction): void {
|
||||
}
|
||||
|
||||
export default function* (): Generator {
|
||||
yield takeEvery(AppActionType.Startup, startup);
|
||||
yield takeEvery(BleUartActionType.Notify, receiveUartData);
|
||||
yield fork(receiveTerminalData);
|
||||
yield takeEvery(TerminalActionType.SendData, sendTerminalData);
|
||||
yield put(setDataSource(terminalDataSource.observable));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user