Skip to content

Quinto y último proyecto requisito obligatorio para obtener la Quality Assurance Certification de freecodecamp

Notifications You must be signed in to change notification settings

waldohidalgo/american-british-translator

Repository files navigation

American British Translator

Quinto y último proyecto finalizado y aprobado el cual es requisito obligatorio para obtener la Quality Assurance Certification de freecodecamp.

El proyecto consiste en realizar un traductor de inglés americano a inglés británico y viceversa. El traductor NO traduce cualquier palabra y/o frase sino un dominio acotado a 2131 palabras y frases las cuales se encuentran en los archivos ubicados en la carpeta components llamados:

  • american-only.js (183 palabras y frases)

  • american-to-british-spelling.js (1699 palabras)

  • american-to-british-titles.js (6 palabras)

  • british-only.js (243 palabras y frases)

El texto a traducir y el idioma se envían desde el cliente al servidor en el cuerpo de una petición POST en formato de objeto siendo el valor de la key text igual al texto que se desea traducir y el valor de la key locale igual a british-to-american o american-to-british. El servidor responde con diversos mensajes según corresponda:

  1. Cuando el texto ingresado posee traducción, dicha traducción se muestra en el área marcada para ello. El servidor responde con un objeto siendo el valor de la key text igual al texto a traducir enviado y el valor de la key translation igual al texto traducido.

  2. Si el texto esta en un idioma y se intenta traducir al mismo idioma entonces se envía lo siguiente:

    Everything looks good to me!

  3. Si el texto que se desea traducir esta en blanco, entonces se envía el siguiente error:

    { error: 'No text to translate' }

  4. Si se pretende traducir a un idioma distinto del inglés americano o inglés británico pasando un argumento diferente de british-to-american o american-to-british, entonces se envía el siguiente error:

    { error: 'Invalid value for locale field' }.

  5. Si en la petición al servidor no estan presentes las keys text o locale, entonces se envía el siguiente error:

    { error: 'Required field(s) missing' }.

Tabla de Contenidos

Deploy

El proyecto ha sido desplegado a la web en mi cuenta gratuita en Render.com. Como es costumbre con Render.com, cuando un servicio web no esta activo, es decir, pasa un tiempo sin uso, dicho servicio es congelado necesitando de al menos 50 segundos o más para volver a visualizar el proyecto.

Requisitos Aprobados

Imagen de Requisitos Aprobados

Tests unitarios y funcionales requeridos

Imagen de Tests unitarios y funcionales requeridos

Proyecto Aprobado

Imagen de Proyecto Aprobado

Tests Requeridos Aprobados

Imagen de Tests Requeridos Aprobados

Código de tests unitarios y funcionales

Se han creado 24 tests unitarios y 6 tests funcionales requeridos:

1. Tests Unitarios

1. Translate Mangoes are my favorite fruit. to British English

test("Translate Mangoes are my favorite fruit. to British English", (done) => {
  assert.equal(
    translator.translate(
      "Mangoes are my favorite fruit.",
      "american-to-british",
      false
    ),
    "Mangoes are my favourite fruit."
  );
  done();
});

2.Translate I ate yogurt for breakfast. to British English

test("Translate I ate yogurt for breakfast. to British English", (done) => {
  assert.equal(
    translator.translate(
      "I ate yogurt for breakfast.",
      "american-to-british",
      false
    ),
    "I ate yoghurt for breakfast."
  );
  done();
});

3.Translate We had a party at my friend's condo. to British English

test("Translate We had a party at my friend's condo. to British English", (done) => {
  assert.equal(
    translator.translate(
      "We had a party at my friend's condo.",
      "american-to-british",
      false
    ),
    "We had a party at my friend's flat."
  );
  done();
});

4.Translate Can you toss this in the trashcan for me? to British English

test("Translate Can you toss this in the trashcan for me? to British English", (done) => {
  assert.equal(
    translator.translate(
      "Can you toss this in the trashcan for me?",
      "american-to-british",
      false
    ),
    "Can you toss this in the bin for me?"
  );
  done();
});

5.Translate The parking lot was full. to British English

test("Translate The parking lot was full. to British English", (done) => {
  assert.equal(
    translator.translate(
      "The parking lot was full.",
      "american-to-british",
      false
    ),
    "The car park was full."
  );
  done();
});

6.Translate Like a high tech Rube Goldberg machine. to British English

test("Translate Like a high tech Rube Goldberg machine. to British English", (done) => {
  assert.equal(
    translator.translate(
      "Like a high tech Rube Goldberg machine.",
      "american-to-british",
      false
    ),
    "Like a high tech Heath Robinson device."
  );
  done();
});

