Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/translate/system-test/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,27 @@ describe('translate', function() {
var INPUT = [
{
input: 'Hello!',
expectedTranslation: '¡Hola!'
expectedTranslation: 'Hola'
},
{
input: 'How are you today?',
expectedTranslation: '¿Cómo estás hoy?'
expectedTranslation: 'Cómo estás hoy'
}
];

function removeSymbols(input) {
// Remove the leading and trailing ! or ? symbols. The API has been known
// to switch back and forth between returning "Cómo estás hoy" and
// "¿Cómo estás hoy?", so let's just not depend on that.
return input.replace(/^\W|\W*$/g, '');
}

it('should translate input', function(done) {
var input = INPUT.map(prop('input'));

translate.translate(input, 'es', function(err, results) {
assert.ifError(err);
results = results.map(removeSymbols);
assert.strictEqual(results[0], INPUT[0].expectedTranslation);
assert.strictEqual(results[1], INPUT[1].expectedTranslation);
done();
Expand All @@ -85,6 +93,7 @@ describe('translate', function() {

translate.translate(input, opts, function(err, results) {
assert.ifError(err);
results = results.map(removeSymbols);
assert.strictEqual(results[0], INPUT[0].expectedTranslation);
assert.strictEqual(results[1], INPUT[1].expectedTranslation);
done();
Expand All @@ -93,11 +102,6 @@ describe('translate', function() {

it('should autodetect HTML', function(done) {
var input = '<body>' + INPUT[0].input + '</body>';
var expectedTranslation = [
'<body>',
INPUT[0].expectedTranslation,
'</body>'
].join(' ');

var opts = {
from: 'en',
Expand All @@ -106,7 +110,14 @@ describe('translate', function() {

translate.translate(input, opts, function(err, results) {
assert.ifError(err);
assert.strictEqual(results, expectedTranslation);

var translation = results.split(/<\/*body>/g)[1].trim();

assert.strictEqual(
removeSymbols(translation),
INPUT[0].expectedTranslation
);

done();
});
});
Expand Down