mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-08 01:45:32 +00:00
fix(common/models): adjusts affected unit tests
This commit is contained in:
parent
2ce4d3ba87
commit
07f48bdc19
3 changed files with 33 additions and 1 deletions
|
|
@ -14,6 +14,12 @@ describe('LMLayer using dummy model', function () {
|
|||
it('will predict future suggestions', function () {
|
||||
var lmLayer = new LMLayer(capabilities());
|
||||
|
||||
var stripIDs = function(suggestions) {
|
||||
suggestions.forEach(function(suggestion) {
|
||||
delete suggestion.id;
|
||||
});
|
||||
}
|
||||
|
||||
// We're testing many as asynchronous messages in a row.
|
||||
// this would be cleaner using async/await syntax.
|
||||
// Not done yet, as this test case is a slightly-edited copy of the in-browser version.
|
||||
|
|
@ -25,15 +31,19 @@ describe('LMLayer using dummy model', function () {
|
|||
}).then(function () {
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[0]);
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[1]);
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[2]);
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[3]);
|
||||
lmLayer.shutdown();
|
||||
return Promise.resolve();
|
||||
|
|
|
|||
|
|
@ -17,8 +17,20 @@ describe('LMLayerWorker', function () {
|
|||
|
||||
// Initialize the worker with a model that will produce one suggestion.
|
||||
var fakePostMessage = sinon.fake();
|
||||
var filteredFakePostMessage = function(event) {
|
||||
if(event.message == 'suggestions') {
|
||||
let suggestions = event.suggestions;
|
||||
|
||||
// Strip any IDs set by the model compositor.
|
||||
suggestions.forEach(function(suggestion) {
|
||||
delete suggestion.id;
|
||||
});
|
||||
}
|
||||
|
||||
fakePostMessage(event);
|
||||
}
|
||||
var context = {
|
||||
postMessage: fakePostMessage
|
||||
postMessage: filteredFakePostMessage
|
||||
};
|
||||
context.importScripts = importScriptsWith(context);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ describe('LMLayer using dummy model', function () {
|
|||
// the WebWorker boundary, so we should be generous here.
|
||||
var lmLayer = new LMLayer(helpers.defaultCapabilities);
|
||||
|
||||
var stripIDs = function(suggestions) {
|
||||
suggestions.forEach(function(suggestion) {
|
||||
delete suggestion.id;
|
||||
});
|
||||
}
|
||||
|
||||
// We're testing many as asynchronous messages in a row.
|
||||
// this would be cleaner using async/await syntax, but
|
||||
// alas some of our browsers don't support it.
|
||||
|
|
@ -29,15 +35,19 @@ describe('LMLayer using dummy model', function () {
|
|||
}).then(function () {
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[0]);
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[1]);
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[2]);
|
||||
return lmLayer.predict(zeroTransform(), emptyContext());
|
||||
}).then(function (suggestions) {
|
||||
stripIDs(suggestions);
|
||||
assert.deepEqual(suggestions, iGotDistractedByHazel()[3]);
|
||||
lmLayer.shutdown();
|
||||
return Promise.resolve();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue