Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank99 committed Apr 10, 2024
1 parent a7c22dd commit b685b37
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
11 changes: 1 addition & 10 deletions packages/itwinui-react/src/core/Dialog/Dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render, act, screen, fireEvent } from '@testing-library/react';
import { render, act, screen } from '@testing-library/react';
import { Dialog } from './Dialog.js';
import { Button } from '../Buttons/Button.js';
import { userEvent } from '@testing-library/user-event';
Expand Down Expand Up @@ -212,13 +212,4 @@ it('should expose show() and close() methods', () => {
act(() => dialog.close());
act(() => vi.runAllTimers());
expect(dialogElement).not.toBeVisible();

act(() => dialog.show());

// Built-in close should still work
act(() => {
fireEvent.keyDown(dialogElement, { key: 'Escape' });
});

expect(dialogElement).not.toBeVisible();
});
16 changes: 16 additions & 0 deletions testing/e2e/app/routes/Dialog/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import { Dialog } from '@itwin/itwinui-react';

export default function DialogTest() {
const dialog = Dialog.useInstance();

React.useEffect(() => {
dialog.show();
}, [dialog]);

return (
<Dialog setFocus instance={dialog}>
<Dialog.Main>Hello</Dialog.Main>
</Dialog>
);
}
13 changes: 13 additions & 0 deletions testing/e2e/app/routes/Dialog/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test, expect } from '@playwright/test';

test.describe('Dialog triggers', () => {
test('should close dialog when pressing Esc', async ({ page }) => {
await page.goto('/Dialog');

const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();

await page.keyboard.press('Escape');
await expect(dialog).not.toBeVisible();
});
});

0 comments on commit b685b37

Please sign in to comment.