|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { configs, test } from '@utils/test/playwright'; |
| 3 | + |
| 4 | +/** |
| 5 | + * This behavior does not vary across directions |
| 6 | + */ |
| 7 | +configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { |
| 8 | + test.describe(title('segment-view: disabled'), () => { |
| 9 | + test('should not have visual regressions', async ({ page }) => { |
| 10 | + await page.setContent( |
| 11 | + ` |
| 12 | + <style> |
| 13 | + /* Styles are here to show the disabled state */ |
| 14 | + ion-segment-view { |
| 15 | + height: 100px; |
| 16 | + background: #3880ff; |
| 17 | + } |
| 18 | + </style> |
| 19 | +
|
| 20 | + <ion-segment-view disabled> |
| 21 | + <ion-segment-content id="paid">Paid</ion-segment-content> |
| 22 | + <ion-segment-content id="free">Free</ion-segment-content> |
| 23 | + <ion-segment-content id="top">Top</ion-segment-content> |
| 24 | + </ion-segment-view> |
| 25 | + `, |
| 26 | + config |
| 27 | + ); |
| 28 | + |
| 29 | + const segment = page.locator('ion-segment-view'); |
| 30 | + |
| 31 | + await expect(segment).toHaveScreenshot(screenshot(`segment-view-disabled`)); |
| 32 | + }); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +/** |
| 37 | + * This behavior does not vary across modes/directions |
| 38 | + */ |
| 39 | +configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => { |
| 40 | + test.describe(title('segment-view: disabled'), () => { |
| 41 | + test('should show the second content when first segment content is disabled', async ({ page }) => { |
| 42 | + await page.setContent( |
| 43 | + ` |
| 44 | + <ion-segment disabled> |
| 45 | + <ion-segment-button content-id="paid" value="paid"> |
| 46 | + <ion-label>Paid</ion-label> |
| 47 | + </ion-segment-button> |
| 48 | + <ion-segment-button content-id="free" value="free"> |
| 49 | + <ion-label>Free</ion-label> |
| 50 | + </ion-segment-button> |
| 51 | + <ion-segment-button content-id="top" value="top"> |
| 52 | + <ion-label>Top</ion-label> |
| 53 | + </ion-segment-button> |
| 54 | + </ion-segment> |
| 55 | + <ion-segment-view> |
| 56 | + <ion-segment-content disabled id="paid">Paid</ion-segment-content> |
| 57 | + <ion-segment-content id="free">Free</ion-segment-content> |
| 58 | + <ion-segment-content id="top">Top</ion-segment-content> |
| 59 | + </ion-segment-view> |
| 60 | + `, |
| 61 | + config |
| 62 | + ); |
| 63 | + |
| 64 | + const segmentContent = page.locator('ion-segment-content[id="free"]'); |
| 65 | + await expect(segmentContent).toBeInViewport(); |
| 66 | + }); |
| 67 | + |
| 68 | + test.only('should scroll to the third content and update the segment value when the second segment content is disabled', async ({ page }) => { |
| 69 | + await page.setContent( |
| 70 | + ` |
| 71 | + <ion-segment> |
| 72 | + <ion-segment-button content-id="paid" value="paid"> |
| 73 | + <ion-label>Paid</ion-label> |
| 74 | + </ion-segment-button> |
| 75 | + <ion-segment-button disabled content-id="free" value="free"> |
| 76 | + <ion-label>Free</ion-label> |
| 77 | + </ion-segment-button> |
| 78 | + <ion-segment-button content-id="top" value="top"> |
| 79 | + <ion-label>Top</ion-label> |
| 80 | + </ion-segment-button> |
| 81 | + </ion-segment> |
| 82 | + <ion-segment-view> |
| 83 | + <ion-segment-content id="paid">Paid</ion-segment-content> |
| 84 | + <ion-segment-content disabled id="free">Free</ion-segment-content> |
| 85 | + <ion-segment-content id="top">Top</ion-segment-content> |
| 86 | + </ion-segment-view> |
| 87 | + `, |
| 88 | + config |
| 89 | + ); |
| 90 | + |
| 91 | + const segmentContent = page.locator('ion-segment-content[id="top"]'); |
| 92 | + await segmentContent.scrollIntoViewIfNeeded(); |
| 93 | + await expect(segmentContent).toBeInViewport(); |
| 94 | + |
| 95 | + const segment = page.locator('ion-segment'); |
| 96 | + expect(await segment.evaluate((el: HTMLIonSegmentElement) => el.value)).toBe('top'); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments