mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
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:
@@ -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();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user