Skip to content

Commit 044cf5f

Browse files
Merge branch 'ROU-11744' of https://github.com/ionic-team/ionic-framework into ROU-11744
2 parents af27af5 + f509523 commit 044cf5f

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,71 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
5151
test('should return the same date format on current month days and on adjacent days', async ({ page }) => {
5252
await page.setContent(
5353
`
54-
<ion-datetime show-adjacent-days="true" locale="en-US" value="2022-10-14T16:22:00.000Z" presentation="date"></ion-datetime>
54+
<ion-datetime show-adjacent-days="true" value="2022-10-14T16:22:00.000Z" presentation="date"></ion-datetime>
5555
`,
5656
config
5757
);
58-
const datetime = page.locator('ion-datetime');
58+
59+
// Wait for the datetime to be ready.
60+
await page.locator('.datetime-ready').waitFor();
61+
5962
const ionChange = await page.spyOnEvent('ionChange');
60-
// Oct 20, 2022
61-
await page.click('.calendar-day[data-month="10"][data-year="2022"][data-day="20"]');
63+
64+
const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');
65+
66+
/**
67+
* Make sure to exclude adjacent days from the query since
68+
* the previous/next month is rendered hidden. This causes
69+
* the query to possibly return different results: one for
70+
* the current month and one from the hidden previous/next
71+
* month.
72+
*/
73+
const october20Button = page.locator(
74+
'[data-month="10"][data-year="2022"][data-day="20"]:not(.calendar-day-adjacent-day)'
75+
);
76+
77+
await october20Button.click();
78+
6279
await ionChange.next();
63-
await expect(ionChange).toHaveReceivedEventDetail({ value: '2022-10-20T16:22:00' });
64-
await expect(datetime).toHaveJSProperty('value', '2022-10-20T16:22:00');
65-
// Nov 1, 2022
66-
await page.click('.calendar-day[data-month="11"][data-year="2022"][data-day="1"]');
80+
await expect(ionChange).toHaveReceivedEventDetail({
81+
value: '2022-10-20T16:22:00',
82+
});
83+
84+
const november1Button = page.locator(
85+
'.calendar-day-adjacent-day[data-month="11"][data-year="2022"][data-day="1"]'
86+
);
87+
88+
await november1Button.click();
89+
// Wait for the datetime to change the month since an adjacent day
90+
// was clicked.
6791
await page.waitForChanges();
92+
93+
// Wait for the title to update to the new month since it changes
94+
// after the month animation finishes.
95+
await expect(calendarMonthYear).toHaveText('November 2022');
96+
6897
await ionChange.next();
69-
await expect(ionChange).toHaveReceivedEventDetail({ value: '2022-11-01T16:22:00' });
70-
await expect(datetime).toHaveJSProperty('value', '2022-11-01T16:22:00');
71-
// Nov 22, 2022
72-
await page.click('.calendar-day[data-month="11"][data-year="2022"][data-day="22"]');
98+
await expect(ionChange).toHaveReceivedEventDetail({
99+
value: '2022-11-01T16:22:00',
100+
});
101+
102+
/**
103+
* Make sure to exclude adjacent days from the query since
104+
* the previous/next month is rendered hidden. This causes
105+
* the query to possibly return different results: one for
106+
* the current month and one from the hidden previous/next
107+
* month.
108+
*/
109+
const november22Button = page.locator(
110+
'[data-month="11"][data-year="2022"][data-day="22"]:not(.calendar-day-adjacent-day)'
111+
);
112+
113+
await november22Button.click();
114+
73115
await ionChange.next();
74-
await expect(ionChange).toHaveReceivedEventDetail({ value: '2022-11-22T16:22:00' });
75-
await expect(datetime).toHaveJSProperty('value', '2022-11-22T16:22:00');
116+
await expect(ionChange).toHaveReceivedEventDetail({
117+
value: '2022-11-22T16:22:00',
118+
});
76119
});
77120
});
78121
});

0 commit comments

Comments
 (0)