From 0a2f09766e4bca49339a08a0d2aa4efddd26f658 Mon Sep 17 00:00:00 2001 From: jahorton Date: Wed, 1 Apr 2020 09:55:43 +0700 Subject: [PATCH] fix(web/engine): unit-test check for saveStore --- web/source/dom/variableStoreCookieSerializer.ts | 8 ++++---- web/source/text/kbdInterface.ts | 10 +++++++++- web/source/text/processor.ts | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/web/source/dom/variableStoreCookieSerializer.ts b/web/source/dom/variableStoreCookieSerializer.ts index 91b4f91d80..92df4cc040 100644 --- a/web/source/dom/variableStoreCookieSerializer.ts +++ b/web/source/dom/variableStoreCookieSerializer.ts @@ -1,7 +1,7 @@ namespace com.keyman.dom { export class VariableStoreCookieSerializer implements text.VariableStoreSerializer { - loadStore(kbdName: string, storeName: string): text.VariableStore { - var cName='KeymanWeb_'+kbdName+'_Option_'+storeName; + loadStore(keyboardID: string, storeName: string): text.VariableStore { + var cName='KeymanWeb_'+keyboardID+'_Option_'+storeName; let map = com.keyman.singleton.util.loadCookie(cName) as text.VariableStore; if(typeof map[storeName] != 'undefined') { @@ -12,9 +12,9 @@ namespace com.keyman.dom { return map || {}; } - saveStore(kbdName: string, storeName: string, storeMap: text.VariableStore) { + saveStore(keyboardID: string, storeName: string, storeMap: text.VariableStore) { // The cookie entry includes the store name... - var cName='KeymanWeb_'+kbdName+'_Option_'+storeName; + var cName='KeymanWeb_'+keyboardID+'_Option_'+storeName; storeMap[storeName] = encodeURIComponent(storeMap[storeName]); // And the lookup under that entry looks for the value under the store name, again. diff --git a/web/source/text/kbdInterface.ts b/web/source/text/kbdInterface.ts index e59bdc635c..72f831b3f8 100644 --- a/web/source/text/kbdInterface.ts +++ b/web/source/text/kbdInterface.ts @@ -926,7 +926,15 @@ namespace com.keyman.text { // And the lookup under that entry looks for the value under the store name, again. let valueObj: VariableStore = {}; valueObj[storeName] = optValue; - this.ruleBehavior.saveStore[storeName] = valueObj; + + // Null-check in case of invocation during unit-test + if(this.ruleBehavior) { + this.ruleBehavior.saveStore[storeName] = valueObj; + } else { + // We're in a unit-test environment, directly invoking this method from outside of a keyboard. + // In this case, we should immediately commit the change. + this.variableStoreSerializer.saveStore(this.activeKeyboard.id, storeName, this.saveStore[storeName]); + } return true; } diff --git a/web/source/text/processor.ts b/web/source/text/processor.ts index 785f25dac3..c51d52964c 100644 --- a/web/source/text/processor.ts +++ b/web/source/text/processor.ts @@ -18,8 +18,8 @@ namespace com.keyman.text { export type LogMessageHandler = (str: string) => void; export interface VariableStoreSerializer { - loadStore(kbdName: string, storeName: string): VariableStore; - saveStore(kbdName: string, storeName: string, storeMap: VariableStore); + loadStore(keyboardID: string, storeName: string): VariableStore; + saveStore(keyboardID: string, storeName: string, storeMap: VariableStore); } export interface ProcessorInitOptions {