Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions e2e/playground.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ test.describe('file tabs', () => {
'src/app/child.component.html',
'src/app/child.component.ts',
]);
await expect(playground.locator('#playground_angular_src_app_example_component_html')).toBeVisible();
const panels = playground.getByRole('tabpanel', { includeHidden: true });
await expect(panels.nth(0)).toBeVisible();

await fileTabs.getByRole('tab', { name: 'src/app/child.component.ts' }).click();
await expect(playground.locator('#playground_angular_src_app_child_component_ts')).toBeVisible();
await expect(playground.locator('#playground_angular_src_app_example_component_html')).toBeHidden();
await expect(panels.nth(3)).toBeVisible();
await expect(panels.nth(0)).toBeHidden();
});

test('select the first file after switching frameworks', async ({ page }) => {
Expand All @@ -98,7 +99,7 @@ test.describe('file tabs', () => {
'aria-selected',
'true'
);
await expect(playground.locator('#playground_vue_src_components_Example_vue')).toBeVisible();
await expect(playground.getByRole('tabpanel', { includeHidden: true }).nth(0)).toBeVisible();
});

test('move focus with the arrow keys and select with Enter', async ({ page }) => {
Expand Down Expand Up @@ -128,8 +129,7 @@ test('StackBlitz receives every file of a multi-file example', async ({ page, co
const playground = await openChildStatePlayground(page);
await expect(playground.locator('.playground__tabs')).toBeVisible();

// The StackBlitz button is the first icon button, and has no accessible name to find it by.
await playground.locator('.playground__control-group--end button').first().click();
await playground.getByRole('button', { name: 'Open in StackBlitz' }).click();
const form = await request;

for (const [file, source] of [
Expand All @@ -151,6 +151,8 @@ test.describe('mode', () => {
const last = playgrounds.last();

await first.getByRole('button', { name: 'MD', exact: true }).click();
await expect(first.getByRole('button', { name: 'MD', exact: true })).toHaveAttribute('aria-pressed', 'true');
await expect(first.getByRole('button', { name: 'iOS', exact: true })).toHaveAttribute('aria-pressed', 'false');
await expect(first.locator('iframe[src*="ionic:mode=md"]')).toBeVisible();
await expect(first.locator('iframe[src*="ionic:mode=ios"]')).toBeHidden();

Expand Down Expand Up @@ -184,3 +186,22 @@ test.describe('mode', () => {
await expect(playground.getByRole('button', { name: 'MD', exact: true })).toBeFocused();
});
});

test('the demo follows the site theme, including after a reset', async ({ page }) => {
await page.addInitScript(() => localStorage.setItem('theme', 'dark'));
// `docusaurus serve` redirects `demo.html` to a clean URL without the base path, which loads the home page instead.
await page.route('**/demo.html*', (route) =>
route.fulfill({ path: `build${new URL(route.request().url()).pathname.replace(/^\/docs/, '')}` })
);
await page.goto('api/alert');
const playground = page.locator('.playground').first();
const demo = playground.frameLocator('iframe[src*="ionic:mode=ios"]').locator('html');

await expect(demo).toHaveClass(/ion-theme-dark/);

// Marks the demo, so the check below waits for the reloaded one.
await demo.evaluate((html) => html.setAttribute('data-before-reset', ''));
await playground.getByRole('button', { name: 'Reset demo' }).click();
await expect(demo).not.toHaveAttribute('data-before-reset');
await expect(demo).toHaveClass(/ion-theme-dark/);
});
2 changes: 1 addition & 1 deletion src/components/global/Playground/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import angular_example_component_ts from './angular/example_component_ts.md';

| Option | Description |
| --- | --- |
| `size` | Height of the demo: `xsmall`, `small` (default), `medium`, `large`, `xlarge`, or any CSS height such as `300px`. |
| `size` | Height of the demo: `xsmall`, `small` (default), `medium`, `large`, `xlarge`, or a pixel value such as `300px`. |
| `mode` | Locks the demo to `ios` or `md` and disables the button for the other mode. |
| `devicePreview` | Renders the demo inside a device frame. Refer to [Device Frame](#show-example-within-a-device-frame-iphonepixel-5). |
| `showConsole` | Shows a console below the demo with anything the demo logs through `console.log`, `console.warn`, or `console.error`. |
Expand Down
Loading
Loading