feat(common/models): transformToSuggestion unit test

This commit is contained in:
jahorton 2020-10-06 10:39:32 +07:00
parent 95e5ce47bf
commit 8d5b70cd77
3 changed files with 78 additions and 4 deletions

View file

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

View 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);
});
});
});

View file

@ -1,5 +1,5 @@
/*
* Unit tests for the priority queue.
* Unit tests for quote behaviors.
*/
var assert = require('chai').assert;