Skip to content

Commit e5b7c7f

Browse files
authored
Merge pull request #3584 from pablo-maff/part5-spanish-playwright
Part5 spanish playwright
2 parents 10d79aa + a1df911 commit e5b7c7f

File tree

10 files changed

+2177
-827
lines changed

10 files changed

+2177
-827
lines changed

src/content/5/en/part5b.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ The application code can be found on [GitHub](https://github.com/fullstack-hy202
358358

359359
Our current implementation is quite good; it has one aspect that could be improved.
360360

361-
After a new note is created, it would make sense to hide the new note form. Currently, the form stays visible. There is a slight problem with hiding the form. The visibility is controlled with the <i>visible</i> state variable inside of the <i>Togglable</i> component.
361+
After a new note is created, it would make sense to hide the new note form. Currently, the form stays visible. There is a slight problem with hiding it, the visibility is controlled with the <i>visible</i> state variable inside of the <i>Togglable</i> component.
362362

363363
One solution to this would be to move control of the Togglable component's state outside the component. However, we won't do that now, because we want the component to be responsible for its own state. So we have to find another solution, and find a mechanism to change the state of the component externally.
364364

src/content/5/en/part5c.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ afterEach(() => {
5757
})
5858
```
5959

60-
Now, after each test, the function _cleanup_ is performed that resets the jsdom that is simulating the browser.
60+
Now, after each test, the function _cleanup_ is executed to reset jsdom, which is simulating the browser.
6161

6262
Expand the _vite.config.js_ file as follows
6363

@@ -131,7 +131,7 @@ We can use the object [screen](https://testing-library.com/docs/queries/about#sc
131131
expect(element).toBeDefined()
132132
```
133133

134-
The existence of an element is checked using Vitest's [expect](https://vitest.dev/api/expect.html#expect) command. Expect generates an assertion from its parameter, the validity of which can be tested using various condition functions. Now we used [toBeDefined](https://vitest.dev/api/expect.html#tobedefined) which tests whether the _element_ parameter of expect exists.
134+
The existence of an element is checked using Vitest's [expect](https://vitest.dev/api/expect.html#expect) command. Expect generates an assertion for its argument, the validity of which can be tested using various condition functions. Now we used [toBeDefined](https://vitest.dev/api/expect.html#tobedefined) which tests whether the _element_ argument of expect exists.
135135

136136
Run the test with command _npm test_:
137137

@@ -384,7 +384,7 @@ The expectation of the test uses [toHaveLength](https://vitest.dev/api/expect.ht
384384
expect(mockHandler.mock.calls).toHaveLength(1)
385385
```
386386

387-
The calls of the mock function are saved to the array [mock.calls](https://vitest.dev/api/mock#mock-calls) within the mock function object.
387+
The calls to the mock function are saved to the array [mock.calls](https://vitest.dev/api/mock#mock-calls) within the mock function object.
388388

389389
[Mock objects and functions](https://en.wikipedia.org/wiki/Mock_object) are commonly used [stub](https://en.wikipedia.org/wiki/Method_stub) components in testing that are used for replacing dependencies of the components being tested. Mocks make it possible to return hardcoded responses, and to verify the number of times the mock functions are called and with what parameters.
390390

@@ -417,7 +417,6 @@ const Togglable = forwardRef((props, ref) => {
417417
The tests are shown below:
418418

419419
```js
420-
421420
import { render, screen } from '@testing-library/react'
422421
import userEvent from '@testing-library/user-event'
423422
import Togglable from './Togglable'
@@ -592,7 +591,7 @@ test('<NoteForm /> updates parent state and calls onSubmit', async() => {
592591
})
593592
```
594593

595-
In the middle of running the tests, the following is printed
594+
In the middle of running the tests, the following is printed in the console:
596595

597596
```
598597
[ [ { content: 'testing a form...', important: true } ] ]

src/content/5/en/part5d.md

Lines changed: 81 additions & 89 deletions
Large diffs are not rendered by default.

src/content/5/en/part5e.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,6 @@ The structure of the test must be as follows:
10901090
```js
10911091
describe('Blog app', function() {
10921092
beforeEach(function() {
1093-
cy.request('POST', 'http://localhost:3003/api/testing/reset')
10941093
cy.visit('http://localhost:5173')
10951094
})
10961095

@@ -1100,8 +1099,6 @@ describe('Blog app', function() {
11001099
})
11011100
```
11021101
1103-
The <i>beforeEach</i> formatting blog must empty the database using for example the method we used in the [material](/en/part5/end_to_end_testing#controlling-the-state-of-the-database).
1104-
11051102
#### 5.18: Blog List End To End Testing, step 2
11061103
11071104
Make tests for logging in. Test both successful and unsuccessful login attempts.
@@ -1112,8 +1109,8 @@ The test structure extends like so:
11121109
```js
11131110
describe('Blog app', function() {
11141111
beforeEach(function() {
1115-
cy.request('POST', 'http://localhost:3001/api/testing/reset')
1116-
// create here a user to backend
1112+
// empty the db here
1113+
// create a user for the backend here
11171114
cy.visit('http://localhost:5173')
11181115
})
11191116

@@ -1133,6 +1130,8 @@ describe('Blog app', function() {
11331130
})
11341131
```
11351132
1133+
The _beforeEach_ block must empty the database using, for example, the reset method we used in the [material](/en/part5/end_to_end_testing_cypress#controlling-the-state-of-the-database).
1134+
11361135
<i>Optional bonus exercise</i>: Check that the notification shown with unsuccessful login is displayed red.
11371136
11381137
#### 5.19: Blog List End To End Testing, step 3
@@ -1146,7 +1145,7 @@ describe('Blog app', function() {
11461145

11471146
describe('When logged in', function() {
11481147
beforeEach(function() {
1149-
// log in user here
1148+
// ...
11501149
})
11511150

11521151
it('A blog can be created', function() {

src/content/5/es/part5.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ lang: es
88

99
En esta parte volvemos al frontend, primero mirando a diferentes posibilidades para probar el código React. También implementaremos la autenticación basada en tokens que permitirá a los usuarios iniciar sesión en nuestra aplicación.
1010

11-
<i>Parte actualizada el 17 de Agosto de 2023</i>
12-
- <i>Create React App reemplazado con Vite</i>
11+
<i>Parte actualizada el 3 de Marzo de 2024</i>
12+
- <i>Jest reemplazado por Vitest</i>
1313

1414
</div>

src/content/5/es/part5b.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,11 @@ El código de la aplicación se puede encontrar en [GitHub](https://github.com/f
358358

359359
Nuestra implementación actual es bastante buena, pero tiene un aspecto que podría mejorarse.
360360

361-
Después de crear una nueva nota, tendría sentido ocultar el nuevo formulario de nota. Actualmente, el formulario permanece visible. Hay un pequeño problema al ocultar el formulario. La visibilidad se controla con la variable <i>visible</i> dentro del componente <i>Togglable</i>. ¿Cómo podemos acceder a él fuera del componente?
361+
Después de crear una nueva nota, tendría sentido ocultar el formulario de nueva nota. Actualmente, el formulario permanece visible. Hay un pequeño problema al ocultarlo, la visibilidad se controla con la variable <i>visible</i> dentro del componente <i>Togglable</i>.
362362

363-
Hay muchas formas de implementar el cierre del formulario desde el componente padre, pero usemos el mecanismo [ref](https://es.react.dev/learn/referencing-values-with-refs) de React, que ofrece una referencia al componente.
363+
Una solución a esto sería mover el control del estado del componente Togglable fuera del componente. Sin embargo, no lo haremos ahora, porque queremos que el componente sea responsable de su propio estado. Por lo tanto, tenemos que encontrar otra solución y hallar un mecanismo para cambiar el estado del componente externamente.
364+
365+
Hay varias formas diferentes de implementar el acceso a las funciones de un componente desde fuera del componente, pero usemos el mecanismo de [ref](https://es.react.dev/learn/referencing-values-with-refs) de React, que ofrece una referencia al componente.
364366

365367
Hagamos los siguientes cambios en el componente <i>App</i>:
366368

@@ -571,14 +573,6 @@ const Blog = ({ blog }) => {
571573

572574
#### 5.8: Frontend de la Lista de Blogs, paso 8
573575

574-
Notamos que algo está mal. Cuando se crea un nuevo blog en la aplicación, no se muestra el nombre del usuario que agregó el blog en los detalles del mismo:
575-
576-
![navegador mostrando nombre faltante debajo del botón Me gusta](../../images/5/59new.png)
577-
578-
Cuando se recarga el navegador, se muestra la información de la persona. Esto no es aceptable, averigua dónde está el problema y realiza la corrección necesaria.
579-
580-
#### 5.9: Frontend de la lista de blogs, paso 9
581-
582576
Implementa la funcionalidad para el botón like. Los likes aumentan al hacer un solicitud HTTP _PUT_ a la dirección única de la publicación del blog en el backend.
583577

584578
Dado que la operación de backend reemplaza toda la publicación del blog, deberás enviar todos sus campos en el cuerpo de la solicitud. Si deseas agregar un like a la siguiente publicación de blog:
@@ -612,7 +606,15 @@ Deberías realizar una solicitud HTTP PUT a la dirección <i>/api/blogs/5a43fde2
612606

613607
El Backend también debe ser actualizado para manejar la referencia al usuario.
614608

615-
**Una última advertencia:** si notas que estás usando async/await y el método _then_ en el mismo código, es casi seguro que estás haciendo algo mal. Usa uno u otro, y nunca uses ambos al mismo tiempo "por si acaso".
609+
#### 5.9: Frontend de la lista de Blogs, paso 9
610+
611+
Nos damos cuenta de que algo está mal. Cuando se da "me gusta" a un blog en la app, el nombre del usuario que añadió el blog no se muestra en sus detalles:
612+
613+
![navegador mostrando nombre faltante debajo del botón de me gusta](../../images/5/59put.png)
614+
615+
Cuando se recarga el navegador, la información de la persona se muestra. Esto no es aceptable, averigua dónde está el problema y realiza la corrección necesaria.
616+
617+
Por supuesto, es posible que ya hayas hecho todo correctamente y el problema no ocurra en tu código. En ese caso, puedes continuar.
616618

617619
#### 5.10: Frontend de la Lista de Blogs, paso 10
618620

@@ -706,12 +708,6 @@ En la parte 3 configuramos la herramienta de estilo de código para el backend [
706708

707709
Vite ha instalado ESlint en el proyecto de forma predeterminada, por lo que todo lo que nos queda por hacer es definir nuestra configuración deseada en el archivo <i>.eslintrc.cjs</i>.
708710

709-
A continuación, comenzaremos a probar el frontend y, para evitar errores de linter no deseados e irrelevantes instalaremos el paquete [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest):
710-
711-
```bash
712-
npm install --save-dev eslint-plugin-jest
713-
```
714-
715711
Creemos un archivo <i>.eslintrc.js</i> con el siguiente contenido:
716712

717713
```js
@@ -720,7 +716,6 @@ module.exports = {
720716
env: {
721717
browser: true,
722718
es2020: true,
723-
"jest/globals": true
724719
},
725720
extends: [
726721
'eslint:recommended',
@@ -731,7 +726,7 @@ module.exports = {
731726
ignorePatterns: ['dist', '.eslintrc.cjs'],
732727
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
733728
settings: { react: { version: '18.2' } },
734-
plugins: ['react-refresh', 'jest'],
729+
plugins: ['react-refresh'],
735730
rules: {
736731
"indent": [
737732
"error",
@@ -773,6 +768,7 @@ Vamos a crear un archivo [.eslintignore](https://eslint.org/docs/latest/use/conf
773768
node_modules
774769
dist
775770
.eslintrc.cjs
771+
vite.config.js
776772
```
777773

778774
Ahora los directorios <em>dist</em> y <em>node_modules</em> se omitirán al realizar el linting.

0 commit comments

Comments
 (0)