forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternet-presence-settings.spec.ts
99 lines (87 loc) · 3.03 KB
/
internet-presence-settings.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
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
const settingsPageElement = {
githubInput: 'internet-github-input',
githubCheckmark: 'internet-github-check',
linkedinCheckmark: 'internet-linkedin-check',
twitterCheckmark: 'internet-twitter-check',
personalWebsiteCheckmark: 'internet-website-check',
flashMessageAlert: 'flash-message',
internetPresenceForm: 'internet-presence'
} as const;
test.beforeEach(async ({ page }) => {
// Reset input values
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
await page.goto('/certifieduser');
if (!process.env.CI) {
await page.getByRole('button', { name: 'Preview custom 404 page' }).click();
}
await page.getByRole('button', { name: 'Edit my profile' }).click();
});
test.describe('Your Internet Presence', () => {
test.skip(({ browserName }) => browserName === 'webkit', 'flaky on Safari');
test('should display the section with save button being disabled', async ({
page
}) => {
await expect(
page.getByRole('heading', {
level: 2,
name: translations.settings.headings.internet
})
).toBeVisible();
await expect(
page
.getByTestId(settingsPageElement.internetPresenceForm)
.getByRole('button', { name: translations.buttons.save })
).toBeVisible();
});
const socials = [
{
name: 'github',
url: 'https://github.com/certified-user',
label: 'GitHub',
checkTestId: settingsPageElement.githubCheckmark
},
{
name: 'linkedin',
url: 'https://www.linkedin.com/in/certified-user',
label: 'LinkedIn',
checkTestId: settingsPageElement.linkedinCheckmark
},
{
name: 'twitter',
url: 'https://twitter.com/certified-user',
label: 'Twitter',
checkTestId: settingsPageElement.twitterCheckmark
},
{
name: 'website',
url: 'https://certified-user.com',
label: translations.settings.labels.personal,
checkTestId: settingsPageElement.personalWebsiteCheckmark
}
];
socials.forEach(social => {
test(`should hide ${social.name} checkmark by default`, async ({
page
}) => {
await expect(page.getByTestId(social.checkTestId)).toBeHidden();
});
test(`should update ${social.name} URL`, async ({ page }) => {
const socialInput = page.getByRole('textbox', { name: social.label });
await expect(socialInput).toBeVisible();
await socialInput.fill(social.url);
const socialCheckmark = page.getByTestId(social.checkTestId);
await expect(socialCheckmark).toBeVisible();
const saveButton = page
.getByTestId(settingsPageElement.internetPresenceForm)
.getByRole('button', { name: translations.buttons.save });
await expect(saveButton).toBeVisible();
await saveButton.click();
await expect(page.getByRole('alert').first()).toContainText(
'We have updated your social links'
);
});
});
});