forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-modal.spec.ts
153 lines (125 loc) · 4.2 KB
/
delete-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
import { exec } from 'child_process';
import { promisify } from 'util';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import { alertToBeVisible } from './utils/alerts';
const execP = promisify(exec);
test.beforeEach(async ({ page }) => {
await page.goto('/settings');
});
test.afterAll(
async () =>
await Promise.all([
await execP('node ./tools/scripts/seed/seed-demo-user --certified-user'),
await execP('node ./tools/scripts/seed/seed-surveys'),
await execP('node ./tools/scripts/seed/seed-ms-username')
])
);
test.describe('Delete Modal component', () => {
test('should render the modal correctly', async ({ page }) => {
await page
.getByRole('button', { name: translations.settings.danger.delete })
.click();
await expect(
page.getByRole('dialog', {
name: translations.settings.danger['delete-title']
})
).toBeVisible();
await expect(
page.getByText(translations.settings.danger['delete-p1'])
).toBeVisible();
await expect(
page.getByText(translations.settings.danger['delete-p2'])
).toBeVisible();
const supportLink = page.getByRole('link', {
name: '[email protected]'
});
await expect(supportLink).toBeVisible();
await expect(supportLink).toHaveAttribute(
'href',
'mailto:[email protected]'
);
await expect(
page.getByRole('button', { name: translations.settings.danger.nevermind })
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.settings.danger.certain })
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.settings.danger.certain })
).toBeDisabled();
await expect(
page.getByRole('button', { name: translations.buttons.close })
).toBeVisible();
});
test('should close the modal after the user cancels account deleting', async ({
page
}) => {
await page
.getByRole('button', { name: translations.settings.danger.delete })
.click();
await expect(
page.getByRole('dialog', {
name: translations.settings.danger['delete-title']
})
).toBeVisible();
await page
.getByRole('button', { name: translations.settings.danger.nevermind })
.click();
await expect(
page.getByRole('dialog', {
name: translations.settings.danger['delete-title']
})
).not.toBeVisible();
});
test('Delele button should be disabled if user incorrectly fills verify input text', async ({
page
}) => {
await page
.getByRole('button', { name: translations.settings.danger.delete })
.click();
await expect(
page.getByRole('dialog', {
name: translations.settings.danger['delete-title']
})
).toBeVisible();
const verifyDeleteInput = page.getByRole('textbox', {
exact: true
});
await verifyDeleteInput.fill('incorrect text');
await expect(
page.getByRole('button', {
name: translations.settings.danger.certain
})
).toBeDisabled();
});
test('should close the modal and redirect to /learn after the user fills the verify input text and clicks delete', async ({
page
}) => {
await page
.getByRole('button', { name: translations.settings.danger.delete })
.click();
await expect(
page.getByRole('dialog', {
name: translations.settings.danger['delete-title']
})
).toBeVisible();
const verifyDeleteText = translations.settings.danger['verify-delete-text'];
const verifyDeleteInput = page.getByRole('textbox', {
exact: true
});
await verifyDeleteInput.fill(verifyDeleteText);
await page
.getByRole('button', { name: translations.settings.danger.certain })
.click();
await expect(
page.getByRole('dialog', {
name: translations.settings.danger['delete-title']
})
).not.toBeVisible();
await expect(page).toHaveURL(/.*\/learn\/?/);
await alertToBeVisible(page, translations.flash['account-deleted']);
// The user is signed out after their account is deleted
await expect(page.getByRole('link', { name: 'Sign in' })).toHaveCount(2);
});
});