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

Fix storybook tests 2 #5026

Merged
merged 3 commits into from
Apr 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useCreateActivityInCache } from '@/activities/hooks/useCreateActivityIn
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
import { mockWorkspaceMembers } from '~/testing/mock-data/workspace-members';

Expand Down Expand Up @@ -64,18 +65,26 @@ describe('useCreateActivityInCache', () => {
const setObjectMetadataItems = useSetRecoilState(
objectMetadataItemsState,
);
const setRecordStore = useSetRecoilState(
recordStoreFamilyState('1234'),
);

const res = useCreateActivityInCache();
return {
...res,
setCurrentWorkspaceMember,
setObjectMetadataItems,
setRecordStore,
};
},
{ wrapper: Wrapper },
);

act(() => {
result.current.setRecordStore({
id: '1234',
__typename: 'Person',
});
result.current.setCurrentWorkspaceMember(mockWorkspaceMembers[0]);
result.current.setObjectMetadataItems(mockObjectMetadataItems);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const BooleanFieldInputWithContext = ({
return (
<FieldContextProvider
fieldDefinition={{
defaultValue: false,
fieldMetadataId: 'boolean',
label: 'Boolean',
iconName: 'Icon123',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const meta: Meta<typeof SettingsDataModelFieldSettingsFormCard> = {
'Modules/Settings/DataModel/Fields/Forms/SettingsDataModelFieldSettingsFormCard',
component: SettingsDataModelFieldSettingsFormCard,
decorators: [
MemoryRouterDecorator,
ComponentDecorator,
ObjectMetadataItemsDecorator,
SnackBarDecorator,
Expand All @@ -61,7 +62,6 @@ const relationFieldMetadataItem = mockedPersonObjectMetadataItem.fields.find(
)!;

export const WithRelationForm: Story = {
decorators: [MemoryRouterDecorator],
args: {
fieldMetadataItem: mockedCompanyObjectMetadataItem.fields.find(
({ name }) => name === 'people',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const meta: Meta<typeof SettingsDataModelFieldPreviewCard> = {
'Modules/Settings/DataModel/Fields/Preview/SettingsDataModelFieldPreviewCard',
component: SettingsDataModelFieldPreviewCard,
decorators: [
MemoryRouterDecorator,
ComponentDecorator,
ObjectMetadataItemsDecorator,
SnackBarDecorator,
Expand Down Expand Up @@ -64,7 +65,6 @@ export const Date: Story = {
};

export const Link: Story = {
decorators: [MemoryRouterDecorator],
args: {
fieldMetadataItem: mockedCompanyObjectMetadataItem.fields.find(
({ type }) => type === FieldMetadataType.Link,
Expand All @@ -91,7 +91,6 @@ export const Rating: Story = {
};

export const Relation: Story = {
decorators: [MemoryRouterDecorator],
args: {
fieldMetadataItem: mockedPersonObjectMetadataItem.fields.find(
({ name }) => name === 'company',
Expand All @@ -100,14 +99,3 @@ export const Relation: Story = {
relationObjectMetadataItem: mockedCompanyObjectMetadataItem,
},
};

// Todo: re-enable this test once useObjectMetadataItem has been split and refactored into smaller functions.
// Right now, as the workspace is not set, the hook things the user is not logged in and it is not possible to have a custom object
// export const Custom: Story = {
// args: {
// fieldMetadataItem: mockedCustomObjectMetadataItem.fields.find(
// ({ type }) => type === FieldMetadataType.Text,
// ),
// objectMetadataItem: mockedCustomObjectMetadataItem,
// },
// };
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const WorkspaceInviteLink = ({
const { enqueueSnackBar } = useSnackBar();

return (
<StyledContainer>
<StyledContainer data-chromatic="ignore">
<StyledLinkContainer>
<TextInput value={inviteLink} disabled fullWidth />
</StyledLinkContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, StoryObj } from '@storybook/react';
import { within } from '@storybook/test';
import { userEvent, within } from '@storybook/test';

import {
PageDecorator,
Expand All @@ -13,7 +13,10 @@ const meta: Meta<PageDecoratorArgs> = {
title: 'Pages/Settings/SettingsProfile',
component: SettingsProfile,
decorators: [PageDecorator],
args: { routePath: '/settings/profile' },
args: {
routePath: '/settings/profile',
additionalRoutes: ['/welcome'],
},
parameters: {
msw: graphqlMocks,
},
Expand All @@ -29,6 +32,7 @@ export const LogOut: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const logoutButton = await canvas.findByText('Logout');
await logoutButton.click();

await userEvent.click(logoutButton);
},
};
79 changes: 45 additions & 34 deletions packages/twenty-front/src/testing/decorators/PageDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FullHeightStorybookLayout } from '../FullHeightStorybookLayout';
export type PageDecoratorArgs = {
routePath: string;
routeParams: RouteParams;
additionalRoutes?: string[];
};

type RouteParams = {
Expand All @@ -44,37 +45,47 @@ const ApolloStorybookDevLogEffect = () => {
export const PageDecorator: Decorator<{
routePath: string;
routeParams: RouteParams;
}> = (Story, { args }) => (
<RecoilRoot>
<ApolloProvider client={mockedApolloClient}>
<ApolloStorybookDevLogEffect />
<ApolloMetadataClientMockedProvider>
<UserProviderEffect />
<UserProvider>
<ClientConfigProviderEffect />
<ClientConfigProvider>
<MemoryRouter
initialEntries={[
computeLocation(args.routePath, args.routeParams),
]}
>
<FullHeightStorybookLayout>
<HelmetProvider>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
<ObjectMetadataItemsProvider>
<Routes>
<Route element={<DefaultLayout />}>
<Route path={args.routePath} element={<Story />} />
</Route>
</Routes>
</ObjectMetadataItemsProvider>
</SnackBarProviderScope>
</HelmetProvider>
</FullHeightStorybookLayout>
</MemoryRouter>
</ClientConfigProvider>
</UserProvider>
</ApolloMetadataClientMockedProvider>
</ApolloProvider>
</RecoilRoot>
);
additionalRoutes?: string[];
}> = (Story, { args }) => {
return (
<RecoilRoot>
<ApolloProvider client={mockedApolloClient}>
<ApolloStorybookDevLogEffect />
<ApolloMetadataClientMockedProvider>
<UserProviderEffect />
<UserProvider>
<ClientConfigProviderEffect />
<ClientConfigProvider>
<MemoryRouter
initialEntries={[
computeLocation(args.routePath, args.routeParams),
]}
>
<FullHeightStorybookLayout>
<HelmetProvider>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
<ObjectMetadataItemsProvider>
<Routes>
<Route element={<DefaultLayout />}>
<Route path={args.routePath} element={<Story />} />
{args.additionalRoutes?.map((route) => (
<Route
key={route}
path={route}
element={<div>Navigated to {route}</div>}
/>
))}
</Route>
</Routes>
</ObjectMetadataItemsProvider>
</SnackBarProviderScope>
</HelmetProvider>
</FullHeightStorybookLayout>
</MemoryRouter>
</ClientConfigProvider>
</UserProvider>
</ApolloMetadataClientMockedProvider>
</ApolloProvider>
</RecoilRoot>
);
};
Loading