Skip to content

Commit 42e44ad

Browse files
committed
test(segment-view): add a test for scrolling to a dynamic height content
1 parent d61cd78 commit 42e44ad

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { expect } from '@playwright/test';
2+
import { configs, test } from '@utils/test/playwright';
3+
4+
/**
5+
* This behavior does not vary across modes/directions
6+
*/
7+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
8+
test.describe(title('segment-view: dynamic height'), () => {
9+
test('should show the third content when clicking the third button', async ({ page, skip }) => {
10+
// Skip this test on Chrome and Firefox
11+
skip.browser('firefox', 'Original issue only happens on Safari.');
12+
skip.browser('chromium', 'Original issue only happens on Safari.');
13+
14+
await page.setContent(
15+
`
16+
<style>
17+
ion-segment-content {
18+
display: flex;
19+
align-items: center;
20+
justify-content: center;
21+
height: fit-content;
22+
}
23+
</style>
24+
25+
<ion-segment>
26+
<ion-segment-button value="first" content-id="first">
27+
<ion-label>First</ion-label>
28+
</ion-segment-button>
29+
<ion-segment-button value="second" content-id="second">
30+
<ion-label>Second</ion-label>
31+
</ion-segment-button>
32+
<ion-segment-button value="third" content-id="third">
33+
<ion-label>Third</ion-label>
34+
</ion-segment-button>
35+
</ion-segment>
36+
<ion-segment-view>
37+
<ion-segment-content id="first">
38+
Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora
39+
quaeritis. Summus brains sit, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum
40+
mauris. Hi mindless mortuis soulless creaturas, imo evil stalking monstra adventus resi dentevil vultus
41+
comedat cerebella viventium. Qui animated corpse, cricket bat max brucks terribilem incessu zomby. The
42+
voodoo sacerdos flesh eater, suscitat mortuos comedere carnem virus. Zonbi tattered for solum oculi eorum
43+
defunctis go lum cerebro. Nescio brains an Undead zombies. Sicut malus putrid voodoo horror. Nigh tofth eliv
44+
</ion-segment-content>
45+
<ion-segment-content id="second">
46+
<ion-input value="" label="Email"></ion-input>
47+
</ion-segment-content>
48+
<ion-segment-content id="third">
49+
<ion-img class="img-part" src="https://picsum.photos/200/300"></ion-img>
50+
</ion-segment-content>
51+
</ion-segment-view>
52+
`,
53+
config
54+
);
55+
56+
// Click the third button
57+
await page.locator('ion-segment-button[value="third"]').click();
58+
59+
// Wait for the content to be scrolled
60+
await page.waitForChanges();
61+
62+
// Check that the third content is visible
63+
const segmentView = page.locator('ion-segment-view');
64+
const thirdContent = page.locator('ion-segment-content#third');
65+
66+
const viewBox = await segmentView.boundingBox();
67+
const contentBox = await thirdContent.boundingBox();
68+
69+
if (!viewBox || !contentBox) throw new Error('Bounding box not found');
70+
71+
// Allow a small tolerance to account for subpixel rendering,
72+
// scrollbars, or layout rounding differences
73+
const tolerance = 10;
74+
expect(contentBox.x).toBeGreaterThanOrEqual(viewBox.x);
75+
expect(contentBox.x + contentBox.width).toBeLessThanOrEqual(viewBox.x + viewBox.width + tolerance);
76+
});
77+
});
78+
});

0 commit comments

Comments
 (0)