Fix Storybook tests (#9554)

Finally fixing the storybook tests!
This commit is contained in:
Charles Bochet
2025-01-10 20:54:10 +01:00
committed by GitHub
parent 2e0169b954
commit 5ec28afac9
5 changed files with 55 additions and 28 deletions

View File

@ -2,4 +2,7 @@
[data-is-storybook="true"] { [data-is-storybook="true"] {
background-color: transparent!important; background-color: transparent!important;
} }
</style> :has(#storybook-panel-root) {
z-index: 100;
}
</style>

View File

@ -87,6 +87,7 @@ export const DisplayDefaultValueWithVariablesProperly: Story = {
args: { args: {
placeholder: 'Enter valid json', placeholder: 'Enter valid json',
defaultValue: '{ "a": { "b" : {{var.test}} } }', defaultValue: '{ "a": { "b" : {{var.test}} } }',
onPersist: fn(),
}, },
play: async ({ canvasElement }) => { play: async ({ canvasElement }) => {
const canvas = within(canvasElement); const canvas = within(canvasElement);
@ -120,6 +121,7 @@ export const InsertVariableInTheMiddleOnTextInput: Story = {
</button> </button>
); );
}, },
onPersist: fn(),
}, },
play: async ({ canvasElement, args }) => { play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement); const canvas = within(canvasElement);
@ -161,6 +163,7 @@ export const CanUseVariableAsObjectProperty: Story = {
</button> </button>
); );
}, },
onPersist: fn(),
}, },
play: async ({ canvasElement, args }) => { play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement); const canvas = within(canvasElement);
@ -188,6 +191,7 @@ export const ClearField: Story = {
args: { args: {
placeholder: 'Enter valid json', placeholder: 'Enter valid json',
defaultValue: '{ "a": 2 }', defaultValue: '{ "a": 2 }',
onPersist: fn(),
}, },
play: async ({ canvasElement, args }) => { play: async ({ canvasElement, args }) => {
const defaultValueStringLength = args.defaultValue!.length; const defaultValueStringLength = args.defaultValue!.length;

View File

@ -38,7 +38,9 @@ export const Open: Story = {
play: async () => { play: async () => {
const canvas = within(document.body); const canvas = within(document.body);
const dropdownButton = await canvas.getByRole('button'); const dropdownButton = await canvas.findByRole('button', {
name: 'Inactive Object Options',
});
await userEvent.click(dropdownButton); await userEvent.click(dropdownButton);
}, },
@ -48,7 +50,9 @@ export const WithActivate: Story = {
play: async () => { play: async () => {
const canvas = within(document.body); const canvas = within(document.body);
const dropdownButton = await canvas.getByRole('button'); const dropdownButton = await canvas.findByRole('button', {
name: 'Inactive Object Options',
});
await userEvent.click(dropdownButton); await userEvent.click(dropdownButton);
@ -69,7 +73,9 @@ export const WithDelete: Story = {
play: async () => { play: async () => {
const canvas = within(document.body); const canvas = within(document.body);
const dropdownButton = await canvas.getByRole('button'); const dropdownButton = await canvas.findByRole('button', {
name: 'Inactive Object Options',
});
await userEvent.click(dropdownButton); await userEvent.click(dropdownButton);

View File

@ -82,22 +82,24 @@ export const Empty: Story = {
play: async () => { play: async () => {
const canvas = within(document.body); const canvas = within(document.body);
const button = await canvas.findByRole('button'); const buttons = await canvas.findAllByRole('button', {
userEvent.click(button); name: 'Open Dropdown',
});
userEvent.click(buttons[0]);
await waitFor(async () => { await waitFor(async () => {
const fakeMenu = await canvas.findByTestId('dropdown-content'); const fakeMenu = await canvas.findByTestId('dropdown-content');
expect(fakeMenu).toBeInTheDocument(); expect(fakeMenu).toBeInTheDocument();
}); });
userEvent.click(button); userEvent.click(buttons[0]);
await waitFor(async () => { await waitFor(async () => {
const fakeMenu = canvas.queryByTestId('dropdown-content'); const fakeMenu = canvas.queryByTestId('dropdown-content');
expect(fakeMenu).not.toBeInTheDocument(); expect(fakeMenu).not.toBeInTheDocument();
}); });
userEvent.click(button); userEvent.click(buttons[0]);
await waitFor(async () => { await waitFor(async () => {
const fakeMenu = await canvas.findByTestId('dropdown-content'); const fakeMenu = await canvas.findByTestId('dropdown-content');
expect(fakeMenu).toBeInTheDocument(); expect(fakeMenu).toBeInTheDocument();
@ -205,8 +207,8 @@ const FakeCheckableMenuItemList = ({ hasAvatar }: { hasAvatar?: boolean }) => {
const playInteraction: PlayFunction<any, any> = async () => { const playInteraction: PlayFunction<any, any> = async () => {
const canvas = within(document.body); const canvas = within(document.body);
const button = await canvas.findByRole('button'); const buttons = await canvas.findAllByRole('button');
userEvent.click(button); userEvent.click(buttons[0]);
await waitFor(async () => { await waitFor(async () => {
expect(canvas.getByText('Company A')).toBeInTheDocument(); expect(canvas.getByText('Company A')).toBeInTheDocument();
@ -257,15 +259,15 @@ export const SearchWithLoadingMenu: Story = {
play: async () => { play: async () => {
const canvas = within(document.body); const canvas = within(document.body);
const button = await canvas.findByRole('button'); const buttons = await canvas.findAllByRole('button');
await waitFor(() => { await waitFor(() => {
userEvent.click(button); userEvent.click(buttons[0]);
expect(canvas.getByDisplayValue('query')).toBeInTheDocument(); expect(canvas.getByDisplayValue('query')).toBeInTheDocument();
}); });
await waitFor(() => { await waitFor(() => {
userEvent.click(button); userEvent.click(buttons[0]);
expect(canvas.queryByDisplayValue('query')).not.toBeInTheDocument(); expect(canvas.queryByDisplayValue('query')).not.toBeInTheDocument();
}); });
}, },

View File

@ -2,6 +2,7 @@ import { Decorator } from '@storybook/react';
import { useRecoilValue } from 'recoil'; import { useRecoilValue } from 'recoil';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState'; import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { RecordIndexContextProvider } from '@/object-record/record-index/contexts/RecordIndexContext';
import { RecordTableBodyContextProvider } from '@/object-record/record-table/contexts/RecordTableBodyContext'; import { RecordTableBodyContextProvider } from '@/object-record/record-table/contexts/RecordTableBodyContext';
import { RecordTableContextProvider } from '@/object-record/record-table/contexts/RecordTableContext'; import { RecordTableContextProvider } from '@/object-record/record-table/contexts/RecordTableContext';
import { isDefined } from 'twenty-ui'; import { isDefined } from 'twenty-ui';
@ -18,28 +19,39 @@ export const RecordTableDecorator: Decorator = (Story) => {
} }
return ( return (
<RecordTableContextProvider <RecordIndexContextProvider
value={{ value={{
indexIdentifierUrl: () => '',
onIndexRecordsLoaded: () => {},
objectNamePlural: personObjectMetadataItem.namePlural,
objectNameSingular: personObjectMetadataItem.nameSingular, objectNameSingular: personObjectMetadataItem.nameSingular,
objectMetadataItem: personObjectMetadataItem, objectMetadataItem: personObjectMetadataItem,
recordTableId: 'persons', recordIndexId: 'record-index',
viewBarId: 'view-bar',
visibleTableColumns: [],
}} }}
> >
<RecordTableBodyContextProvider <RecordTableContextProvider
value={{ value={{
onCellMouseEnter: () => {}, objectNameSingular: personObjectMetadataItem.nameSingular,
onCloseTableCell: () => {}, objectMetadataItem: personObjectMetadataItem,
onOpenTableCell: () => {}, recordTableId: 'persons',
onActionMenuDropdownOpened: () => {}, viewBarId: 'view-bar',
onMoveFocus: () => {}, visibleTableColumns: [],
onMoveSoftFocusToCell: () => {},
onUpsertRecord: () => {},
}} }}
> >
<Story /> <RecordTableBodyContextProvider
</RecordTableBodyContextProvider> value={{
</RecordTableContextProvider> onCellMouseEnter: () => {},
onCloseTableCell: () => {},
onOpenTableCell: () => {},
onActionMenuDropdownOpened: () => {},
onMoveFocus: () => {},
onMoveSoftFocusToCell: () => {},
onUpsertRecord: () => {},
}}
>
<Story />
</RecordTableBodyContextProvider>
</RecordTableContextProvider>
</RecordIndexContextProvider>
); );
}; };