From 2ff5ce9852be77e0e0f4586b10eebf821922be5f Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 19 Jan 2021 10:32:21 -0600 Subject: [PATCH] dismiss compile error notification on successful compile If we got a successful compile, then the error is no longer applicable. --- src/sagas/notification.test.ts | 30 +++++++++++++++++++++++++++++- src/sagas/notification.ts | 6 ++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/sagas/notification.test.ts b/src/sagas/notification.test.ts index 2838c9b2..86212272 100644 --- a/src/sagas/notification.test.ts +++ b/src/sagas/notification.test.ts @@ -13,9 +13,10 @@ import { BootloaderConnectionFailureReason, didFailToConnect as bootloaderDidFailToConnect, } from '../actions/lwp3-bootloader'; -import { didFailToCompile } from '../actions/mpy'; +import { didCompile, didFailToCompile } from '../actions/mpy'; import { add } from '../actions/notification'; import { didSucceed, didUpdate } from '../actions/service-worker'; +import { MessageId } from '../components/notification-i18n'; import notification from './notification'; test.each([ @@ -86,3 +87,30 @@ test.each([ await saga.end(); }); + +test.each([[didCompile(new Uint8Array()), MessageId.MpyError]])( + 'actions that should close a notification: %o', + async (action: Action, key: string) => { + const getToasts = jest.fn().mockReturnValue([]); + const show = jest.fn(); + const dismiss = jest.fn(); + const clear = jest.fn(); + + const toaster: IToaster = { + getToasts, + show, + dismiss, + clear, + }; + + const saga = new AsyncSaga(notification, { notification: { toaster } }); + + saga.put(action); + + expect(show).not.toBeCalled(); + expect(dismiss).toBeCalledWith(key); + expect(clear).not.toBeCalled(); + + await saga.end(); + }, +); diff --git a/src/sagas/notification.ts b/src/sagas/notification.ts index 23b60cbd..47ee3e5c 100644 --- a/src/sagas/notification.ts +++ b/src/sagas/notification.ts @@ -214,6 +214,11 @@ function* showEditorStorageChanged(): Generator { yield put(reloadProgram()); } +function* dismissCompilerError(): Generator { + const { toaster } = (yield getContext('notification')) as NotificationContext; + toaster.dismiss(MessageId.MpyError); +} + function* showCompilerError(action: MpyDidFailToCompileAction): Generator { yield* showSingleton(Level.Error, MessageId.MpyError, { errorMessage: action.err }); } @@ -263,6 +268,7 @@ export default function* (): Generator { showBootloaderDidFailToConnectError, ); yield takeEvery(EditorActionType.StorageChanged, showEditorStorageChanged); + yield takeEvery(MpyActionType.DidCompile, dismissCompilerError); yield takeEvery(MpyActionType.DidFailToCompile, showCompilerError); yield takeEvery(NotificationActionType.Add, addNotification); yield takeEvery(ServiceWorkerActionType.DidUpdate, showServiceWorkerUpdate);