From b7061f63b4f45424c207dde272212febadb6b8bb Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 30 Jan 2021 12:49:43 -0600 Subject: [PATCH] add tests for firmware reducers --- src/firmware/reducers.test.ts | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/firmware/reducers.test.ts diff --git a/src/firmware/reducers.test.ts b/src/firmware/reducers.test.ts new file mode 100644 index 00000000..c47b0f04 --- /dev/null +++ b/src/firmware/reducers.test.ts @@ -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; + +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); +});