From 3216108ca1a9921e37c58feedb29277f98f8970a Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Fri, 8 Nov 2024 14:54:38 -0800 Subject: [PATCH] test(segment): fix flaky gesture test and re-enable (#30008) Issue number: internal --------- ## What is the current behavior? There's a flaky test that was disabled for segment. It's been known that gesture tests are prone to be flaky. ## What is the new behavior? - Fixed the test by switching to the improved `dragElementBy` function ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information N/A --- .../segment/test/segment-events.e2e.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/components/segment/test/segment-events.e2e.ts b/core/src/components/segment/test/segment-events.e2e.ts index 71aa7bdf80f..676e92b1c2e 100644 --- a/core/src/components/segment/test/segment-events.e2e.ts +++ b/core/src/components/segment/test/segment-events.e2e.ts @@ -1,5 +1,5 @@ import { expect } from '@playwright/test'; -import { configs, test } from '@utils/test/playwright'; +import { configs, test, dragElementBy } from '@utils/test/playwright'; /** * This behavior does not vary across modes/directions. @@ -105,8 +105,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => }); }); - // TODO FW-3021 - test.describe.skip('when the pointer is released', () => { + test.describe('when the pointer is released', () => { test('should emit if the value has changed', async ({ page }) => { test.info().annotations.push({ type: 'issue', @@ -136,14 +135,22 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => const ionChangeSpy = await page.spyOnEvent('ionChange'); + const segment = page.locator('ion-segment'); const firstButton = page.locator('ion-segment-button[value="1"]'); const lastButton = page.locator('ion-segment-button[value="3"]'); - await firstButton.hover(); - await page.mouse.down(); - - await lastButton.hover(); - await page.mouse.up(); + /* + * `dragByX` should represent the total width of all segment buttons, + * excluding the first half of the first button and the second half + * of the last button. This calculation accounts for dragging from + * the center of the first button to the center of the last button. + */ + const segmentWidth = await segment.boundingBox().then((box) => (box ? box.width : 0)); + const firstButtonWidth = await firstButton.boundingBox().then((box) => (box ? box.width : 0)); + const lastButtonWidth = await lastButton.boundingBox().then((box) => (box ? box.width : 0)); + const dragByX = segmentWidth - firstButtonWidth / 2 - lastButtonWidth / 2; + + await dragElementBy(firstButton, page, dragByX); expect(ionChangeSpy).toHaveReceivedEventDetail({ value: '3' }); expect(ionChangeSpy).toHaveReceivedEventTimes(1);