7.Translate To play hooky means to skip class or work. to British English

test("Translate To play hooky means to skip class or work. to British English", (done) => {
  assert.equal(
    translator.translate(
      "To play hooky means to skip class or work.",
      "american-to-british",
      false
    ),
    "To bunk off means to skip class or work."
  );
  done();
});

8.Translate No Mr. Bond, I expect you to die. to British English

test("Translate No Mr. Bond, I expect you to die. to British English", (done) => {
  assert.equal(
    translator.translate(
      "No Mr. Bond, I expect you to die.",
      "american-to-british",
      false
    ),
    "No Mr Bond, I expect you to die."
  );
  done();
});

9.Translate Dr. Grosh will see you now. to British English

test("Translate Dr. Grosh will see you now. to British English", (done) => {
  assert.equal(
    translator.translate(
      "Dr. Grosh will see you now.",
      "american-to-british",
      false
    ),
    "Dr Grosh will see you now."
  );
  done();
});

10.Translate Lunch is at 12:15 today. to British English

test("Translate Lunch is at 12:15 today. to British English", (done) => {
  assert.equal(
    translator.translate(
      "Lunch is at 12:15 today.",
      "american-to-british",
      false
    ),
    "Lunch is at 12.15 today."
  );
  done();
});

11.Translate We watched the footie match for a while. to American English

test("Translate We watched the footie match for a while. to American English", (done) => {
  assert.equal(
    translator.translate(
      "We watched the footie match for a while.",
      "british-to-american",
      false
    ),
    "We watched the soccer match for a while."
  );
  done();
});

12.Translate Paracetamol takes up to an hour to work. to American English

test("Translate Paracetamol takes up to an hour to work. to American English", (done) => {
  assert.equal(
    translator.translate(
      "Paracetamol takes up to an hour to work.",
      "british-to-american",
      false
    ),
    "Tylenol takes up to an hour to work."
  );
  done();
});

13.Translate First, caramelise the onions. to American English

test("Translate First, caramelise the onions. to American English", (done) => {
  assert.equal(
    translator.translate(
      "First, caramelise the onions.",
      "british-to-american",
      false
    ),
    "First, caramelize the onions."
  );
  done();
});

14.Translate I spent the bank holiday at the funfair. to American English

test("Translate I spent the bank holiday at the funfair. to American English", (done) => {
  assert.equal(
    translator.translate(
      "I spent the bank holiday at the funfair.",
      "british-to-american",
      false
    ),
    "I spent the public holiday at the carnival."
  );
  done();
});

15.Translate I had a bicky then went to the chippy. to American English

test("Translate I had a bicky then went to the chippy. to American English", (done) => {
  assert.equal(
    translator.translate(
      "I had a bicky then went to the chippy.",
      "british-to-american",
      false
    ),
    "I had a cookie then went to the fish-and-chip shop."
  );
  done();
});

16.Translate I've just got bits and bobs in my bum bag. to American English

test("Translate I've just got bits and bobs in my bum bag. to American English", (done) => {
  assert.equal(
    translator.translate(
      "I've just got bits and bobs in my bum bag.",
      "british-to-american",
      false
    ),
    "I've just got odds and ends in my fanny pack."
  );
  done();
});

17.Translate The car boot sale at Boxted Airfield was called off. to American English

test("Translate The car boot sale at Boxted Airfield was called off. to American English", (done) => {
  assert.equal(
    translator.translate(
      "The car boot sale at Boxted Airfield was called off.",
      "british-to-american",
      false
    ),
    "The swap meet at Boxted Airfield was called off."
  );
  done();
});

18.Translate Have you met Mrs Kalyani? to American English

test("Translate Have you met Mrs Kalyani? to American English", (done) => {
  assert.equal(
    translator.translate(
      "Have you met Mrs Kalyani?",
      "british-to-american",
      false
    ),
    "Have you met Mrs. Kalyani?"
  );
  done();
});

19.Translate Prof Joyner of King's College, London. to American English

test("Translate Prof Joyner of King's College, London. to American English", (done) => {
  assert.equal(
    translator.translate(
      "Prof Joyner of King's College, London.",
      "british-to-american",
      false
    ),
    "Prof. Joyner of King's College, London."
  );
  done();
});

20.Translate Tea time is usually around 4 or 4.30. to American English

test("Translate Tea time is usually around 4 or 4.30. to American English", (done) => {
  assert.equal(
    translator.translate(
      "Tea time is usually around 4 or 4.30.",
      "british-to-american",
      false
    ),
    "Tea time is usually around 4 or 4:30."
  );
  done();
});

