From 994540e2637d539646fb7d26313b112fba76bcb7 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 26 Feb 2022 12:55:49 -0600 Subject: [PATCH] actions: fix missed refactoring Missed some renames when refactoring that weren't picked up locally for some reason. --- src/firmware/sagas.test.ts | 15 +++++++-------- src/notifications/sagas.test.ts | 8 ++++---- test/index.ts | 16 ++++++++-------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/firmware/sagas.test.ts b/src/firmware/sagas.test.ts index 23046fd0..a7102b57 100644 --- a/src/firmware/sagas.test.ts +++ b/src/firmware/sagas.test.ts @@ -10,7 +10,6 @@ import JSZip from 'jszip'; import { AsyncSaga } from '../../test'; import { BootloaderConnectionFailureReason, - BootloaderProgramRequestAction, checksumRequest, checksumResponse, connect, @@ -160,7 +159,7 @@ describe('flashFirmware', () => { programRequest(++id, 0x08005000 + offset, dummyPayload), ); expect( - (action as BootloaderProgramRequestAction).payload.byteLength, + (action as ReturnType).payload.byteLength, ).toBe(Math.min(14, totalFirmwareSize - offset)); saga.put(didRequest(id)); @@ -1092,7 +1091,7 @@ describe('flashFirmware', () => { programRequest(++id, 0x08005000 + offset, dummyPayload), ); expect( - (action as BootloaderProgramRequestAction).payload.byteLength, + (action as ReturnType).payload.byteLength, ).toBe(Math.min(14, totalFirmwareSize - offset)); saga.put(didRequest(id)); @@ -1242,7 +1241,7 @@ describe('flashFirmware', () => { programRequest(++id, 0x08005000 + offset, dummyPayload), ); expect( - (action as BootloaderProgramRequestAction).payload.byteLength, + (action as ReturnType).payload.byteLength, ).toBe(Math.min(14, totalFirmwareSize - offset)); saga.put(didRequest(id)); @@ -1395,7 +1394,7 @@ describe('flashFirmware', () => { programRequest(++id, 0x08005000 + offset, dummyPayload), ); expect( - (action as BootloaderProgramRequestAction).payload.byteLength, + (action as ReturnType).payload.byteLength, ).toBe(Math.min(14, totalFirmwareSize - offset)); saga.put(didRequest(id)); @@ -1924,9 +1923,9 @@ describe('flashFirmware', () => { expect(action).toEqual( programRequest(++id, 0x08005000 + offset, dummyPayload), ); - expect((action as BootloaderProgramRequestAction).payload.byteLength).toBe( - Math.min(14, totalFirmwareSize - offset), - ); + expect( + (action as ReturnType).payload.byteLength, + ).toBe(Math.min(14, totalFirmwareSize - offset)); saga.put(didRequest(id)); diff --git a/src/notifications/sagas.test.ts b/src/notifications/sagas.test.ts index e555cf25..01c385e1 100644 --- a/src/notifications/sagas.test.ts +++ b/src/notifications/sagas.test.ts @@ -7,8 +7,8 @@ import { FirmwareReaderErrorCode, firmwareVersion, } from '@pybricks/firmware'; +import { AnyAction } from 'redux'; import { AsyncSaga } from '../../test'; -import { Action } from '../actions'; import { didCheckForUpdate } from '../app/actions'; import { bleDIServiceDidReceiveFirmwareRevision } from '../ble-device-info-service/actions'; import { @@ -90,7 +90,7 @@ test.each([ fileStorageDidFailToInitialize(new Error('test error')), fileStorageDidFailToReadFile('test.file', new Error('test error')), fileStorageDidFailToWriteFile('test.file', new Error('test error')), -])('actions that should show notification: %o', async (action: Action) => { +])('actions that should show notification: %o', async (action: AnyAction) => { const getToasts = jest.fn().mockReturnValue([]); const show = jest.fn(); const dismiss = jest.fn(); @@ -122,7 +122,7 @@ test.each([ didCheckForUpdate(true), bleDIServiceDidReceiveFirmwareRevision(firmwareVersion), didFailToSaveAs(new DOMException('test message', 'AbortError')), -])('actions that should not show a notification: %o', async (action: Action) => { +])('actions that should not show a notification: %o', async (action: AnyAction) => { const getToasts = jest.fn().mockReturnValue([]); const show = jest.fn(); const dismiss = jest.fn(); @@ -149,7 +149,7 @@ test.each([ test.each([[didCompile(new Uint8Array()), MessageId.MpyError]])( 'actions that should close a notification: %o', - async (action: Action, key: string) => { + async (action: AnyAction, key: string) => { const getToasts = jest.fn().mockReturnValue([]); const show = jest.fn(); const dismiss = jest.fn(); diff --git a/test/index.ts b/test/index.ts index 6451e979..d8c23537 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2020 The Pybricks Authors +import { AnyAction } from 'redux'; import { END, MulticastChannel, Saga, Task, runSaga, stdChannel } from 'redux-saga'; -import { Action } from '../src/actions'; import { RootState } from '../src/reducers'; type RecursivePartial = { @@ -10,9 +10,9 @@ type RecursivePartial = { }; export class AsyncSaga { - private channel: MulticastChannel; - private dispatches: (Action | END)[]; - private takers: { put: (action: Action | END) => void }[]; + private channel: MulticastChannel; + private dispatches: (AnyAction | END)[]; + private takers: { put: (action: AnyAction | END) => void }[]; private state: RecursivePartial; private task: Task; @@ -43,18 +43,18 @@ export class AsyncSaga { return this.dispatches.length; } - public put(action: Action): void { + public put(action: AnyAction): void { this.channel.put(action); } - public take(): Promise { + public take(): Promise { const next = this.dispatches.shift(); if (next === undefined) { // if there are no dispatches queued, then queue the taker to be // completed later return new Promise((resolve, reject) => { this.takers.push({ - put: (a: Action | END): void => { + put: (a: AnyAction | END): void => { if (a.type === END.type) { reject(); } else { @@ -88,7 +88,7 @@ export class AsyncSaga { } } - private dispatch(action: Action | END): Action | END { + private dispatch(action: AnyAction | END): AnyAction | END { const taker = this.takers.shift(); if (taker === undefined) { // if there are no takers waiting, the queue the action