Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LG-3943: remove todays date from DatePickerMenu.stories #2174

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fifty-turkeys-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/date-picker': patch
---

Modify `DatePickerMenu.stories.tsx` to exclude the current date, as it caused daily chromatic changes.
Original file line number Diff line number Diff line change
Expand Up @@ -78,55 +78,19 @@ export default meta;

type DatePickerMenuStoryType = StoryObj<typeof DatePickerMenu>;

export const Basic: DatePickerMenuStoryType = {
render: args => {
MockDate.reset();
const [value, setValue] = useState<DateType>(null);

const date = new Date(Date.now());
const props = omit(args, [...contextPropNames, 'isOpen']);
const refEl = useRef<HTMLDivElement>(null);
return (
<DatePickerProvider value={value} setValue={setValue}>
<div style={{ minHeight: '50vh' }}>
<InlineCode ref={refEl}>
Today:{' '}
{new Intl.DateTimeFormat('en-GB', {
dateStyle: 'full',
}).format(date)}
</InlineCode>
<DatePickerMenu {...props} refEl={refEl} />
</div>
</DatePickerProvider>
);
},
};

Basic.parameters = {
chromatic: { disableSnapshot: true },
};

export const WithValue: DatePickerMenuStoryType = {
render: args => {
MockDate.reset();

const props = omit(args, [...contextPropNames, 'isOpen']);
const refEl = useRef<HTMLDivElement>(null);
const date = new Date(Date.now());
const withValueDate = new Date(2023, Month.September, 10);
return (
<DatePickerProvider
value={newUTC(2023, Month.September, 10)}
setValue={() => {}}
>
<div style={{ minHeight: '50vh' }}>
<InlineCode ref={refEl}>
Today:{' '}
{new Intl.DateTimeFormat('en-GB', {
dateStyle: 'full',
}).format(date)}
</InlineCode>
<br></br>
<InlineCode ref={refEl}>
Value:{' '}
{new Intl.DateTimeFormat('en-GB', {
Expand Down Expand Up @@ -156,15 +120,14 @@ export const MockedToday: DatePickerMenuStoryType = {

const props = omit(args, [...contextPropNames, 'isOpen']);
const refEl = useRef<HTMLDivElement>(null);
const date = new Date(Date.now());
return (
<DatePickerProvider value={value} setValue={setValue}>
<div style={{ minHeight: '50vh' }}>
<InlineCode ref={refEl}>
Today:{' '}
Mocked Today:{' '}
{new Intl.DateTimeFormat('en-GB', {
dateStyle: 'full',
}).format(date)}
}).format(mockToday)}
</InlineCode>
<DatePickerMenu {...props} refEl={refEl} />
</div>
Expand All @@ -188,8 +151,8 @@ type DatePickerMenuInteractionTestType = Omit<DatePickerMenuStoryType, 'play'> &
* Chromatic Interaction tests
*/

export const InitialFocusToday: DatePickerMenuInteractionTestType = {
...Basic,
export const InitialFocusMockedToday: DatePickerMenuInteractionTestType = {
...MockedToday,
play: async ctx => {
const { findByRole } = within(ctx.canvasElement.parentElement!);
await findByRole('listbox');
Expand All @@ -208,47 +171,47 @@ export const InitialFocusValue: DatePickerMenuInteractionTestType = {
export const LeftArrowKey: DatePickerMenuInteractionTestType = {
...WithValue,
play: async ctx => {
await InitialFocusToday.play(ctx);
await InitialFocusMockedToday.play(ctx);
userEvent.keyboard('{arrowleft}');
},
};

export const RightArrowKey: DatePickerMenuInteractionTestType = {
...WithValue,
play: async ctx => {
await InitialFocusToday.play(ctx);
await InitialFocusMockedToday.play(ctx);
userEvent.keyboard('{arrowright}');
},
};

export const UpArrowKey: DatePickerMenuInteractionTestType = {
...WithValue,
play: async ctx => {
await InitialFocusToday.play(ctx);
await InitialFocusMockedToday.play(ctx);
userEvent.keyboard('{arrowup}');
},
};

export const DownArrowKey: DatePickerMenuInteractionTestType = {
...WithValue,
play: async ctx => {
await InitialFocusToday.play(ctx);
await InitialFocusMockedToday.play(ctx);
userEvent.keyboard('{arrowdown}');
},
};

export const UpToPrevMonth: DatePickerMenuInteractionTestType = {
...WithValue,
play: async ctx => {
await InitialFocusToday.play(ctx);
await InitialFocusMockedToday.play(ctx);
userEvent.keyboard('{arrowup}{arrowup}');
},
};

export const DownToNextMonth: DatePickerMenuInteractionTestType = {
...WithValue,
play: async ctx => {
await InitialFocusToday.play(ctx);
await InitialFocusMockedToday.play(ctx);
userEvent.keyboard('{arrowdown}{arrowdown}{arrowdown}');
},
};
Expand Down
Loading