21.Highlight translation in Mangoes are my favorite fruit.

test("Highlight translation in Mangoes are my favorite fruit.", (done) => {
  assert.equal(
    translator.translate(
      "Mangoes are my favorite fruit.",
      "american-to-british",
      true
    ),
    'Mangoes are my <span class="highlight">favourite</span> fruit.'
  );
  done();
});

22.Highlight translation in I ate yogurt for breakfast.

test("Highlight translation in I ate yogurt for breakfast.", (done) => {
  assert.equal(
    translator.translate(
      "I ate yogurt for breakfast.",
      "american-to-british",
      true
    ),
    'I ate <span class="highlight">yoghurt</span> for breakfast.'
  );
  done();
});

23.Highlight translation in We watched the footie match for a while.

test("Highlight translation in We watched the footie match for a while.", (done) => {
  assert.equal(
    translator.translate(
      "We watched the footie match for a while.",
      "british-to-american",
      true
    ),
    'We watched the <span class="highlight">soccer</span> match for a while.'
  );
  done();
});

24.Highlight translation in Paracetamol takes up to an hour to work.

test("Highlight translation in Paracetamol takes up to an hour to work.", (done) => {
  assert.equal(
    translator.translate(
      "Paracetamol takes up to an hour to work.",
      "british-to-american",
      true
    ),
    '<span class="highlight">Tylenol</span> takes up to an hour to work.'
  );
  done();
});

2. Tests Funcionales

1.Translation with text and locale fields: POST request to /api/translate

test("Translation with text and locale fields: POST request to /api/translate", (done) => {
  chai
    .request(server)
    .keepOpen()
    .post("/api/translate")
    .send({
      text: "Mangoes are my favorite fruit.",
      locale: "american-to-british",
    })
    .end((err, res) => {
      assert.equal(res.status, 200);
      assert.equal(res.body.text, "Mangoes are my favorite fruit.");
      assert.equal(
        res.body.translation,
        'Mangoes are my <span class="highlight">favourite</span> fruit.'
      );
      done();
    });
});

2.Translation with text and invalid locale field: POST request to /api/translate

test("Translation with text and invalid locale field: POST request to /api/translate", (done) => {
  chai
    .request(server)
    .keepOpen()
    .post("/api/translate")
    .send({
      text: "Mangoes are my favorite fruit.",
      locale: "american-to-spanish",
    })
    .end((err, res) => {
      assert.equal(res.status, 200);
      assert.equal(res.body.error, "Invalid value for locale field");
      done();
    });
});

3.Translation with missing text field: POST request to /api/translate

test("Translation with missing text field: POST request to /api/translate", (done) => {
  chai
    .request(server)
    .keepOpen()
    .post("/api/translate")
    .send({
      locale: "american-to-british",
    })
    .end((err, res) => {
      assert.equal(res.status, 200);
      assert.equal(res.body.error, "Required field(s) missing");
      done();
    });
});

4.Translation with missing locale field: POST request to /api/translate

test("Translation with missing locale field: POST request to /api/translate", (done) => {
  chai
    .request(server)
    .keepOpen()
    .post("/api/translate")
    .send({
      text: "Mangoes are my favorite fruit.",
    })
    .end((err, res) => {
      assert.equal(res.status, 200);
      assert.equal(res.body.error, "Required field(s) missing");
      done();
    });
});

5.Translation with empty text: POST request to /api/translate

test("Translation with empty text: POST request to /api/translate", (done) => {
  chai
    .request(server)
    .keepOpen()
    .post("/api/translate")
    .send({
      text: "",
      locale: "american-to-british",
    })
    .end((err, res) => {
      assert.equal(res.status, 200);
      assert.equal(res.body.error, "No text to translate");
      done();
    });
});

6.Translation with text that needs no translation: POST request to /api/translate

test("Translation with text that needs no translation: POST request to /api/translate", (done) => {
  chai
    .request(server)
    .keepOpen()
    .post("/api/translate")
    .send({
      text: "Mangoes are my favorite fruit.",
      locale: "british-to-american",
    })
    .end((err, res) => {
      assert.equal(res.status, 200);
      assert.equal(res.body.text, "Mangoes are my favorite fruit.");
      assert.equal(res.body.translation, "Everything looks good to me!");
      done();
    });
});

Screenshots

1. Home: Inital State

Imagen de Home: Inital Load

2. British to American Translation

Imagen de British to American Translation

3. American to British Translation

Imagen de American to British Translation

4. American to American Translation (same)

Imagen de American to American Translation (same)

5. British to British Translation (same)

Imagen de British to British Translation (same)

6. Blank Translate Error

Imagen de Blank Translate Error