mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
This adds actions that are triggered when the device info service characteristics are read.
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2021 The Pybricks Authors
|
|
|
|
import { Action } from '../actions';
|
|
import {
|
|
BleDeviceDidFailToConnectReason,
|
|
connect,
|
|
didConnect,
|
|
didDisconnect,
|
|
didFailToConnect,
|
|
didFailToDisconnect,
|
|
disconnect,
|
|
} from './actions';
|
|
import reducers, { BleConnectionState } from './reducers';
|
|
|
|
type State = ReturnType<typeof reducers>;
|
|
|
|
test('initial state', () => {
|
|
expect(reducers(undefined, {} as Action)).toMatchInlineSnapshot(`
|
|
Object {
|
|
"connection": "ble.connection.state.disconnected",
|
|
}
|
|
`);
|
|
});
|
|
|
|
test('connection', () => {
|
|
expect(
|
|
reducers({ connection: BleConnectionState.Disconnected } as State, connect())
|
|
.connection,
|
|
).toBe(BleConnectionState.Connecting);
|
|
expect(
|
|
reducers({ connection: BleConnectionState.Connecting } as State, didConnect())
|
|
.connection,
|
|
).toBe(BleConnectionState.Connected);
|
|
expect(
|
|
reducers(
|
|
{ connection: BleConnectionState.Connecting } as State,
|
|
didFailToConnect({} as BleDeviceDidFailToConnectReason),
|
|
).connection,
|
|
).toBe(BleConnectionState.Disconnected);
|
|
expect(
|
|
reducers({ connection: BleConnectionState.Connected } as State, disconnect())
|
|
.connection,
|
|
).toBe(BleConnectionState.Disconnecting);
|
|
expect(
|
|
reducers(
|
|
{ connection: BleConnectionState.Disconnecting } as State,
|
|
didDisconnect(),
|
|
).connection,
|
|
).toBe(BleConnectionState.Disconnected);
|
|
expect(
|
|
reducers(
|
|
{ connection: BleConnectionState.Disconnecting } as State,
|
|
didFailToDisconnect(),
|
|
).connection,
|
|
).toBe(BleConnectionState.Connected);
|
|
});
|