Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new levels of notification for dev toolbar apps #10252

Merged
merged 11 commits into from
Mar 8, 2024
Prev Previous commit
Next Next commit
test: add test
  • Loading branch information
Princesseuh committed Feb 27, 2024
commit 1d17316d5748664b4eff70119aa25d1c8c3c70a4
14 changes: 14 additions & 0 deletions packages/astro/e2e/dev-toolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,18 @@ test.describe('Dev Toolbar', () => {
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();
});
});
10 changes: 9 additions & 1 deletion packages/astro/e2e/fixtures/dev-toolbar/custom-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default {
id: 'my-plugin',
name: 'My Plugin',
icon: 'astro:logo',
init(canvas) {
init(canvas, eventTarget) {
const astroWindow = document.createElement('astro-dev-toolbar-window');
const myButton = document.createElement('astro-dev-toolbar-button');
myButton.size = 'medium';
Expand All @@ -13,6 +13,14 @@ export default {
console.log('Clicked!');
});

eventTarget.dispatchEvent(
new CustomEvent("toggle-notification", {
detail: {
level: "warning",
},
})
);

astroWindow.appendChild(myButton);

canvas.appendChild(astroWindow);
Expand Down
Loading