forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink-ms-user.spec.ts
122 lines (109 loc) · 3.85 KB
/
link-ms-user.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
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import { alertToBeVisible } from './utils/alerts';
test.beforeEach(async ({ page }) => {
await page.goto(
'/learn/foundational-c-sharp-with-microsoft/write-your-first-code-using-c-sharp/trophy-write-your-first-code-using-c-sharp'
);
});
test.describe('Link MS user component (signed-out user)', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('should display the page content with a signin CTA', async ({
page
}) => {
await expect(
page.getByRole('heading', {
name: 'Trophy - Write Your First Code Using C#',
level: 1
})
).toBeVisible();
await expect(
page.getByRole('heading', {
name: translations.learn.ms['link-header'],
level: 2
})
).toBeVisible();
await expect(
page.getByText(translations.learn.ms['link-signin'])
).toBeVisible();
// There are 2 sign in button on the page: one in the navbar, and one in the page content
const signInButtons = await page
.getByRole('link', { name: translations.buttons['sign-in'] })
.all();
expect(signInButtons).toHaveLength(2);
});
});
test.describe('Link MS user component (signed-in user)', () => {
test.afterEach(() => {
execSync('node ./tools/scripts/seed/seed-ms-username');
});
test("should recognize the user's MS account", async ({ page }) => {
await expect(
page.getByRole('heading', {
name: 'Trophy - Write Your First Code Using C#',
level: 1
})
).toBeVisible();
await expect(page.locator('main')).toHaveText(
/The Microsoft account with username "certifieduser" is currently linked to your freeCodeCamp account\. If this is not your Microsoft username, remove the link\./
);
});
test('should allow the user to unlink their MS account and display a form for re-link', async ({
page
}) => {
const unlinkButton = page.getByRole('button', {
name: translations.buttons['unlink-account']
});
await expect(unlinkButton).toBeVisible();
await unlinkButton.click();
await alertToBeVisible(page, translations.flash.ms.transcript.unlinked);
await expect(
page.getByRole('heading', {
name: translations.learn.ms['link-header'],
level: 2
})
).toBeVisible();
await expect(page.getByText(translations.learn.ms.unlinked)).toBeVisible();
await expect(
page.getByRole('listitem').filter({
hasText:
'Using a browser where you are logged into your Microsoft account, go to https://learn.microsoft.com/users/me/transcript'
})
).toBeVisible();
await expect(
page
.getByRole('listitem')
.filter({ hasText: translations.learn.ms['link-li-2'] })
).toBeVisible();
await expect(
page
.getByRole('listitem')
.filter({ hasText: translations.learn.ms['link-li-3'] })
).toBeVisible();
await expect(
page
.getByRole('listitem')
.filter({ hasText: translations.learn.ms['link-li-4'] })
).toBeVisible();
await expect(
page.getByRole('listitem').filter({
hasText:
'Paste the URL into the input below, it should look similar to this: https://learn.microsoft.com/LOCALE/users/USERNAME/transcript/ID'
})
).toBeVisible();
await expect(
page
.getByRole('listitem')
.filter({ hasText: translations.learn.ms['link-li-6'] })
).toBeVisible();
const transcriptLinkInput = page.getByLabel(
translations.learn.ms['transcript-label']
);
await expect(transcriptLinkInput).toBeVisible();
await expect(transcriptLinkInput).toHaveAttribute(
'placeholder',
'https://learn.microsoft.com/en-us/users/username/transcript/transcriptId'
);
});
});