|
| 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 | + // Wait for the image to load and be visible |
| 63 | + const imgLocator = page.locator('ion-segment-content#third ion-img'); |
| 64 | + await imgLocator.waitFor({ state: 'visible', timeout: 10000 }); |
| 65 | + |
| 66 | + // Wait for any layout adjustments |
| 67 | + await page.waitForChanges(); |
| 68 | + |
| 69 | + // Check that the third content is visible |
| 70 | + const segmentView = page.locator('ion-segment-view'); |
| 71 | + const thirdContent = page.locator('ion-segment-content#third'); |
| 72 | + |
| 73 | + const viewBox = await segmentView.boundingBox(); |
| 74 | + const contentBox = await thirdContent.boundingBox(); |
| 75 | + |
| 76 | + if (!viewBox || !contentBox) throw new Error('Bounding box not found'); |
| 77 | + |
| 78 | + // Allow a small tolerance to account for subpixel rendering, |
| 79 | + // scrollbars, or layout rounding differences |
| 80 | + const tolerance = 10; |
| 81 | + expect(contentBox.x).toBeGreaterThanOrEqual(viewBox.x); |
| 82 | + expect(contentBox.x + contentBox.width).toBeLessThanOrEqual(viewBox.x + viewBox.width + tolerance); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments