Skip to content

Commit

Permalink
fix(sb): a date comparaison was not consistent across snapshots over …
Browse files Browse the repository at this point in the history
…time
  • Loading branch information
sneko committed Jan 3, 2025
1 parent 8f36edb commit d5bfefc
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meta, StoryFn } from '@storybook/react';
import { mockDateDecorator } from 'storybook-mock-date-decorator';

import { ComponentProps, StoryHelperFactory } from '@ad/.storybook/helpers';
import { playFindAlert, playFindButton } from '@ad/.storybook/testing';
Expand Down Expand Up @@ -36,6 +37,9 @@ const mswCommonParameters = [
}),
];

// [WORKAROUND] Since using the date mock on `NormalStory`, it leaks over other stories when switching the view, so we have to explicitely set a date for others
const workaroundDate = new Date('December 31, 2024 18:00:00 UTC');

const commonComponentProps: ComponentProps<ComponentType> = {
params: {
organizationId: 'b79cb3ba-745e-5d9a-8903-4a02327a7e01',
Expand All @@ -51,6 +55,7 @@ NormalStory.args = {
...commonComponentProps,
};
NormalStory.parameters = {
date: new Date('December 19, 2024 18:00:00 UTC'), // Mock date generation so underlying computed `lastSynchronizationTooOld` returns "false"
msw: {
handlers: [
...mswCommonParameters,
Expand All @@ -65,17 +70,13 @@ NormalStory.parameters = {
type: 'query' as 'query',
path: ['listTicketingSystems'],
response: {
ticketingSystems: [
{
...ticketingSystems[0],
lastSynchronizationAt: new Date(), // Set a recent date so the UI is correct
},
],
ticketingSystems: [ticketingSystems[0]],
},
}),
],
},
};
NormalStory.decorators = [mockDateDecorator];
NormalStory.play = async ({ canvasElement }) => {
await playFindButton(canvasElement, /synchroniser/i);
};
Expand All @@ -87,6 +88,7 @@ DesynchronizedStory.args = {
...commonComponentProps,
};
DesynchronizedStory.parameters = {
date: workaroundDate,
msw: {
handlers: [
...mswCommonParameters,
Expand All @@ -107,6 +109,7 @@ DesynchronizedStory.parameters = {
],
},
};
DesynchronizedStory.decorators = [mockDateDecorator];
DesynchronizedStory.play = async ({ canvasElement }) => {
await playFindButton(canvasElement, /synchroniser/i);
};
Expand All @@ -118,6 +121,7 @@ NoTicketingSystemStory.args = {
...commonComponentProps,
};
NoTicketingSystemStory.parameters = {
date: workaroundDate,
msw: {
handlers: [
...mswCommonParameters,
Expand All @@ -138,6 +142,7 @@ NoTicketingSystemStory.parameters = {
],
},
};
NoTicketingSystemStory.decorators = [mockDateDecorator];
NoTicketingSystemStory.play = async ({ canvasElement }) => {
await playFindAlert(canvasElement);
};
Expand All @@ -149,6 +154,7 @@ NoEventSerieStory.args = {
...commonComponentProps,
};
NoEventSerieStory.parameters = {
date: workaroundDate,
msw: {
handlers: [
...mswCommonParameters,
Expand All @@ -169,6 +175,7 @@ NoEventSerieStory.parameters = {
],
},
};
NoEventSerieStory.decorators = [mockDateDecorator];
NoEventSerieStory.play = async ({ canvasElement }) => {
await playFindButton(canvasElement, /synchroniser/i);
};
Expand All @@ -183,6 +190,7 @@ WithLayoutStory.parameters = {
layout: 'fullscreen',
...NormalStory.parameters,
};
WithLayoutStory.decorators = [mockDateDecorator];
WithLayoutStory.play = async ({ canvasElement }) => {
await playFindButton(canvasElement, /synchroniser/i);
};
Expand Down

0 comments on commit d5bfefc

Please sign in to comment.