forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution-viewer.spec.ts
76 lines (57 loc) · 2.32 KB
/
solution-viewer.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
import { test, expect } from '@playwright/test';
test.describe('Solution Viewer component', () => {
test('renders the modal correctly', async ({ page }) => {
await page.goto(
'/certification/certifieduser/javascript-algorithms-and-data-structures'
);
await page.getByRole('button', { name: /view/i }).first().click();
const projectSolutionViewerModal = page.getByRole('dialog', {
name: 'Solution for'
});
// The modal should show the solution title...
await expect(projectSolutionViewerModal).toBeVisible();
// ...and relevant code file/s
await expect(page.getByText(/js/i)).toBeVisible();
await expect(page.locator('pre').first()).toBeVisible();
const closeButtons = await page
.getByRole('button', { name: 'Close' })
.all();
const topRightCloseButton = closeButtons[0];
await topRightCloseButton.click();
await expect(projectSolutionViewerModal).toBeHidden();
await page.getByRole('button', { name: 'View' }).first().click();
const bottomRightCloseButton = closeButtons[1];
await bottomRightCloseButton.click();
await expect(projectSolutionViewerModal).toBeHidden();
});
test('renders external project links correctly', async ({ page }) => {
await page.goto(
'/certification/certifieduser/front-end-development-libraries'
);
const projectLink = page.getByRole('link', { name: 'View' }).first();
const browserContext = page.context();
const [newPage] = await Promise.all([
browserContext.waitForEvent('page'),
projectLink.click()
]);
await newPage.waitForLoadState();
await expect(newPage).toHaveURL(/^https:\/\/codepen\.io/);
await newPage.close();
});
test('render projects with multiple solutions correctly', async ({
page
}) => {
await page.goto('/certification/certifieduser/quality-assurance-v7');
const dropdownButton = page.getByRole('button', { name: 'View' }).first();
await dropdownButton.click();
await expect(page.getByRole('menu')).toBeVisible();
const sourceLink = page.getByRole('menuitem', { name: /source/i }).first();
const browserContext = page.context();
const [newPage] = await Promise.all([
browserContext.waitForEvent('page'),
sourceLink.click()
]);
await newPage.waitForLoadState();
await newPage.close();
});
});