Skip to content

Commit ef4c1cd

Browse files
committed
test(datetime-button): add tests for datetime constraints
- should default to exact current time with no constraints - should obey minuteValues constraint - should obey hourValues constraint - should obey monthValues constraint
1 parent 4824122 commit ef4c1cd

1 file changed

Lines changed: 150 additions & 0 deletions

File tree

core/src/components/datetime-button/test/basic/datetime-button.e2e.ts

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,154 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
344344
await expect(page.locator('ion-datetime-button')).toContainText('Thu, November 02 01:22 AM');
345345
});
346346
});
347+
348+
test.describe(title('datetime-button: datetime constraints'), () => {
349+
test('should default to exact current time with no constraints', async ({ page }) => {
350+
const fixedTime = new Date('2026-06-18T17:54:54.518Z');
351+
await page.clock.setFixedTime(fixedTime);
352+
353+
await page.setContent(
354+
`
355+
<ion-datetime-button datetime="datetime"></ion-datetime-button>
356+
<ion-datetime id="datetime" presentation="date-time" locale="en-US"></ion-datetime>
357+
<script>
358+
const datetime = document.querySelector('ion-datetime');
359+
datetime.formatOptions = {
360+
date: {
361+
weekday: "short",
362+
month: "long",
363+
day: "2-digit"
364+
},
365+
time: {
366+
hour: "2-digit",
367+
minute: "2-digit"
368+
}
369+
}
370+
</script>
371+
`,
372+
config
373+
);
374+
await page.locator('.datetime-ready').waitFor();
375+
376+
const dateFormat = new Intl.DateTimeFormat('en-US', {
377+
weekday: 'short',
378+
month: 'long',
379+
day: '2-digit',
380+
});
381+
const timeFormat = new Intl.DateTimeFormat('en-US', {
382+
hour: '2-digit',
383+
minute: '2-digit',
384+
});
385+
386+
await expect(page.locator('#date-button')).toContainText(dateFormat.format(fixedTime));
387+
await expect(page.locator('#time-button')).toContainText(timeFormat.format(fixedTime));
388+
});
389+
390+
test('should obey minuteValues constraint', async ({ page }) => {
391+
const fixedTime = new Date('2026-06-18T17:54:54.518Z');
392+
await page.clock.setFixedTime(fixedTime);
393+
394+
await page.setContent(
395+
`
396+
<ion-datetime-button datetime="datetime"></ion-datetime-button>
397+
<ion-datetime id="datetime" presentation="time" locale="en-US" minute-values="0"></ion-datetime>
398+
<script>
399+
const datetime = document.querySelector('ion-datetime');
400+
datetime.formatOptions = {
401+
time: {
402+
hour: "2-digit",
403+
minute: "2-digit"
404+
}
405+
}
406+
</script>
407+
`,
408+
config
409+
);
410+
await page.locator('.datetime-ready').waitFor();
411+
412+
await page.pause();
413+
414+
const expectedTime = fixedTime;
415+
expectedTime.setMinutes(0);
416+
417+
const timeFormat = new Intl.DateTimeFormat('en-US', {
418+
hour: '2-digit',
419+
minute: '2-digit',
420+
});
421+
422+
await expect(page.locator('#time-button')).toContainText(timeFormat.format(expectedTime));
423+
});
424+
425+
test('should obey hourValues constraint', async ({ page }) => {
426+
const fixedTime = new Date('2026-06-18T17:54:54.518Z');
427+
await page.clock.setFixedTime(fixedTime);
428+
429+
await page.setContent(
430+
`
431+
<ion-datetime-button datetime="datetime"></ion-datetime-button>
432+
<ion-datetime id="datetime" presentation="time" locale="en-US" hour-values="0"></ion-datetime>
433+
<script>
434+
const datetime = document.querySelector('ion-datetime');
435+
datetime.formatOptions = {
436+
time: {
437+
hour: "2-digit",
438+
minute: "2-digit"
439+
}
440+
}
441+
</script>
442+
`,
443+
config
444+
);
445+
await page.locator('.datetime-ready').waitFor();
446+
447+
await page.pause();
448+
449+
const expectedTime = fixedTime;
450+
expectedTime.setHours(0);
451+
452+
const timeFormat = new Intl.DateTimeFormat('en-US', {
453+
hour: '2-digit',
454+
minute: '2-digit',
455+
});
456+
457+
await expect(page.locator('#time-button')).toContainText(timeFormat.format(expectedTime));
458+
});
459+
460+
test('should obey monthValues constraint', async ({ page }) => {
461+
const fixedTime = new Date('2026-06-18T17:54:54.518Z');
462+
await page.clock.setFixedTime(fixedTime);
463+
464+
await page.setContent(
465+
`
466+
<ion-datetime-button datetime="datetime"></ion-datetime-button>
467+
<ion-datetime id="datetime" presentation="date" locale="en-US" month-values="1"></ion-datetime>
468+
<script>
469+
const datetime = document.querySelector('ion-datetime');
470+
datetime.formatOptions = {
471+
date: {
472+
weekday: "short",
473+
month: "long",
474+
day: "2-digit"
475+
}
476+
}
477+
</script>
478+
`,
479+
config
480+
);
481+
await page.locator('.datetime-ready').waitFor();
482+
483+
await page.pause();
484+
485+
const expectedTime = fixedTime;
486+
expectedTime.setMonth(0);
487+
488+
const dateFormat = new Intl.DateTimeFormat('en-US', {
489+
weekday: 'short',
490+
month: 'long',
491+
day: '2-digit',
492+
});
493+
494+
await expect(page.locator('#date-button')).toContainText(dateFormat.format(expectedTime));
495+
});
496+
});
347497
});

0 commit comments

Comments
 (0)