Skip to content

The open alternative to Salesforce, designed for AI.

Stabilize frontend Storybook interactions (#28693)

Raphaël Bosi0d41a5534ac3
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatTab.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatTab.stories.tsx
index 557d38b1120..97a1551deba 100644
--- a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatTab.stories.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatTab.stories.tsx
@@ -167,7 +167,7 @@ export const NewChatSuggestedPrompt: Story = {
canvas.getByRole('button', { name: 'Create a record' }),
);
await waitFor(() => expect(editor).toHaveTextContent('Details:'));
- await expect(editor).toHaveFocus();
+ await waitFor(() => expect(editor).toHaveFocus());
await userEvent.type(editor, 'A new partner');
await expect(editor).toHaveTextContent('A new partner');
await expect(
diff --git a/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx b/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx
index f472da42ced..aaa43bd40a6 100644
--- a/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/draggable-list/components/__stories__/DraggableList.stories.tsx
@@ -129,11 +129,15 @@ export const PointerGripReorder: Story = {
throw new Error('The row action must be a native button');
}
- const firstItem = rowAction.closest('[aria-roledescription="draggable"]');
+ const firstItem = await waitFor(() => {
+ const dragHost = rowAction.closest('[aria-roledescription="draggable"]');
- if (!(firstItem instanceof HTMLElement)) {
- throw new Error('The row action must stay inside its drag host');
- }
+ if (!(dragHost instanceof HTMLElement)) {
+ throw new Error('The row action must stay inside its drag host');
+ }
+
+ return dragHost;
+ });
const secondItem = canvas.getByRole('button', { name: 'Phone' });
const firstBounds = firstItem.getBoundingClientRect();
const secondBounds = secondItem.getBoundingClientRect();
diff --git a/packages/twenty-ui/src/components/input/CountrySelect/__stories__/CountrySelect.parts.stories.tsx b/packages/twenty-ui/src/components/input/CountrySelect/__stories__/CountrySelect.parts.stories.tsx
index 6e9ed6feed8..505c12be897 100644
--- a/packages/twenty-ui/src/components/input/CountrySelect/__stories__/CountrySelect.parts.stories.tsx
+++ b/packages/twenty-ui/src/components/input/CountrySelect/__stories__/CountrySelect.parts.stories.tsx
@@ -175,6 +175,7 @@ export const DistinctEmptyAndReservedIdentifiers: Story = {
await waitFor(() =>
expect(trigger).toHaveAttribute('aria-expanded', 'false'),
);
+ await waitFor(() => expect(popup).not.toBeInTheDocument());
},
};
diff --git a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.interactions.stories.tsx b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.interactions.stories.tsx
index 4892a26cd65..ab3fd1b8455 100644
--- a/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.interactions.stories.tsx
+++ b/packages/twenty-ui/src/components/input/DatePicker/__stories__/DatePicker.interactions.stories.tsx
@@ -136,18 +136,22 @@ export const NavigationUnmount: Story = {
await userEvent.click(
await canvas.findByRole('combobox', { name: 'Month' }),
);
- await expect(args.onNavigationOpenChange).toHaveBeenLastCalledWith({
- open: true,
- control: 'month',
- });
+ await waitFor(() =>
+ expect(args.onNavigationOpenChange).toHaveBeenLastCalledWith({
+ open: true,
+ control: 'month',
+ }),
+ );
await userEvent.click(
await body.findByRole('option', { name: 'November' }),
);
await expect(canvas.getByText('Calendar hidden')).toBeVisible();
- await expect(args.onNavigationOpenChange).toHaveBeenLastCalledWith({
- open: false,
- control: 'month',
- });
+ await waitFor(() =>
+ expect(args.onNavigationOpenChange).toHaveBeenLastCalledWith({
+ open: false,
+ control: 'month',
+ }),
+ );
},
};
diff --git a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.collection.stories.tsx b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.collection.stories.tsx
index d047aa4dd41..7b1b15c659d 100644
--- a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.collection.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.collection.stories.tsx
@@ -89,10 +89,15 @@ export const ExternalFiltering: Story = {
await userEvent.clear(input);
await userEvent.type(input, 'Pa');
const paris = await body.findByRole('option', { name: 'Paris' });
+ const listbox = body.getByRole('listbox', { name: 'City suggestions' });
await waitFor(() =>
expect(input).toHaveAttribute('aria-activedescendant', paris.id),
);
await userEvent.keyboard('{Enter}');
await expect(input).toHaveValue('Paris');
+ await waitFor(() =>
+ expect(input).toHaveAttribute('aria-expanded', 'false'),
+ );
+ await waitFor(() => expect(listbox).not.toBeInTheDocument());
},
};
diff --git a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteFilteredExample.tsx b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteFilteredExample.tsx
index 69db0d73217..0fe1116c89b 100644
--- a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteFilteredExample.tsx
+++ b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteFilteredExample.tsx
@@ -24,7 +24,7 @@ export const AutocompleteFilteredExample = () => {
<Autocomplete.Empty>
No city starts with this query
</Autocomplete.Empty>
- <Autocomplete.List>
+ <Autocomplete.List aria-label="City suggestions">
{(city: string) => (
<Autocomplete.Item key={city} value={city}>
{city}
diff --git a/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx b/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx
index 0e7339ee434..2be4fefe0c4 100644
--- a/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx
@@ -93,7 +93,7 @@ export const PopupTrigger: Story = {
const closedBackground = getComputedStyle(trigger).backgroundColor;
await userEvent.click(trigger);
- await body.findByRole('dialog', { name: 'Details' });
+ const popup = await body.findByRole('dialog', { name: 'Details' });
await userEvent.unhover(trigger);
await expect(trigger).toHaveAttribute('data-popup-open');
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
@@ -113,6 +113,7 @@ export const PopupTrigger: Story = {
await userEvent.keyboard('{Escape}');
await waitFor(() => expect(trigger).not.toHaveAttribute('data-popup-open'));
+ await waitFor(() => expect(popup).not.toBeInTheDocument());
await waitFor(() => expect(trigger).toHaveFocus());
await userEvent.unhover(trigger);
await expect(getComputedStyle(trigger).backgroundColor).toBe(
@@ -121,9 +122,12 @@ export const PopupTrigger: Story = {
await userEvent.keyboard('{Enter}');
await waitFor(() => expect(trigger).toHaveAttribute('data-popup-open'));
+ const reopenedPopup = await body.findByRole('dialog', { name: 'Details' });
await expect(args.onClick).toHaveBeenCalledTimes(2);
await userEvent.keyboard('{Escape}');
await waitFor(() => expect(trigger).not.toHaveAttribute('data-popup-open'));
+ await waitFor(() => expect(reopenedPopup).not.toBeInTheDocument());
+ await waitFor(() => expect(trigger).toHaveFocus());
},
};