forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp-modal.spec.ts
249 lines (198 loc) · 7.39 KB
/
help-modal.spec.ts
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
test.beforeEach(async ({ page }) => {
await page.goto(
'/learn/foundational-c-sharp-with-microsoft/write-your-first-code-using-c-sharp/write-your-first-c-sharp-code'
);
});
test.describe('Help Modal component', () => {
test('renders the modal correctly', async ({ page }) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
await expect(
page.getByRole('dialog', { name: translations.buttons['ask-for-help'] })
).toBeVisible();
await expect(
page.getByText(
`If you've already tried the Read-Search-Ask method, then you can ask for help on the freeCodeCamp forum.`
)
).toBeVisible();
await expect(
page.getByText(
`Before making a new post please check if your question has already been answered on the forum.`
)
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.buttons['create-post'] })
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.buttons.cancel })
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.buttons.close })
).toBeVisible();
});
test('should disable the submit button if the checkboxes are not checked', async ({
page
}) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
await page
.getByRole('button', {
name: translations.buttons['create-post']
})
.click();
await expect(
page.getByRole('dialog', { name: translations.buttons['ask-for-help'] })
).toBeVisible();
const rsaCheckbox = page.getByRole('checkbox', {
name: 'I have tried the Read-Search-Ask method'
});
const similarQuestionsCheckbox = page.getByRole('checkbox', {
name: 'I have searched for similar questions that have already been answered on the forum'
});
const descriptionInput = page.getByRole('textbox', {
name: translations['forum-help']['whats-happening']
});
const submitButton = page.getByRole('button', {
name: translations.buttons['submit']
});
await descriptionInput.fill(
'Example text with a 100 characters to validate if the rules applied to block users from spamming help forum are working.'
);
await expect(submitButton).toBeDisabled();
await rsaCheckbox.check();
await similarQuestionsCheckbox.uncheck();
await expect(submitButton).toBeDisabled();
await rsaCheckbox.uncheck();
await similarQuestionsCheckbox.check();
await expect(submitButton).toBeDisabled();
});
test('should disable the submit button if the description contains less than 50 characters', async ({
page
}) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
await page
.getByRole('button', {
name: translations.buttons['create-post']
})
.click();
await expect(
page.getByRole('dialog', { name: translations.buttons['ask-for-help'] })
).toBeVisible();
const rsaCheckbox = page.getByRole('checkbox', {
name: 'I have tried the Read-Search-Ask method'
});
const similarQuestionsCheckbox = page.getByRole('checkbox', {
name: 'I have searched for similar questions that have already been answered on the forum'
});
const descriptionInput = page.getByRole('textbox', {
name: translations['forum-help']['whats-happening']
});
const submitButton = page.getByRole('button', {
name: translations.buttons['submit']
});
await rsaCheckbox.check();
await similarQuestionsCheckbox.check();
await descriptionInput.fill('Example text');
await expect(submitButton).toBeDisabled();
});
test('should ask the user to fill in the help form and create a forum page', async ({
context,
page
}) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
await page
.getByRole('button', {
name: translations.buttons['create-post']
})
.click();
await expect(
page.getByRole('dialog', { name: translations.buttons['ask-for-help'] })
).toBeVisible();
const rsaCheckbox = page.getByRole('checkbox', {
name: 'I have tried the Read-Search-Ask method'
});
const similarQuestionsCheckbox = page.getByRole('checkbox', {
name: 'I have searched for similar questions that have already been answered on the forum'
});
const descriptionInput = page.getByRole('textbox', {
name: translations['forum-help']['whats-happening']
});
const submitButton = page.getByRole('button', {
name: translations.buttons['submit']
});
await expect(rsaCheckbox).toBeVisible();
await expect(similarQuestionsCheckbox).toBeVisible();
await expect(descriptionInput).toBeVisible();
await rsaCheckbox.check();
await similarQuestionsCheckbox.check();
await descriptionInput.fill(
'Example text with a 100 characters to validate if the rules applied to block users from spamming help forum are working.'
);
await expect(submitButton).toBeEnabled();
await submitButton.click();
const newPagePromise = context.waitForEvent('page');
const newPage = await newPagePromise;
await newPage.waitForLoadState();
await expect(newPage).toHaveURL(/.*forum\.freecodecamp.org.*/);
});
test('Cancel button closes the modal', async ({ page }) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
const dialog = page.getByRole('dialog', {
name: translations.buttons['ask-for-help']
});
await expect(dialog).toBeVisible();
await page
.getByRole('button', { name: translations.buttons.cancel })
.click();
await expect(dialog).not.toBeVisible();
});
test('Close button closes the modal', async ({ page }) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
const dialog = page.getByRole('dialog', {
name: translations.buttons['ask-for-help']
});
await expect(dialog).toBeVisible();
await page
.getByRole('button', { name: translations.buttons.close })
.click();
await expect(dialog).not.toBeVisible();
});
test('Read-Search-Ask link', async ({ page }) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
const link = page.getByRole('link', { name: 'Read-Search-Ask' });
await expect(link).toHaveAttribute(
'href',
'https://forum.freecodecamp.org/t/19514'
);
await expect(link).toHaveAttribute('target', '_blank');
await expect(link).toHaveAttribute('rel', 'noopener noreferrer');
});
test('Already been answered link', async ({ page }) => {
await page
.getByRole('button', { name: translations.buttons['ask-for-help'] })
.click();
const link = page.getByRole('link', {
name: 'already been answered on the forum'
});
await expect(link).toHaveAttribute(
'href',
'https://forum.freecodecamp.org/search?q=Write%20Your%20First%20C%23%20Code'
);
await expect(link).toHaveAttribute('target', '_blank');
await expect(link).toHaveAttribute('rel', 'noopener noreferrer');
});
});