forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
material-docs.spec.ts
198 lines (146 loc) · 6.94 KB
/
material-docs.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { test as base, expect, Page } from '@playwright/test';
import kebabCase from 'lodash/kebabCase';
import FEATURE_TOGGLE from 'docs/src/featureToggle';
import { TestFixture } from './playwright.config';
const test = base.extend<TestFixture>({});
test.describe('Material docs', () => {
test('should have correct link with hash in the TOC', async ({ page }) => {
await page.goto('/material-ui/getting-started/installation/');
const anchors = page.locator('[aria-label="Page table of contents"] ul a');
const firstAnchor = anchors.first();
const textContent = await firstAnchor.textContent();
await expect(firstAnchor).toHaveAttribute(
'href',
`/material-ui/getting-started/installation/#${kebabCase(textContent || '')}`,
);
});
test('[zh] should have correct link with hash in the TOC', async ({ page }) => {
test.skip(
(process.env.CIRCLE_BRANCH || '').startsWith('pull'),
'There is no languages on the deploy preview',
);
await page.goto('/zh/material-ui/getting-started/installation/');
const anchors = page.locator('main nav ul a');
const firstAnchor = anchors.first();
const textContent = await firstAnchor.textContent();
await expect(firstAnchor).toHaveAttribute(
'href',
`/zh/material-ui/getting-started/installation/#${kebabCase(textContent || '')}`,
);
});
test.describe('Demo page', () => {
test('should have correct link for API section', async ({ page }) => {
await page.goto('/material-ui/react-card/');
const anchors = page.locator('div > h2#api ~ ul a');
const firstAnchor = anchors.first();
const textContent = await firstAnchor.textContent();
await expect(firstAnchor).toHaveAttribute(
'href',
`/material-ui/api/${kebabCase(textContent || '')}/`,
);
});
test('should have correct API link to mui-base', async ({ page }) => {
await page.goto('/material-ui/react-tabs/');
await expect(page.locator('a[href="/base/api/tab-panel-unstyled/"]')).toContainText(
'<TabPanelUnstyled />',
);
await expect(page.locator('a[href="/base/api/tab-unstyled/"]')).toContainText(
'<TabUnstyled />',
);
await expect(page.locator('a[href="/base/api/tabs-list-unstyled/"]')).toContainText(
'<TabsListUnstyled />',
);
await expect(page.locator('a[href="/base/api/tabs-unstyled/"]')).toContainText(
'<TabsUnstyled />',
);
});
test('should have correct link for sidebar anchor', async ({ page }) => {
await page.goto('/material-ui/react-card/');
const anchor = page.locator('nav[aria-label="documentation"] .app-drawer-active');
await expect(anchor).toHaveAttribute('href', '/material-ui/react-card/');
await expect(anchor).toHaveText('Card');
});
test('should have plural url for Tabs', async ({ page }) => {
await page.goto('/material-ui/react-tabs/');
const anchor = page.locator('nav[aria-label="documentation"] .app-drawer-active');
await expect(anchor).toHaveAttribute('href', '/material-ui/react-tabs/');
await expect(anchor).toHaveText('Tabs');
});
test('should have plural url for Breadcrumbs', async ({ page }) => {
await page.goto('/material-ui/react-breadcrumbs/');
const anchor = page.locator('nav[aria-label="documentation"] .app-drawer-active');
await expect(anchor).toHaveAttribute('href', '/material-ui/react-breadcrumbs/');
await expect(anchor).toHaveText('Breadcrumbs');
});
test('should not have react- prefix for icons', async ({ page }) => {
await page.goto('/material-ui/icons/');
const anchor = page.locator('nav[aria-label="documentation"] .app-drawer-active');
await expect(anchor).toHaveAttribute('href', '/material-ui/icons/');
await expect(anchor).toHaveText('Icons');
});
test('should not have react- prefix for material-icons', async ({ page }) => {
await page.goto('/material-ui/material-icons/');
const anchor = page.locator('nav[aria-label="documentation"] .app-drawer-active');
await expect(anchor).toHaveAttribute('href', '/material-ui/material-icons/');
await expect(anchor).toHaveText('Material Icons');
});
});
test.describe('API page', () => {
test('should have correct link for sidebar anchor', async ({ page }) => {
await page.goto('/material-ui/api/card/');
const anchor = page.locator('nav[aria-label="documentation"] ul a:text-is("Card")');
await expect(anchor).toHaveAttribute('app-drawer-active', '');
await expect(anchor).toHaveAttribute('href', '/material-ui/api/card/');
});
test('all the links in the main content should have correct prefix', async ({ page }) => {
await page.goto('/material-ui/api/card/');
const anchors = page.locator('div#main-content a');
const handles = await anchors.elementHandles();
const links = await Promise.all(handles.map((elm) => elm.getAttribute('href')));
links.forEach((link) => {
if (
link &&
['/getting-started', '/customization', '/guides', '/discover-more'].some((path) =>
link.includes(path),
)
) {
expect(link).toMatch(/^\/(material-ui|system)/);
}
expect(link).not.toMatch(/\/components/); // there should be no `/components` in the url anymore
if (link && link.startsWith('/system')) {
expect(link.startsWith('/system')).toBeTruthy();
expect(link.match(/\/system{1}/g)).toHaveLength(1); // should not have repeated `/system/system/*`
}
});
});
});
test.describe('Search', () => {
const retryToggleSearch = async (page: Page, count = 3) => {
try {
await page.keyboard.press('Meta+k');
await page.waitForSelector('input#docsearch-input', { timeout: 2000 });
} catch (error) {
if (count === 0) {
throw error;
}
await retryToggleSearch(page, count - 1);
}
};
test('should have correct link when searching component', async ({ page }) => {
await page.goto('/material-ui/getting-started/installation/');
await page.waitForLoadState('networkidle'); // wait for docsearch
await retryToggleSearch(page);
await page.type('input#docsearch-input', 'card', { delay: 50 });
const anchor = page.locator('.DocSearch-Hits a:has-text("Card")');
await expect(anchor.first()).toHaveAttribute('href', '/material-ui/react-card/');
});
test('should have correct link when searching API', async ({ page }) => {
await page.goto('/material-ui/getting-started/installation/');
await page.waitForLoadState('networkidle'); // wait for docsearch
await retryToggleSearch(page);
await page.type('input#docsearch-input', 'card api', { delay: 50 });
const anchor = page.locator('.DocSearch-Hits a:has-text("Card API")');
await expect(anchor.first()).toHaveAttribute('href', '/material-ui/api/card/');
});
});
});