mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
strongly type MessageId
This way we can add tests to ensure proper mapping in .json
This commit is contained in:
committed by
David Lechner
parent
c373b3abc5
commit
5da915851c
@@ -1,15 +1,9 @@
|
||||
{
|
||||
"bootloader": {
|
||||
"connection": {
|
||||
"didConnect": {
|
||||
"cannotWriteWithoutResponse": "This web browser does not support Web Bluetooth Write Characteristic Without Response. Flashing firmware will take a long time."
|
||||
},
|
||||
"didFailToConnect": {
|
||||
"gattServiceNotFound": "Connected to hub but failed to get LEGO bootloader service. Try removing the \"LEGO Bootloader\" device in your OS Bluetooth settings, then try again.",
|
||||
"noWebBluetooth": "This web browser does not support Web Bluetooth or it is not enabled.",
|
||||
"unknown": "Unexpected error while trying to connect. Check console log and report the error."
|
||||
}
|
||||
}
|
||||
"ble": {
|
||||
"cannotWriteWithoutResponse": "This web browser does not support Web Bluetooth Write Characteristic Without Response. Flashing firmware will take a long time.",
|
||||
"gattServiceNotFound": "Connected to hub but failed to get LEGO bootloader service. Try removing the \"LEGO Bootloader\" device in your OS Bluetooth settings, then try again.",
|
||||
"noWebBluetooth": "This web browser does not support Web Bluetooth or it is not enabled.",
|
||||
"connectFailed": "Unexpected error while trying to connect. Check console log and report the error."
|
||||
},
|
||||
"serviceWorker": {
|
||||
"success": "Content is cached for offline use.",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
|
||||
import { MessageId } from '../reducers/notification';
|
||||
import en from './notification.en.json';
|
||||
|
||||
function lookup(obj: object, id: string): string | undefined {
|
||||
const value = id
|
||||
.split('.')
|
||||
.reduce((pv, cv) => pv && (pv as Record<string, object>)[cv], obj);
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
describe('Ensure .json file has matches for MessageIds', () => {
|
||||
test.each(Object.values(MessageId))('%s', (id) => {
|
||||
expect(lookup(en, id)).toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user