Skip to content

Commit a93db26

Browse files
committed
Add tests for the DateInputService
1 parent 29e5ef5 commit a93db26

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

packages/circuit-ui/components/DateInput/DateInputService.spec.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,28 @@ import { getDateSegments } from './DateInputService.js';
1919

2020
describe('DateInputService', () => {
2121
describe('getDateSegments', () => {
22-
it.todo('should', () => {
23-
const actual = getDateSegments();
24-
expect(actual).toBe('TODO:');
22+
it.each([
23+
// locale, year, month, day
24+
['en-US', [4, 0, 2]],
25+
['de-DE', [4, 2, 0]],
26+
['pt-BR', [4, 2, 0]],
27+
])('should order the segments for the %s locale', (locale, indices) => {
28+
const actual = getDateSegments(locale);
29+
const year = actual.findIndex(({ type }) => type === 'year');
30+
const month = actual.findIndex(({ type }) => type === 'month');
31+
const day = actual.findIndex(({ type }) => type === 'day');
32+
expect([year, month, day]).toEqual(indices);
33+
});
34+
35+
it.each([
36+
// locale, literal
37+
['en-US', '/'],
38+
['de-DE', '.'],
39+
['pt-BR', '/'],
40+
])('should return the literal for the %s locale', (locale, literal) => {
41+
const actual = getDateSegments(locale);
42+
const literalSegment = actual.find(({ type }) => type === 'literal');
43+
expect(literalSegment?.value).toBe(literal);
2544
});
2645
});
2746
});

packages/circuit-ui/components/DateInput/DateInputService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* limitations under the License.
1414
*/
1515

16+
import { Temporal } from 'temporal-polyfill';
1617
import { formatDateTimeToParts } from '@sumup-oss/intl';
1718

1819
import type { Locale } from '../../util/i18n.js';
1920

20-
// TODO: Replace with Temporal.PlainDate
21-
const TEST_VALUE = new Date(2024, 3, 8);
21+
const TEST_VALUE = new Temporal.PlainDate(2024, 3, 8);
2222

2323
export function getDateSegments(locale?: Locale) {
2424
const parts = formatDateTimeToParts(TEST_VALUE, locale);

0 commit comments

Comments
 (0)