-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
dev-toolbar.test.js
324 lines (248 loc) · 11.8 KB
/
dev-toolbar.test.js
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
const test = testFactory({
root: './fixtures/dev-toolbar/',
});
let devServer;
test.beforeAll(async ({ astro }) => {
devServer = await astro.startDevServer();
});
test.afterAll(async () => {
await devServer.stop();
});
test.describe('Dev Toolbar', () => {
test('dev toolbar exists in the page', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const devToolbar = page.locator('astro-dev-toolbar');
await expect(devToolbar).toHaveCount(1);
});
test('shows app name on hover', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:home"]');
const appButtonTooltip = appButton.locator('.item-tooltip');
await appButton.hover();
await expect(appButtonTooltip).toBeVisible();
});
test('can open Astro app', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:home"]');
await appButton.click();
const astroAppCanvas = toolbar.locator(
'astro-dev-toolbar-app-canvas[data-app-id="astro:home"]'
);
const astroWindow = astroAppCanvas.locator('astro-dev-toolbar-window');
await expect(astroWindow).toHaveCount(1);
await expect(astroWindow).toBeVisible();
// Toggle app off
await appButton.click();
await expect(astroWindow).not.toBeVisible();
});
test('show integration app', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/view-transition-a'));
let toolbar = page.locator('astro-dev-toolbar');
let appButton = toolbar.locator('button[data-app-id="astro:home"]');
await appButton.click();
let astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:home"]');
let astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card');
await page.waitForSelector('astro-dev-toolbar-card');
await expect(astroToolbarCards.first()).toBeVisible();
let consolePromise = page.waitForEvent('console');
await page.click('#go-to-b');
await consolePromise;
toolbar = page.locator('astro-dev-toolbar');
appButton = toolbar.locator('button[data-app-id="astro:home"]');
await appButton.click();
astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:home"]');
astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card');
await page.waitForSelector('astro-dev-toolbar-card');
await expect(astroToolbarCards.first()).toBeVisible();
});
test('xray shows highlights and tooltips', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:xray"]');
await appButton.click();
const xrayCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:xray"]');
const xrayHighlight = xrayCanvas.locator('astro-dev-toolbar-highlight');
await expect(xrayHighlight).toBeVisible();
await xrayHighlight.hover();
const xrayHighlightTooltip = xrayHighlight.locator('astro-dev-toolbar-tooltip');
await expect(xrayHighlightTooltip).toBeVisible();
// Toggle app off
await appButton.click();
await expect(xrayHighlight).not.toBeVisible();
await expect(xrayHighlightTooltip).not.toBeVisible();
});
test('xray shows no islands message when there are none', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/xray-no-islands'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:xray"]');
await appButton.click();
const xrayCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:xray"]');
const auditHighlight = xrayCanvas.locator('astro-dev-toolbar-highlight');
await expect(auditHighlight).not.toBeVisible();
const xrayWindow = xrayCanvas.locator('astro-dev-toolbar-window');
await expect(xrayWindow).toHaveCount(1);
await expect(xrayWindow).toBeVisible();
await expect(xrayWindow.locator('astro-dev-toolbar-icon[icon=lightbulb]')).toBeVisible();
});
test('audit shows higlights and tooltips', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:audit"]');
await appButton.click();
const auditCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:audit"]');
const auditHighlights = auditCanvas.locator('astro-dev-toolbar-highlight');
for (const auditHighlight of await auditHighlights.all()) {
await expect(auditHighlight).toBeVisible();
await auditHighlight.hover();
const auditHighlightTooltip = auditHighlight.locator('astro-dev-toolbar-tooltip');
await expect(auditHighlightTooltip).toBeVisible();
}
// Toggle app off
await appButton.click();
});
test('audit shows no issues message when there are no issues', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/audit-no-warning'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:audit"]');
await appButton.click();
const auditCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:audit"]');
const auditHighlight = auditCanvas.locator('astro-dev-toolbar-highlight');
await expect(auditHighlight).not.toBeVisible();
const auditWindow = auditCanvas.locator('astro-dev-toolbar-window');
await expect(auditWindow).toHaveCount(1);
await expect(auditWindow).toBeVisible();
await expect(auditWindow.locator('astro-dev-toolbar-icon[icon=check-circle]')).toBeVisible();
});
test('audit shows a window with list of problems', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:audit"]');
await appButton.click();
const auditCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:audit"]');
const auditWindow = auditCanvas.locator('astro-dev-toolbar-window');
await expect(auditWindow).toHaveCount(1);
await expect(auditWindow).toBeVisible();
// Toggle app off
await appButton.click();
await expect(auditWindow).not.toBeVisible();
});
test('adjusts tooltip position if off-screen', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/tooltip-position'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:audit"]');
await appButton.click();
const auditCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:audit"]');
const auditHighlights = auditCanvas.locator('astro-dev-toolbar-highlight');
for (const highlight of await auditHighlights.all()) {
await expect(highlight).toBeVisible();
await highlight.hover();
const tooltip = highlight.locator('astro-dev-toolbar-tooltip');
await expect(tooltip).toBeVisible();
const tooltipBox = await tooltip.boundingBox();
const { clientWidth, clientHeight } = await page.evaluate(() => ({
clientWidth: document.documentElement.clientWidth,
clientHeight: document.documentElement.clientHeight,
}));
expect(tooltipBox.x + tooltipBox.width).toBeLessThan(clientWidth);
expect(tooltipBox.y + tooltipBox.height).toBeLessThan(clientHeight);
}
});
test('can open Settings app', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="astro:settings"]');
await appButton.click();
const settingsAppCanvas = toolbar.locator(
'astro-dev-toolbar-app-canvas[data-app-id="astro:settings"]'
);
const settingsWindow = settingsAppCanvas.locator('astro-dev-toolbar-window');
await expect(settingsWindow).toHaveCount(1);
await expect(settingsWindow).toBeVisible();
// Toggle app off
await appButton.click();
await expect(settingsWindow).not.toBeVisible();
});
test('Opening a app closes the currently opened app', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
let appButton = toolbar.locator('button[data-app-id="astro:settings"]');
await appButton.click();
const settingsAppCanvas = toolbar.locator(
'astro-dev-toolbar-app-canvas[data-app-id="astro:settings"]'
);
const settingsWindow = settingsAppCanvas.locator('astro-dev-toolbar-window');
await expect(settingsWindow).toHaveCount(1);
await expect(settingsWindow).toBeVisible();
// Click the astro app
appButton = toolbar.locator('button[data-app-id="astro:home"]');
await appButton.click();
const astroAppCanvas = toolbar.locator(
'astro-dev-toolbar-app-canvas[data-app-id="astro:home"]'
);
const astroWindow = astroAppCanvas.locator('astro-dev-toolbar-window');
await expect(astroWindow).toHaveCount(1);
await expect(astroWindow).toBeVisible();
await expect(settingsWindow).not.toBeVisible();
});
test('Settings app contains message on disabling the toolbar', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
let appButton = toolbar.locator('button[data-app-id="astro:settings"]');
await appButton.click();
const settingsAppCanvas = toolbar.locator(
'astro-dev-toolbar-app-canvas[data-app-id="astro:settings"]'
);
const settingsWindow = settingsAppCanvas.locator('astro-dev-toolbar-window');
await expect(settingsWindow).toHaveCount(1);
await expect(settingsWindow).toBeVisible();
const hideToolbar = settingsWindow.getByRole('heading', { name: 'Hide toolbar' });
await expect(hideToolbar).toBeVisible();
});
test('supports third-party apps', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="my-plugin"]');
await appButton.click();
const myAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="my-plugin"]');
const myAppWindow = myAppCanvas.locator('astro-dev-toolbar-window');
await expect(myAppWindow).toHaveCount(1);
await expect(myAppWindow).toBeVisible();
// Toggle app off
await appButton.click();
await expect(myAppWindow).not.toBeVisible();
});
test('islands include their server and client render time', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const island = page.locator('astro-island');
await expect(island).toHaveCount(1);
const serverRenderTime = await island.getAttribute('server-render-time');
const clientRenderTime = await island.getAttribute('client-render-time');
expect(serverRenderTime).not.toBe(null);
expect(clientRenderTime).not.toBe(null);
});
test('apps can show notifications', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
const appButton = toolbar.locator('button[data-app-id="my-plugin"]');
await appButton.click();
const customAppNotification = appButton.locator('.icon .notification');
await expect(customAppNotification).toHaveAttribute('data-active');
await expect(customAppNotification).toHaveAttribute('data-level', 'warning');
await expect(customAppNotification).toBeVisible();
});
test('can quit apps by clicking outside the window', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
const toolbar = page.locator('astro-dev-toolbar');
for (const appId of ['astro:home', 'astro:audit', 'astro:xray', 'astro:settings']) {
const appButton = toolbar.locator(`button[data-app-id="${appId}"]`);
await appButton.click();
await expect(appButton).toHaveClass('item active');
await page.click('body');
await expect(appButton).not.toHaveClass('active');
}
});
});