Skip to content

Commit 3216108

Browse files
authored
test(segment): fix flaky gesture test and re-enable (#30008)
Issue number: internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> 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? <!-- Please describe the behavior or changes that are being added by this PR. --> - Fixed the test by switching to the improved `dragElementBy` function ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> N/A
1 parent 4bffe97 commit 3216108

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

core/src/components/segment/test/segment-events.e2e.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import { configs, test } from '@utils/test/playwright';
2+
import { configs, test, dragElementBy } from '@utils/test/playwright';
33

44
/**
55
* This behavior does not vary across modes/directions.
@@ -105,8 +105,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
105105
});
106106
});
107107

108-
// TODO FW-3021
109-
test.describe.skip('when the pointer is released', () => {
108+
test.describe('when the pointer is released', () => {
110109
test('should emit if the value has changed', async ({ page }) => {
111110
test.info().annotations.push({
112111
type: 'issue',
@@ -136,14 +135,22 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
136135

137136
const ionChangeSpy = await page.spyOnEvent('ionChange');
138137

138+
const segment = page.locator('ion-segment');
139139
const firstButton = page.locator('ion-segment-button[value="1"]');
140140
const lastButton = page.locator('ion-segment-button[value="3"]');
141141

142-
await firstButton.hover();
143-
await page.mouse.down();
144-
145-
await lastButton.hover();
146-
await page.mouse.up();
142+
/*
143+
* `dragByX` should represent the total width of all segment buttons,
144+
* excluding the first half of the first button and the second half
145+
* of the last button. This calculation accounts for dragging from
146+
* the center of the first button to the center of the last button.
147+
*/
148+
const segmentWidth = await segment.boundingBox().then((box) => (box ? box.width : 0));
149+
const firstButtonWidth = await firstButton.boundingBox().then((box) => (box ? box.width : 0));
150+
const lastButtonWidth = await lastButton.boundingBox().then((box) => (box ? box.width : 0));
151+
const dragByX = segmentWidth - firstButtonWidth / 2 - lastButtonWidth / 2;
152+
153+
await dragElementBy(firstButton, page, dragByX);
147154

148155
expect(ionChangeSpy).toHaveReceivedEventDetail({ value: '3' });
149156
expect(ionChangeSpy).toHaveReceivedEventTimes(1);

0 commit comments

Comments
 (0)