Skip to content

Commit 7e5b413

Browse files
committed
adds tests for input segment
1 parent a66dd00 commit 7e5b413

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed
Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1-
21
import React from 'react';
32
import { render } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
44

55
import { DateInputSegment } from '.';
66

7-
describe('packages/date-input-segment', () => {
8-
test('condition', () => {
9-
10-
})
11-
})
7+
describe('packages/date-picker/date-input-segment', () => {
8+
describe('Typing', () => {
9+
test('Typing a number sets the value', async () => {
10+
const result = render(<DateInputSegment segment="day" />);
11+
const input = result.getByRole('spinbutton');
12+
await userEvent.type(input, '12');
13+
expect(input).toHaveValue('12');
14+
});
15+
test('Typing letters does not the value', async () => {
16+
const result = render(<DateInputSegment segment="day" />);
17+
const input = result.getByRole('spinbutton');
18+
await userEvent.type(input, 'abc');
19+
expect(input).toHaveValue('');
20+
});
21+
});
22+
describe('Arrow Keys', () => {
23+
test('ArrowUp increments value', async () => {
24+
const result = render(<DateInputSegment segment="day" />);
25+
const input = result.getByRole('spinbutton');
26+
await userEvent.type(input, '{arrowup}');
27+
expect(input).toHaveValue('01');
28+
});
29+
test('ArrowDown decrements value', async () => {
30+
const result = render(<DateInputSegment segment="day" />);
31+
const input = result.getByRole('spinbutton');
32+
await userEvent.type(input, '{arrowup}{arrowup}{arrowdown}');
33+
expect(input).toHaveValue('01');
34+
});
35+
});
36+
});

packages/date-picker/src/DateInputSegment/DateInputSegment.stories.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { StoryFn } from '@storybook/react';
2+
import { StoryFn, StoryObj } from '@storybook/react';
3+
import { userEvent, within } from '@storybook/testing-library';
34

45
import LeafyGreenProvider from '@leafygreen-ui/leafygreen-provider';
56
import { StoryMetaType } from '@leafygreen-ui/lib';
@@ -62,4 +63,21 @@ const Template: StoryFn<typeof DateInputSegment> = props => (
6263

6364
export const Basic = Template.bind({});
6465

66+
export const Type: StoryObj<typeof DateInputSegment> = {
67+
play: async ({ canvasElement }) => {
68+
const canvas = within(canvasElement);
69+
const input = canvas.getByRole('spinbutton');
70+
await userEvent.type(input, '12');
71+
},
72+
};
73+
74+
export const ArrowUp: StoryObj<typeof DateInputSegment> = {
75+
play: async ({ canvasElement }) => {
76+
const canvas = within(canvasElement);
77+
const input = canvas.getByRole('spinbutton');
78+
input.focus();
79+
await userEvent.type(input, '{arrowup}');
80+
},
81+
};
82+
6583
export const Generated = () => {};

packages/date-picker/src/DateInputSegment/DateInputSegment.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
77
import { Size } from '@leafygreen-ui/tokens';
88
import { useUpdatedBaseFontSize } from '@leafygreen-ui/typography';
99

10-
import { useDatePickerContext } from '../DatePickerContext';
10+
import { useDatePickerContext } from '../DatePickerContext/DatePickerContext';
1111

1212
import {
1313
charsPerSegment,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { DateInputSegment } from './DateInputSegment';
2+
export { DateInputSegmentProps } from './DateInputSegment.types';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { DatePicker } from './DatePicker';
2-
export { DatePickerProps } from './DatePicker.types';
2+
export { type DatePickerProps } from './DatePicker.types';

packages/date-picker/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { DatePicker, DatePickerProps } from './DatePicker';
1+
export { DatePicker, type DatePickerProps } from './DatePicker';

0 commit comments

Comments
 (0)