-
Notifications
You must be signed in to change notification settings - Fork 59
/
app.spec.js
227 lines (172 loc) · 8.04 KB
/
app.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import { test, expect } from '@playwright/test';
const TEST_TEXT_EMPTY = '';
const TEST_TEXT_NO_NUMBERS = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
const TEST_TEXT_NUMBERS = 'Si tengo 8 manzanas y compro 2 más, ¿cúantas manzanas tengo en total?';
const TEST_TEXT_DECIMALS = 'Calcular la suma de 1.65 más 0.15 y más 1.10';
const TEST_TEXT_NOT_A_NUMBER = 'Esto no es un número: 41u0003jot';
test.describe('Para un texto con sólo palábras:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_NO_NUMBERS);
});
test('Caracteres: 123', async ({ page }) => {
await expect(page.locator('li[data-testid="character-count"]:has-text("123")')).toBeVisible();
});
test('Caracteres Sin Espacios: 102', async ({ page }) => {
await expect(page.locator('li[data-testid="character-no-spaces-count"]:has-text("102")')).toBeVisible();
});
test('Palabras: 19', async ({ page }) => {
await expect(page.locator('li[data-testid="word-count"]:has-text("19")')).toBeVisible();
});
test('Números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-count"]:has-text("0")')).toBeVisible();
});
test('Suma números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-sum"]:has-text("0")')).toBeVisible();
});
test('Longitud promedio palabra: 5.53', async ({ page }) => {
await expect(page.locator('li[data-testid="word-length-average"]:has-text("5.53")')).toBeVisible();
});
});
test.describe('Para un texto con números:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_NUMBERS);
});
test('Números: 2', async ({ page }) => {
await expect(page.locator('li[data-testid="number-count"]:has-text("2")')).toBeVisible();
});
test('Suma números: 10', async ({ page }) => {
await expect(page.locator('li[data-testid="number-sum"]:has-text("10")')).toBeVisible();
});
});
test.describe('Para un texto números decimales:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_DECIMALS);
});
test('Números: 3', async ({ page }) => {
await expect(page.locator('li[data-testid="number-count"]:has-text("3")')).toBeVisible();
});
test('Suma números: 2.9', async ({ page }) => {
await expect(page.locator('li[data-testid="number-sum"]:has-text("2.9")')).toBeVisible();
});
});
test.describe('Para un texto sin números válidos:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_NOT_A_NUMBER);
});
test('Números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-count"]:has-text("0")')).toBeVisible();
});
test('Suma números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-sum"]:has-text("0")')).toBeVisible();
});
});
test.describe('Botón:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_NO_NUMBERS);
});
test('Limpia caja de texto', async ({ page }) => {
const textarea = await page.locator('textarea[name="user-input"]');
await expect(textarea).toHaveValue(TEST_TEXT_NO_NUMBERS);
const button = await page.locator('id=reset-button')
await button.click();
await expect(textarea).toHaveValue(TEST_TEXT_EMPTY);
});
});
//TODO: Reemplazar skip por describe para ejecutar el test de funcionalidades opcionales
test.skip('Opcional:', () => {
const TEST_TEXT_SPACES = ' ';
const TEST_TEXT_PUNCTUATION_MARKS = '.,;:"«»[]{}()¿?¡!-';
test.describe('Para un texto con sólo signos de puntuación:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_PUNCTUATION_MARKS);
});
test('Caracteres: 18', async ({ page }) => {
await expect(page.locator('li[data-testid="character-count"]:has-text("18")')).toBeVisible();
});
test('Caracteres Sin Espacios: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="character-no-spaces-count"]:has-text("0")')).toBeVisible();
});
test('Palabras: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="word-count"]:has-text("0")')).toBeVisible();
});
test('Números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-count"]:has-text("0")')).toBeVisible();
});
test('Suma números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-sum"]:has-text("0")')).toBeVisible();
});
test('Longitud promedio palabra: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="word-length-average"]:has-text("0")')).toBeVisible();
});
});
test.describe('Para un texto vacio:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_EMPTY);
});
test('Caracteres: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="character-count"]:has-text("0")')).toBeVisible();
});
test('Caracteres Sin Espacios: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="character-no-spaces-count"]:has-text("0")')).toBeVisible();
});
test('Palabras: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="word-count"]:has-text("0")')).toBeVisible();
});
test('Números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-count"]:has-text("0")')).toBeVisible();
});
test('Suma números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-sum"]:has-text("0")')).toBeVisible();
});
test('Longitud promedio palabra: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="word-length-average"]:has-text("0")')).toBeVisible();
});
});
test.describe('Para un texto de solo espacios:', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:3000/');
const textarea = await page.locator('textarea[name="user-input"]');
await textarea.click();
await textarea.type(TEST_TEXT_SPACES);
});
test('Caracteres: 7', async ({ page }) => {
await expect(page.locator('li[data-testid="character-count"]:has-text("7")')).toBeVisible();
});
test('Caracteres Sin Espacios: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="character-no-spaces-count"]:has-text("0")')).toBeVisible();
});
test('Palabras: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="word-count"]:has-text("0")')).toBeVisible();
});
test('Números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-count"]:has-text("0")')).toBeVisible();
});
test('Suma números: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="number-sum"]:has-text("0")')).toBeVisible();
});
test('Longitud promedio palabra: 0', async ({ page }) => {
await expect(page.locator('li[data-testid="word-length-average"]:has-text("0")')).toBeVisible();
});
});
});