fix(web/engine): unit-test check for saveStore

This commit is contained in:
jahorton 2020-04-01 09:55:43 +07:00
parent 680db25eff
commit 0a2f09766e
3 changed files with 15 additions and 7 deletions

View file

@ -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.

View file

@ -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;
}

View file

@ -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 {