|
1 | 1 | import { expect } from '@playwright/test'; |
2 | 2 | import { configs, test } from '@utils/test/playwright'; |
3 | 3 |
|
4 | | -/** |
5 | | - * This behavior does not vary across directions |
6 | | - */ |
7 | 4 | configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { |
8 | 5 | test.describe(title('datetime: show adjacent days'), () => { |
9 | 6 | test('should not have visual regressions', async ({ page }) => { |
@@ -54,7 +51,11 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { |
54 | 51 | const datetime = page.locator('#display'); |
55 | 52 | await expect(datetime).toHaveScreenshot(screenshot(`datetime-show-adjacent-days-display`)); |
56 | 53 | }); |
| 54 | + }); |
| 55 | +}); |
57 | 56 |
|
| 57 | +configs({ directions: ['ltr', 'rtl'] }).forEach(({ title, config }) => { |
| 58 | + test.describe(title('datetime: show adjacent days'), () => { |
58 | 59 | test('should return the same date format on current month days and on adjacent days', async ({ page }) => { |
59 | 60 | await page.setContent( |
60 | 61 | ` |
@@ -124,5 +125,49 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { |
124 | 125 | value: '2022-11-22T16:22:00', |
125 | 126 | }); |
126 | 127 | }); |
| 128 | + |
| 129 | + test('should navigate to previous month via swipe and then select adjacent day from prior month', async ({ page }) => { |
| 130 | + await page.setContent( |
| 131 | + ` |
| 132 | + <ion-datetime show-adjacent-days="true" value="2026-02-14T16:22:00.000Z" presentation="date"></ion-datetime> |
| 133 | + `, |
| 134 | + config |
| 135 | + ); |
| 136 | + |
| 137 | + // Wait for the datetime to be ready. |
| 138 | + await page.locator('.datetime-ready').waitFor(); |
| 139 | + const ionChange = await page.spyOnEvent('ionChange'); |
| 140 | + const calendarMonthYear = page.locator('ion-datetime .calendar-month-year'); |
| 141 | + const calendarBody = page.locator('ion-datetime .calendar-body'); |
| 142 | + |
| 143 | + // Wait for the month to be visible. |
| 144 | + await expect(calendarMonthYear).toHaveText('February 2026'); |
| 145 | + |
| 146 | + // Scroll to the previous month. |
| 147 | + await calendarBody.evaluate((el: HTMLElement) => { |
| 148 | + const rtl = document.documentElement.dir === 'rtl'; |
| 149 | + el.scrollLeft += rtl ? el.clientWidth * 2 : -el.clientWidth * 2; |
| 150 | + }); |
| 151 | + |
| 152 | + // Wait for the month to change. |
| 153 | + await page.waitForChanges(); |
| 154 | + await expect(calendarMonthYear).toHaveText('January 2026'); |
| 155 | + |
| 156 | + // Select the adjacent day from the prior month. |
| 157 | + const dec31Adjacent = page.locator( |
| 158 | + '.calendar-day-adjacent-day[data-month="12"][data-year="2025"][data-day="31"]' |
| 159 | + ); |
| 160 | + await dec31Adjacent.click(); |
| 161 | + |
| 162 | + // Wait for the month to change. |
| 163 | + await page.waitForChanges(); |
| 164 | + |
| 165 | + // Wait for the month to be visible. |
| 166 | + await expect(calendarMonthYear).toHaveText('December 2025'); |
| 167 | + await ionChange.next(); |
| 168 | + await expect(ionChange).toHaveReceivedEventDetail({ |
| 169 | + value: '2025-12-31T16:22:00', |
| 170 | + }); |
| 171 | + }); |
127 | 172 | }); |
128 | 173 | }); |
0 commit comments