Download slate/playwright/integration/examples/paste-html.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/slate/playwright/integration/examples/paste-html.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/slate/playwright/integration/examples/paste-html.test.ts
-
curl -L -o paste-html.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/slate/playwright/integration/examples/paste-html.test.ts
1.29 kB
| import { test, expect, Page } from '@playwright/test' | |
| test.describe('paste html example', () => { | |
| test.beforeEach( | |
| async ({ page }) => | |
| await page.goto('http://localhost:3000/examples/paste-html') | |
| ) | |
| const pasteHtml = async (page: Page, htmlContent: string) => { | |
| await page.getByRole('textbox').click() | |
| await page.getByRole('textbox').selectText() | |
| await page.keyboard.press('Backspace') | |
| await page | |
| .getByRole('textbox') | |
| .evaluate((el: HTMLElement, htmlContent: string) => { | |
| const clipboardEvent = Object.assign( | |
| new Event('paste', { bubbles: true, cancelable: true }), | |
| { | |
| clipboardData: { | |
| getData: (type = 'text/html') => htmlContent, | |
| types: ['text/html'], | |
| }, | |
| } | |
| ) | |
| el.dispatchEvent(clipboardEvent) | |
| }, htmlContent) | |
| } | |
| test('pasted bold text uses <strong>', async ({ page }) => { | |
| await pasteHtml(page, '<strong>Hello Bold</strong>') | |
| expect(await page.locator('strong').textContent()).toContain('Hello') | |
| }) | |
| test('pasted code uses <code>', async ({ page }) => { | |
| await pasteHtml(page, '<code>console.log("hello from slate!")</code>') | |
| expect(await page.locator('code').textContent()).toContain('slate!') | |
| }) | |
| }) | |