-
Notifications
You must be signed in to change notification settings - Fork 57
feat(web): onImagePress #690
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
Open
hejsztynx
wants to merge
6
commits into
@kacperzolkiewski/feat-on-image-press
Choose a base branch
from
@ksienkiewicz/feat-web-enriched-text-on-image-press
base: @kacperzolkiewski/feat-on-image-press
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
946c613
feat: onImagePress
hejsztynx 7b614da
test: onImagePress tests
hejsztynx daacfb8
docs: update
hejsztynx 6767b26
fix: checkbox pointer event
hejsztynx 1c76620
feat: cleanup
hejsztynx eab9d31
fix: onImagePress when no explicit width and height attrs present
hejsztynx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| import { test, expect, type Page } from '@playwright/test'; | ||
|
|
||
| test.setTimeout(90_000); | ||
|
|
||
| const IMAGE_ROUTE = '**/pw-e2e-ok.png'; | ||
| const IMAGE_SRC = '/pw-e2e-ok.png'; | ||
| const BROKEN_IMAGE_ROUTE = '**/pw-e2e-broken.png'; | ||
| const BROKEN_IMAGE_SRC = '/pw-e2e-broken.png'; | ||
| const PNG_BODY = Buffer.from( | ||
| 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==', | ||
| 'base64' | ||
| ); | ||
|
|
||
| const sel = { | ||
| root: '[data-testid="test-enriched-text-root"]', | ||
| htmlInput: '[data-testid="test-enriched-text-html-input"]', | ||
| setValueButton: '[data-testid="test-enriched-text-set-value-button"]', | ||
| valueOutput: '[data-testid="test-enriched-text-value-output"]', | ||
| display: '[data-testid="test-enriched-text-display"]', | ||
| displayInner: '[data-testid="test-enriched-text-display"] .et-view', | ||
| imagePressOutput: '[data-testid="test-enriched-text-image-press-output"]', | ||
| } as const; | ||
|
|
||
| const VISIBILITY_TIMEOUT_MS = 1_000; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.route(IMAGE_ROUTE, async (route) => { | ||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: 'image/png', | ||
| body: PNG_BODY, | ||
| }); | ||
| }); | ||
| await page.route(BROKEN_IMAGE_ROUTE, (route) => route.abort()); | ||
| }); | ||
|
|
||
| async function gotoTestEnrichedText(page: Page): Promise<void> { | ||
| await page.goto('/test-enriched-text'); | ||
| await page.waitForSelector(sel.displayInner); | ||
| } | ||
|
|
||
| async function setEnrichedTextValue(page: Page, html: string): Promise<void> { | ||
| await page.fill(sel.htmlInput, html); | ||
| await page.click(sel.setValueButton); | ||
|
|
||
| await expect | ||
| .poll(async () => (await page.locator(sel.valueOutput).textContent()) ?? '') | ||
| .toBe(html); | ||
| } | ||
|
|
||
| function imagePress(page: Page) { | ||
| return page.locator(sel.imagePressOutput); | ||
| } | ||
|
|
||
| test.describe('EnrichedText image press', () => { | ||
| test('pressing an image emits onImagePress with the image', async ({ | ||
| page, | ||
| }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue( | ||
| page, | ||
| `<html><p>Look <img src="${IMAGE_SRC}" width="32" height="32" /> now.</p></html>` | ||
| ); | ||
|
|
||
| await expect(imagePress(page)).toHaveText('null'); | ||
|
|
||
| await page.locator(`${sel.displayInner} img`).click(); | ||
|
|
||
| await expect | ||
| .poll(async () => | ||
| JSON.parse((await imagePress(page).textContent()) || 'null') | ||
| ) | ||
| .toEqual({ image: { uri: IMAGE_SRC, width: 32, height: 32 } }); | ||
| }); | ||
|
|
||
| test('pressing an image surrounded by styled text still emits onImagePress', async ({ | ||
| page, | ||
| }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue( | ||
| page, | ||
| `<html><p>A <b>bold</b> <img src="${IMAGE_SRC}" width="120" height="60" /> here.</p></html>` | ||
| ); | ||
|
|
||
| await page.locator(`${sel.displayInner} img`).click(); | ||
|
|
||
| await expect | ||
| .poll(async () => | ||
| JSON.parse((await imagePress(page).textContent()) || 'null') | ||
| ) | ||
| .toEqual({ image: { uri: IMAGE_SRC, width: 120, height: 60 } }); | ||
| }); | ||
|
|
||
| test('pressing non-image text does not emit onImagePress', async ({ | ||
| page, | ||
| }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue( | ||
| page, | ||
| `<html><p>Plain text with an <img src="${IMAGE_SRC}" width="32" height="32" />.</p></html>` | ||
| ); | ||
|
|
||
| await page | ||
| .locator(`${sel.displayInner} p`) | ||
| .click({ position: { x: 2, y: 2 } }); | ||
|
|
||
| await expect(imagePress(page)).toHaveText('null'); | ||
| }); | ||
|
|
||
| test('pressing an empty-src placeholder does not emit onImagePress', async ({ | ||
| page, | ||
| }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue( | ||
| page, | ||
| '<html><p>Before <img src="" width="40" height="40" /> after.</p></html>' | ||
| ); | ||
|
|
||
| await expect(page.locator(`${sel.displayInner} img`)).toBeVisible({ | ||
| timeout: VISIBILITY_TIMEOUT_MS, | ||
| }); | ||
|
|
||
| await page.locator(`${sel.displayInner} img`).click(); | ||
|
|
||
| await expect(imagePress(page)).toHaveText('null'); | ||
| }); | ||
|
|
||
| test('pressing a broken-URL placeholder does emit onImagePress', async ({ | ||
| page, | ||
| }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue( | ||
| page, | ||
| `<html><p>Before <img src="${BROKEN_IMAGE_SRC}" width="40" height="40" /> after.</p></html>` | ||
| ); | ||
|
|
||
| await expect(page.locator(`${sel.displayInner} img`)).toBeVisible({ | ||
| timeout: VISIBILITY_TIMEOUT_MS, | ||
| }); | ||
|
|
||
| await page.locator(`${sel.displayInner} img`).click(); | ||
|
|
||
| await expect | ||
| .poll(async () => | ||
| JSON.parse((await imagePress(page).textContent()) || 'null') | ||
| ) | ||
| .toEqual({ image: { uri: BROKEN_IMAGE_SRC, width: 40, height: 40 } }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('EnrichedText press inside lists', () => { | ||
| const listCases = [ | ||
| { | ||
| name: 'unordered list', | ||
| open: '<ul>', | ||
| close: '</ul>', | ||
| }, | ||
| { | ||
| name: 'ordered list', | ||
| open: '<ol>', | ||
| close: '</ol>', | ||
| }, | ||
| { | ||
| name: 'checkbox list', | ||
| open: '<ul data-type="checkbox">', | ||
| close: '</ul>', | ||
| }, | ||
| ]; | ||
|
|
||
| for (const c of listCases) { | ||
| test(`pressing an image inside a ${c.name} emits onImagePress`, async ({ | ||
| page, | ||
| }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue( | ||
| page, | ||
| `<html>${c.open}<li><p>See <img src="${IMAGE_SRC}" width="28" height="28" /> tiny</p></li><li><p>Other item</p></li>${c.close}</html>` | ||
| ); | ||
|
|
||
| await expect(imagePress(page)).toHaveText('null'); | ||
|
|
||
| await page.locator(`${sel.displayInner} li img`).click(); | ||
|
|
||
| await expect | ||
| .poll(async () => | ||
| JSON.parse((await imagePress(page).textContent()) || 'null') | ||
| ) | ||
| .toEqual({ image: { uri: IMAGE_SRC, width: 28, height: 28 } }); | ||
| }); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.