forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform-helper.spec.ts
100 lines (84 loc) · 3.61 KB
/
form-helper.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
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
test.describe('Test form with only solution link', () => {
test.beforeEach(async ({ page }) => {
await page.goto(
'learn/front-end-development-libraries/front-end-development-libraries-projects/build-a-random-quote-machine'
);
});
test('The form is visible and has only solution link input', async ({
page
}) => {
// The solution form should be present and visible
const solutionForm = page.getByTestId('form-helper-form');
await expect(solutionForm).toBeVisible();
// The form submit button should be disabled as the form is not filled
const solutionFormButton = solutionForm.getByRole('button', {
name: `${translations.learn['i-completed']}`
});
await expect(solutionFormButton).toBeVisible();
await expect(solutionFormButton).toBeDisabled();
const solutionLinkInputLabel = solutionForm.getByTestId(
'solution-control-label'
);
await expect(solutionLinkInputLabel).toBeVisible();
await expect(solutionLinkInputLabel).toHaveText(
translations.learn['solution-link']
);
const solutionLinkInput = solutionForm.getByTestId('solution-form-control');
await expect(solutionLinkInput).toBeVisible();
const githubLinkInputLabel = solutionForm.getByTestId(
'githubLink-control-label'
);
await expect(githubLinkInputLabel).not.toBeVisible();
// The form submit button should be enabled as the form is now filled
await solutionLinkInput.fill('test-input');
await expect(solutionFormButton).toBeEnabled();
});
});
test.describe('Test form with solution link and github link', () => {
test.beforeEach(async ({ page }) => {
await page.goto(
'learn/quality-assurance/quality-assurance-projects/personal-library'
);
});
test('The form is visible and has solution link and github link input', async ({
page
}) => {
// The solution form should be present and visible
const solutionForm = page.getByTestId('form-helper-form');
await expect(solutionForm).toBeVisible();
// The form submit button should be disabled as the form is not filled
const solutionFormButton = solutionForm.getByRole('button', {
name: `${translations.learn['i-completed']}`
});
await expect(solutionFormButton).toBeVisible();
await expect(solutionFormButton).toBeDisabled();
const solutionLinkInputLabel = solutionForm.getByTestId(
'solution-control-label'
);
await expect(solutionLinkInputLabel).toBeVisible();
await expect(solutionLinkInputLabel).toHaveText(
translations.learn['solution-link']
);
const solutionLinkInput = solutionForm.getByTestId('solution-form-control');
await expect(solutionLinkInput).toBeVisible();
const githubLinkInputLabel = solutionForm.getByTestId(
'githubLink-control-label'
);
await expect(githubLinkInputLabel).toBeVisible();
await expect(githubLinkInputLabel).toHaveText(
translations.learn['source-code-link']
);
const githubLinkInput = solutionForm.getByTestId('githubLink-form-control');
await expect(githubLinkInput).toBeVisible();
// The form submit button should be enabled as the form is now filled
await solutionLinkInput.fill('test-input');
await expect(solutionFormButton).toBeEnabled();
// The form submit button should be enabled as the GitHub link is now filled
await solutionLinkInput.fill('');
await expect(solutionFormButton).toBeDisabled();
await githubLinkInput.fill('test-input');
await expect(solutionFormButton).toBeEnabled();
});
});