Skip to content

Commit

Permalink
Increase storybook pages code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Aug 31, 2024
1 parent 56f8091 commit dfe939e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,92 @@ import {
} from '~/testing/decorators/PageDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';

import { userEvent, within } from '@storybook/test';
import { SettingsAppearance } from '../profile/appearance/components/SettingsAppearance';

Date.now = () => new Date('2022-06-13T12:33:37.000Z').getTime();

const meta: Meta<PageDecoratorArgs> = {
title: 'Pages/Settings/SettingsAppearance',
component: SettingsAppearance,
decorators: [PageDecorator],
args: { routePath: '/settings/appearance' },
parameters: {
msw: graphqlMocks,
date: new Date(2021, 1, 1),
},
};

export default meta;

export type Story = StoryObj<typeof SettingsAppearance>;

export const Default: Story = {};
export const Default: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

await canvas.findByText('Theme', undefined, {
timeout: 3000,
});

await canvas.findByText('Date and time');
},
};

export const DateTimeSettingsTimezone: Story = {
play: async () => {
const canvas = within(document.body);

await canvas.findByText('Date and time');

const timezoneSelect = await canvas.findByText(
'(GMT-04:00) Eastern Daylight Time - New York',
);

userEvent.click(timezoneSelect);

const systemSettingsOptions = await canvas.findByText(
'(GMT-11:00) Niue Time',
);

userEvent.click(systemSettingsOptions);

await canvas.findByText('(GMT-11:00) Niue Time');
},
};

export const DateTimeSettingsDateFormat: Story = {
play: async () => {
const canvas = within(document.body);

await canvas.findByText('Date and time');

const timeFormatSelect = await canvas.findByText('13 Jun, 2022');

userEvent.click(timeFormatSelect);

const timeFormatOptions = await canvas.findByText('Jun 13, 2022');

userEvent.click(timeFormatOptions);

await canvas.findByText('Jun 13, 2022');
},
};

export const DateTimeSettingsTimeFormat: Story = {
play: async () => {
const canvas = within(document.body);

await canvas.findByText('Date and time');

const timeFormatSelect = await canvas.findByText('24h (08:33)');

userEvent.click(timeFormatSelect);

const timeFormatOptions = await canvas.findByText('12h (8:33 AM)');

userEvent.click(timeFormatOptions);

await canvas.findByText('12h (8:33 AM)');
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PageDecoratorArgs,
} from '~/testing/decorators/PageDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { sleep } from '~/utils/sleep';

const meta: Meta<PageDecoratorArgs> = {
title: 'Pages/Settings/Developers/SettingsDevelopers',
Expand All @@ -26,8 +25,9 @@ export type Story = StoryObj<typeof SettingsDevelopers>;
export const Default: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await sleep(100);

await canvas.findByText('API keys');
await canvas.findByText('API keys', undefined, {
timeout: 3000,
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PageDecoratorArgs,
} from '~/testing/decorators/PageDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { sleep } from '~/utils/sleep';

const meta: Meta<PageDecoratorArgs> = {
title: 'Pages/Settings/Integrations/SettingsIntegrationNewDatabaseConnection',
Expand All @@ -29,8 +28,9 @@ export type Story = StoryObj<typeof SettingsIntegrationNewDatabaseConnection>;
export const Default: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
sleep(100);

await canvas.findByText('Connect a new database');
await canvas.findByText('Connect a new database', undefined, {
timeout: 3000,
});
},
};
15 changes: 10 additions & 5 deletions packages/twenty-front/src/testing/decorators/PageDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import { DefaultLayout } from '~/modules/ui/layout/page/DefaultLayout';
import { UserProvider } from '~/modules/users/components/UserProvider';
import { mockedApolloClient } from '~/testing/mockedApolloClient';

import { RecoilDebugObserverEffect } from '@/debug/components/RecoilDebugObserver';
import { PrefetchDataProvider } from '@/prefetch/components/PrefetchDataProvider';
import { IconsProvider } from 'twenty-ui';
import { FullHeightStorybookLayout } from '../FullHeightStorybookLayout';

export type PageDecoratorArgs = {
Expand Down Expand Up @@ -63,6 +65,7 @@ const ApolloStorybookDevLogEffect = () => {
const Providers = () => {
return (
<RecoilRoot>
<RecoilDebugObserverEffect />
<ApolloProvider client={mockedApolloClient}>
<ApolloStorybookDevLogEffect />
<ApolloMetadataClientMockedProvider>
Expand All @@ -73,11 +76,13 @@ const Providers = () => {
<FullHeightStorybookLayout>
<HelmetProvider>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
<ObjectMetadataItemsProvider>
<PrefetchDataProvider>
<Outlet />
</PrefetchDataProvider>
</ObjectMetadataItemsProvider>
<IconsProvider>
<ObjectMetadataItemsProvider>
<PrefetchDataProvider>
<Outlet />
</PrefetchDataProvider>
</ObjectMetadataItemsProvider>
</IconsProvider>
</SnackBarProviderScope>
</HelmetProvider>
</FullHeightStorybookLayout>
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-front/src/testing/mock-data/view-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const mockedViewFieldsData = [
// Companies
{
id: '79035310-e955-4986-a4a4-73f9d9949c6a',
fieldMetadataId: 'name',
fieldMetadataId: '9e123592-cd2b-471c-8143-3cc0b46089ef',
viewId: mockedViewsData[0].id,
position: 0,
isVisible: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/twenty-front/src/testing/mock-data/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ export const mockedViewsData = [
{
id: '37a8a866-eb17-4e76-9382-03143a2f6a80',
name: 'All companies',
objectMetadataId: 'f9fd99a8-108f-4066-9675-cde753cf5de9',
objectMetadataId: '701aecf9-eb1c-4d84-9d94-b954b231b64b',
type: 'table',
icon: 'IconSkyline',
key: 'INDEX',
Expand Down Expand Up @@ -850,7 +850,7 @@ export const mockedViewsData = [
{
id: '5c307222-1dd5-4ff3-ab06-8d990e9b3c74',
name: 'All companies (v2)',
objectMetadataId: 'f9fd99a8-108f-4066-9675-cde753cf5de9',
objectMetadataId: '701aecf9-eb1c-4d84-9d94-b954b231b64b',
type: 'table',
icon: 'IconSkyline',
key: 'INDEX',
Expand Down

0 comments on commit dfe939e

Please sign in to comment.