mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-26 01:27:42 +00:00
Refactor: move global test helpers to unit_tests/helpers.js.
This commit is contained in:
parent
f2b1335c97
commit
bf60ea5e6d
5 changed files with 70 additions and 100 deletions
|
|
@ -114,33 +114,16 @@ describe('LMLayerWorker', function() {
|
|||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a MessageEvent (for inter-worker communication), with the given data payload.
|
||||
* @param {*} data
|
||||
*/
|
||||
function createMessageEventWithData(data) {
|
||||
return { data };
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecation warning: Soon, models will not be required to be passed as source code;
|
||||
* when this happens, tests should refrain from sending source code for the model
|
||||
* parameter.
|
||||
*/
|
||||
// TODO: Use dummyModel defined in unit_tests/helpers.js
|
||||
function dummyModel() {
|
||||
return 'return {model: {}, configuration: {}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns reasonable defaults for the default capabilities
|
||||
* to initialize the LMLayer.
|
||||
*/
|
||||
function defaultCapabilities() {
|
||||
return {
|
||||
maxLeftContextCodeUnits: 64
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last message received in a pretty string format.
|
||||
* @param {sinon.SinonFake} fakePostMessage
|
||||
|
|
|
|||
|
|
@ -206,41 +206,4 @@ describe('LMLayerWorker dummy model', function() {
|
|||
futureSuggestions[3]);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Capabilities of a keyboard that will ONLY send left-sided capabilities.
|
||||
* The keyboard does not support deleting to the right.
|
||||
*
|
||||
* @returns Capabilities
|
||||
*/
|
||||
function defaultCapabilities() {
|
||||
return {
|
||||
maxLeftContextCodeUnits: 64,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a transform that does nothing.
|
||||
*
|
||||
* @returns Transform
|
||||
*/
|
||||
function zeroTransform() {
|
||||
return {
|
||||
insert: '',
|
||||
deleteLeft: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a context of an empty buffer.
|
||||
*
|
||||
* @returns Context
|
||||
*/
|
||||
function emptyContext() {
|
||||
return {
|
||||
left: '',
|
||||
startOfBuffer: true,
|
||||
endOfBuffer: true
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -48,47 +48,4 @@ describe('LMLayerWorker', function () {
|
|||
sinon.restore();
|
||||
});
|
||||
});
|
||||
|
||||
// Helpers (TODO: factor out!)
|
||||
|
||||
/**
|
||||
* Creates a MessageEvent (for inter-worker communication), with the given data payload.
|
||||
* @param {*} data
|
||||
*/
|
||||
function createMessageEventWithData(data) {
|
||||
return { data };
|
||||
}
|
||||
|
||||
/**
|
||||
* A valid model that suggests exactly what you want it to suggest.
|
||||
*/
|
||||
function dummyModel(futureSuggestions) {
|
||||
return {
|
||||
type: 'dummy',
|
||||
futureSuggestions: futureSuggestions || []
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns reasonable defaults for the default capabilities
|
||||
* to initialize the LMLayer.
|
||||
*/
|
||||
function defaultCapabilities() {
|
||||
return {
|
||||
maxLeftContextCodeUnits: 64
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Context of an empty buffer; no text, at both the start and end of the buffer.
|
||||
*/
|
||||
function emptyContext() {
|
||||
return { left: '', startOfBuffer: true, endOfBuffer: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* This transform, when applied, makes no changes to the buffer.
|
||||
*/
|
||||
function zeroTransform() {
|
||||
return { insert: '', deleteLeft: 0 };
|
||||
}
|
||||
});
|
||||
|
|
|
|||
67
common/predictive-text/unit_tests/helpers.js
Normal file
67
common/predictive-text/unit_tests/helpers.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* @file helpers
|
||||
*
|
||||
* Globally-defined helper functions for use in in Mocha tests.
|
||||
*/
|
||||
|
||||
// Choose the appropriate global object. Either `global` in
|
||||
// Node, or `window` in browsers.
|
||||
var _ = global || window;
|
||||
|
||||
/**
|
||||
* Creates a MessageEvent (for inter-worker communication), with the given data payload.
|
||||
*
|
||||
* @param {*} data
|
||||
*/
|
||||
_.createMessageEventWithData = function createMessageEventWithData(data) {
|
||||
return { data };
|
||||
}
|
||||
|
||||
/**
|
||||
* A valid model that suggests exactly what you want it to suggest.
|
||||
*
|
||||
* @returns {ModelDescription}
|
||||
*/
|
||||
_.dummyModel = function dummyModel(futureSuggestions) {
|
||||
return {
|
||||
type: 'dummy',
|
||||
futureSuggestions: futureSuggestions || []
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Capabilities of a keyboard that will ONLY send left-sided capabilities.
|
||||
* The keyboard does not support deleting to the right.
|
||||
*
|
||||
* @returns {Capabilities}
|
||||
*/
|
||||
_.defaultCapabilities = function defaultCapabilities() {
|
||||
return {
|
||||
maxLeftContextCodeUnits: 64
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Context of an empty buffer; no text, at both the start and
|
||||
* end of the buffer.
|
||||
*
|
||||
* @returns {Context}
|
||||
*/
|
||||
_.emptyContext = function emptyContext() {
|
||||
return {
|
||||
left: '',
|
||||
startOfBuffer: true,
|
||||
endOfBuffer: true
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Transform that, when applied, makes no changes to the buffer.
|
||||
*
|
||||
* @returns {Transform}
|
||||
*/
|
||||
_.zeroTransform = function zeroTransform() {
|
||||
return {
|
||||
insert: '',
|
||||
deleteLeft: 0,
|
||||
};
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ test-browsers ( ) {
|
|||
# Defaults
|
||||
get_builder_OS # return: os_id="linux"|"mac"|"win"
|
||||
|
||||
FLAGS=
|
||||
FLAGS="--require ./unit_tests/helpers"
|
||||
CI_REPORTING=0
|
||||
RUN_HEADLESS=1
|
||||
RUN_BROWSERS=1
|
||||
|
|
@ -80,4 +80,4 @@ fi
|
|||
# Run browser-based tests.
|
||||
if (( RUN_BROWSERS )); then
|
||||
test-browsers || fail "Browser-based tests failed!"
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue