Skip to content

Commit

Permalink
Add tests for the DateInputService
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Oct 22, 2024
1 parent e875a7d commit b63fdbc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 22 additions & 3 deletions packages/circuit-ui/components/DateInput/DateInputService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
4 changes: 2 additions & 2 deletions packages/circuit-ui/components/DateInput/DateInputService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b63fdbc

Please sign in to comment.