-
Notifications
You must be signed in to change notification settings - Fork 13.4k
test(drag-element, item-sliding): prevent full swipe #31097
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
Changes from 4 commits
f07a5e0
03a4a77
fbd4983
b1df2e2
f6c4aee
b840229
c055092
ed95dac
f7df147
c763b6a
27a8b6a
92bcffe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { configs, test, dragElementBy } from '@utils/test/playwright'; | ||
|
|
||
| /** | ||
| * Drag distances that reveal options without crossing the full swipe threshold | ||
| * (optsWidth + SWIPE_MARGIN). A narrower options panel requires a shorter drag. | ||
| */ | ||
| const DRAG_DISTANCE_TWO_OPTIONS = 150; | ||
|
|
||
| /** | ||
| * item-sliding doesn't have mode-specific styling, | ||
| * but the child components, item-options and item-option, do. | ||
|
|
@@ -10,28 +16,29 @@ import { configs, test, dragElementBy } from '@utils/test/playwright'; | |
| */ | ||
| configs({ modes: ['ionic-md', 'ios', 'md'] }).forEach(({ title, screenshot, config }) => { | ||
| test.describe(title('item-sliding: icons'), () => { | ||
| test('should not have visual regressions', async ({ page }) => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto(`/src/components/item-sliding/test/icons`, config); | ||
| }); | ||
|
|
||
| const itemIDs = ['iconsOnly', 'iconsStart', 'iconsEnd', 'iconsTop', 'iconsBottom']; | ||
| for (const itemID of itemIDs) { | ||
| const item = page.locator(`#${itemID}`); | ||
| ['iconsOnly', 'iconsStart', 'iconsEnd', 'iconsTop', 'iconsBottom'].forEach((position) => { | ||
| test(`${position} - should not have visual regressions`, async ({ page }) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By breaking it apart, it's easier to determine which test failed. |
||
| const item = page.locator(`#${position}`); | ||
|
|
||
| /** | ||
| * Negative dragByX value to drag element from the right to the left | ||
| * to reveal the options on the right side. | ||
| * Positive dragByX value to drag element from the left to the right | ||
| * to reveal the options on the left side. | ||
| */ | ||
| const dragByX = config.direction === 'rtl' ? 150 : -150; | ||
| const dragByX = config.direction === 'rtl' ? DRAG_DISTANCE_TWO_OPTIONS : -DRAG_DISTANCE_TWO_OPTIONS; | ||
|
|
||
| await dragElementBy(item, page, dragByX, 0, undefined, undefined, true, 20); | ||
| await dragElementBy(item, page, dragByX, 0, undefined, undefined, undefined, 15); | ||
| await page.waitForChanges(); | ||
|
|
||
| // Convert camelCase ids to kebab-case for screenshot file names | ||
| const itemIDKebab = itemID.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | ||
| await expect(item).toHaveScreenshot(screenshot(`item-sliding-${itemIDKebab}`)); | ||
| } | ||
| const positionKebab = position.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | ||
| await expect(item).toHaveScreenshot(screenshot(`item-sliding-${positionKebab}`)); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,37 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { configs, test, dragElementBy } from '@utils/test/playwright'; | ||
|
|
||
| /** | ||
| * Drag distances that reveal options without crossing the full swipe threshold | ||
| * (optsWidth + SWIPE_MARGIN). A narrower options panel requires a shorter drag. | ||
| */ | ||
| const DRAG_DISTANCE_TWO_OPTIONS = 150; | ||
|
|
||
| /** | ||
| * The shapes on the `item-option` do not vary by direction | ||
| * when they are not being dragged. | ||
| */ | ||
| configs({ modes: ['ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { | ||
| test.describe(title('item-sliding: shapes'), () => { | ||
| test('should not have visual regressions when not expanded', async ({ page }) => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto(`/src/components/item-sliding/test/shapes`, config); | ||
| }); | ||
|
|
||
| const itemIDs = ['round', 'soft', 'rectangular']; | ||
| for (const itemID of itemIDs) { | ||
| const item = page.locator(`#${itemID}`); | ||
| ['round', 'soft', 'rectangular'].forEach((shape) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By breaking it apart, it's easier to determine which test failed. |
||
| test(`${shape} - should not have visual regressions when not expanded`, async ({ page }) => { | ||
| const item = page.locator(`#${shape}`); | ||
|
|
||
| /** | ||
| * Negative dragByX value to drag element from the right to the left | ||
| * to reveal the options on the right side. | ||
| */ | ||
| const dragByX = -150; | ||
| const dragByX = -DRAG_DISTANCE_TWO_OPTIONS; | ||
|
|
||
| await dragElementBy(item, page, dragByX); | ||
| await dragElementBy(item, page, dragByX, 0, undefined, undefined, undefined, 15); | ||
| await page.waitForChanges(); | ||
|
|
||
| await expect(item).toHaveScreenshot(screenshot(`item-sliding-${itemID}`)); | ||
| } | ||
| await expect(item).toHaveScreenshot(screenshot(`item-sliding-${shape}`)); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { configs, test, dragElementBy } from '@utils/test/playwright'; | ||
|
|
||
| /** | ||
| * Drag distances that reveal options without crossing the full swipe threshold | ||
| * (optsWidth + SWIPE_MARGIN). A narrower options panel requires a shorter drag. | ||
| */ | ||
| const DRAG_DISTANCE_TWO_OPTIONS = 150; | ||
|
|
||
| /** | ||
| * This behavior does not vary across modes | ||
| */ | ||
|
|
@@ -16,7 +22,7 @@ configs({ modes: ['ionic-md', 'md', 'ios'], directions: ['ltr'] }).forEach(({ ti | |
| * Negative dragByX value to drag element from the right to the left | ||
| * to reveal the options on the right side. | ||
| */ | ||
| const dragByX = -150; | ||
| const dragByX = -DRAG_DISTANCE_TWO_OPTIONS; | ||
|
|
||
| await dragElementBy(item, page, dragByX); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still uses the default
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the reason why as comments: c763b6a |
||
| await page.waitForChanges(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big upgrade from the old
forloop! Nice work!