dismiss compile error notification on successful compile

If we got a successful compile, then the error is no longer applicable.
This commit is contained in:
David Lechner
2021-01-19 17:20:56 -06:00
parent 9033659c76
commit 2ff5ce9852
2 changed files with 35 additions and 1 deletions
+29 -1
View File
@@ -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();
},
);
+6
View File
@@ -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);