diff --git a/packages/circuit-ui/components/DateInput/DateInputService.spec.ts b/packages/circuit-ui/components/DateInput/DateInputService.spec.ts index 7925d1a052..0d22581ce9 100644 --- a/packages/circuit-ui/components/DateInput/DateInputService.spec.ts +++ b/packages/circuit-ui/components/DateInput/DateInputService.spec.ts @@ -19,9 +19,28 @@ import { getDateSegments } from './DateInputService.js'; describe('DateInputService', () => { describe('getDateSegments', () => { - it.todo('should', () => { - const actual = getDateSegments(); - expect(actual).toBe('TODO:'); + it.each([ + // locale, year, month, day + ['en-US', [4, 0, 2]], + ['de-DE', [4, 2, 0]], + ['pt-BR', [4, 2, 0]], + ])('should order the segments for the %s locale', (locale, indices) => { + const actual = getDateSegments(locale); + const year = actual.findIndex(({ type }) => type === 'year'); + const month = actual.findIndex(({ type }) => type === 'month'); + const day = actual.findIndex(({ type }) => type === 'day'); + expect([year, month, day]).toEqual(indices); + }); + + it.each([ + // locale, literal + ['en-US', '/'], + ['de-DE', '.'], + ['pt-BR', '/'], + ])('should return the literal for the %s locale', (locale, literal) => { + const actual = getDateSegments(locale); + const literalSegment = actual.find(({ type }) => type === 'literal'); + expect(literalSegment?.value).toBe(literal); }); }); }); diff --git a/packages/circuit-ui/components/DateInput/DateInputService.ts b/packages/circuit-ui/components/DateInput/DateInputService.ts index ad75258589..836d135858 100644 --- a/packages/circuit-ui/components/DateInput/DateInputService.ts +++ b/packages/circuit-ui/components/DateInput/DateInputService.ts @@ -13,12 +13,12 @@ * limitations under the License. */ +import { Temporal } from 'temporal-polyfill'; import { formatDateTimeToParts } from '@sumup-oss/intl'; import type { Locale } from '../../util/i18n.js'; -// TODO: Replace with Temporal.PlainDate -const TEST_VALUE = new Date(2024, 3, 8); +const TEST_VALUE = new Temporal.PlainDate(2024, 3, 8); export function getDateSegments(locale?: Locale) { const parts = formatDateTimeToParts(TEST_VALUE, locale);