add tests for firmware reducers

This commit is contained in:
David Lechner
2021-02-01 10:26:05 -06:00
parent 6ed5dca8ce
commit b7061f63b4
+39
View File
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 The Pybricks Authors
import { Action } from '../actions';
import {
FailToFinishReasonType,
didFailToFinish,
didFinish,
didProgress,
didStart,
} from './actions';
import reducers from './reducers';
type State = ReturnType<typeof reducers>;
test('initial state', () => {
expect(reducers(undefined, {} as Action)).toMatchInlineSnapshot(`
Object {
"flashing": false,
"progress": null,
}
`);
});
test('flashing', () => {
expect(reducers({ flashing: false } as State, didStart()).flashing).toBe(true);
expect(reducers({ flashing: true } as State, didFinish()).flashing).toBe(false);
expect(
reducers(
{ flashing: true } as State,
didFailToFinish(FailToFinishReasonType.TimedOut),
).flashing,
).toBe(false);
});
test('progress', () => {
expect(reducers({ progress: 1 } as State, didStart()).progress).toBe(null);
expect(reducers({ progress: null } as State, didProgress(1)).progress).toBe(1);
});