mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-07 01:15:33 +00:00
feat(common/models): transformToSuggestion unit test
This commit is contained in:
parent
95e5ce47bf
commit
8d5b70cd77
3 changed files with 78 additions and 4 deletions
|
|
@ -71,11 +71,15 @@ namespace models {
|
|||
export function transformToSuggestion(transform: Transform): Suggestion;
|
||||
export function transformToSuggestion(transform: Transform, p: number): Suggestion & {p: number};
|
||||
export function transformToSuggestion(transform: Transform, p?: number): Suggestion & {p?: number} {
|
||||
return {
|
||||
let suggestion: Suggestion & {p?: number} = {
|
||||
transform: transform,
|
||||
transformId: transform.id,
|
||||
displayAs: transform.insert,
|
||||
p: p
|
||||
displayAs: transform.insert
|
||||
};
|
||||
|
||||
if(p === 0 || p) {
|
||||
suggestion.p = p;
|
||||
}
|
||||
return suggestion;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
70
common/models/templates/test/test-common.js
Normal file
70
common/models/templates/test/test-common.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Unit tests for common utility functions/methods.
|
||||
*/
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var models = require('../').models;
|
||||
|
||||
describe('Common utility functions', function() {
|
||||
// TODO: unit tests for other common utility functions
|
||||
|
||||
describe('transformToSuggestion', function() {
|
||||
it('p: undefined', function() {
|
||||
let suggestion = {
|
||||
transform: {
|
||||
insert: 'hello',
|
||||
deleteLeft: 0,
|
||||
id: 0
|
||||
},
|
||||
transformId: 0,
|
||||
displayAs: 'hello'
|
||||
};
|
||||
|
||||
assert.deepEqual(models.transformToSuggestion(suggestion.transform), suggestion);
|
||||
});
|
||||
|
||||
it('p: 0', function() {
|
||||
let suggestion = {
|
||||
transform: {
|
||||
insert: 'hello',
|
||||
deleteLeft: 0,
|
||||
id: 0
|
||||
},
|
||||
transformId: 0,
|
||||
displayAs: 'hello',
|
||||
p: 0
|
||||
};
|
||||
|
||||
assert.deepEqual(models.transformToSuggestion(suggestion.transform, 0), suggestion);
|
||||
});
|
||||
|
||||
it('p > 0', function() {
|
||||
let suggestion = {
|
||||
transform: {
|
||||
insert: 'hello',
|
||||
deleteLeft: 0,
|
||||
id: 0
|
||||
},
|
||||
transformId: 0,
|
||||
displayAs: 'hello',
|
||||
p: 0.5
|
||||
};
|
||||
|
||||
assert.deepEqual(models.transformToSuggestion(suggestion.transform, 0.5), suggestion);
|
||||
});
|
||||
|
||||
it('properly handles the transformId', function() {
|
||||
let suggestion = {
|
||||
transform: {
|
||||
insert: 'hello',
|
||||
deleteLeft: 0,
|
||||
id: 3
|
||||
},
|
||||
transformId: 3, // Ensures there isn't a separate ID seed in use.
|
||||
displayAs: 'hello'
|
||||
};
|
||||
|
||||
assert.deepEqual(models.transformToSuggestion(suggestion.transform), suggestion);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Unit tests for the priority queue.
|
||||
* Unit tests for quote behaviors.
|
||||
*/
|
||||
|
||||
var assert = require('chai').assert;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue